start better segregation of concerns
This commit is contained in:
parent
98cc70dbfb
commit
fce25c60ed
21
dist/smartacme.classes.acmeaccount.d.ts
vendored
21
dist/smartacme.classes.acmeaccount.d.ts
vendored
@ -1,3 +1,22 @@
|
|||||||
import 'typings-global';
|
/// <reference types="q" />
|
||||||
|
import * as q from 'q';
|
||||||
|
import { SmartAcme } from './smartacme.classes.smartacme';
|
||||||
|
/**
|
||||||
|
* class AcmeAccount represents an AcmeAccount
|
||||||
|
*/
|
||||||
export declare class AcmeAccount {
|
export declare class AcmeAccount {
|
||||||
|
parentSmartAcme: SmartAcme;
|
||||||
|
location: string;
|
||||||
|
link: string;
|
||||||
|
JWK: any;
|
||||||
|
constructor(smartAcmeParentArg: SmartAcme);
|
||||||
|
/**
|
||||||
|
* register the account with letsencrypt
|
||||||
|
*/
|
||||||
|
register(): q.Promise<{}>;
|
||||||
|
/**
|
||||||
|
* agree to letsencrypr terms of service
|
||||||
|
*/
|
||||||
|
agreeTos(): q.Promise<{}>;
|
||||||
|
createAcmeCert(domainNameArg: string): void;
|
||||||
}
|
}
|
||||||
|
52
dist/smartacme.classes.acmeaccount.js
vendored
52
dist/smartacme.classes.acmeaccount.js
vendored
@ -1,6 +1,54 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
const q = require("q");
|
||||||
|
/**
|
||||||
|
* class AcmeAccount represents an AcmeAccount
|
||||||
|
*/
|
||||||
class AcmeAccount {
|
class AcmeAccount {
|
||||||
|
constructor(smartAcmeParentArg) {
|
||||||
|
this.parentSmartAcme = smartAcmeParentArg;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* register the account with letsencrypt
|
||||||
|
*/
|
||||||
|
register() {
|
||||||
|
let done = q.defer();
|
||||||
|
this.parentSmartAcme.rawacmeClient.newReg({
|
||||||
|
contact: ['mailto:domains@lossless.org']
|
||||||
|
}, (err, res) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('smartacme: something went wrong:');
|
||||||
|
console.log(err);
|
||||||
|
done.reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.JWK = res.body.key;
|
||||||
|
this.link = res.headers.link;
|
||||||
|
console.log(this.link);
|
||||||
|
this.location = res.headers.location;
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* agree to letsencrypr terms of service
|
||||||
|
*/
|
||||||
|
agreeTos() {
|
||||||
|
let done = q.defer();
|
||||||
|
let tosPart = this.link.split(',')[1];
|
||||||
|
let tosLinkPortion = tosPart.split(';')[0];
|
||||||
|
let url = tosLinkPortion.split(';')[0].trim().replace(/[<>]/g, '');
|
||||||
|
this.parentSmartAcme.rawacmeClient.post(this.location, { Agreement: url, resource: 'reg' }, (err, res) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
done.reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
createAcmeCert(domainNameArg) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.AcmeAccount = AcmeAccount;
|
exports.AcmeAccount = AcmeAccount;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuYWNtZWFjY291bnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUuY2xhc3Nlcy5hY21lYWNjb3VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBRXZCO0NBRUM7QUFGRCxrQ0FFQyJ9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuYWNtZWFjY291bnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUuY2xhc3Nlcy5hY21lY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JQUVwQyxDQUFDO0NBQ0o7QUF4REQsa0NBd0RDIn0=
|
72
dist/smartacme.classes.acmecert.d.ts
vendored
72
dist/smartacme.classes.acmecert.d.ts
vendored
@ -1,3 +1,71 @@
|
|||||||
import 'typings-global';
|
/// <reference types="q" />
|
||||||
export declare class AcmeCert {
|
import * as q from 'q';
|
||||||
|
import { IRsaKeypair } from './smartacme.classes.smartacme';
|
||||||
|
import { AcmeAccount } from './smartacme.classes.acmeaccount';
|
||||||
|
/**
|
||||||
|
* types of challenges supported by letsencrypt and this module
|
||||||
|
*/
|
||||||
|
export declare type TChallengeType = 'dns-01' | 'http-01';
|
||||||
|
/**
|
||||||
|
* values that a challenge's status can have
|
||||||
|
*/
|
||||||
|
export declare type TChallengeStatus = 'pending';
|
||||||
|
export interface ISmartAcmeChallenge {
|
||||||
|
uri: string;
|
||||||
|
status: TChallengeStatus;
|
||||||
|
type: TChallengeType;
|
||||||
|
token: string;
|
||||||
|
keyAuthorization: string;
|
||||||
|
}
|
||||||
|
export interface ISmartAcmeChallengeAccepted extends ISmartAcmeChallenge {
|
||||||
|
keyHash: string;
|
||||||
|
}
|
||||||
|
export interface IAcmeCsrConstructorOptions {
|
||||||
|
bit: number;
|
||||||
|
key: string;
|
||||||
|
domain: string;
|
||||||
|
country: string;
|
||||||
|
country_short: string;
|
||||||
|
locality: string;
|
||||||
|
organization: string;
|
||||||
|
organization_short: string;
|
||||||
|
password: string;
|
||||||
|
unstructured: string;
|
||||||
|
subject_alt_names: string[];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* class AcmeCert represents a cert for domain
|
||||||
|
*/
|
||||||
|
export declare class AcmeCert {
|
||||||
|
attributes: any;
|
||||||
|
fullchain: string;
|
||||||
|
parentAcmeAccount: AcmeAccount;
|
||||||
|
csr: any;
|
||||||
|
validFrom: Date;
|
||||||
|
validTo: Date;
|
||||||
|
keypair: IRsaKeypair;
|
||||||
|
keyPairFinal: IRsaKeypair;
|
||||||
|
constructor(optionsArg: IAcmeCsrConstructorOptions, parentSmartAcmeArg: any);
|
||||||
|
/**
|
||||||
|
* requests a challenge for a domain
|
||||||
|
* @param domainNameArg - the domain name to request a challenge for
|
||||||
|
* @param challengeType - the challenge type to request
|
||||||
|
*/
|
||||||
|
requestChallenge(domainNameArg: string, challengeTypeArg?: TChallengeType): q.Promise<ISmartAcmeChallengeAccepted>;
|
||||||
|
/**
|
||||||
|
* validates a challenge, only call after you have set the challenge at the expected location
|
||||||
|
*/
|
||||||
|
validate(challenge: ISmartAcmeChallengeAccepted): q.Promise<{}>;
|
||||||
|
/**
|
||||||
|
* requests a certificate
|
||||||
|
*/
|
||||||
|
requestCert(): q.Promise<{}>;
|
||||||
|
/**
|
||||||
|
* getCertificate - takes care of cooldown, validation polling and certificate retrieval
|
||||||
|
*/
|
||||||
|
getCertificate(): void;
|
||||||
|
/**
|
||||||
|
* accept a challenge - for private use only
|
||||||
|
*/
|
||||||
|
private acceptChallenge(challenge);
|
||||||
}
|
}
|
||||||
|
142
dist/smartacme.classes.acmecert.js
vendored
142
dist/smartacme.classes.acmecert.js
vendored
File diff suppressed because one or more lines are too long
21
dist/smartacme.classes.helper.d.ts
vendored
21
dist/smartacme.classes.helper.d.ts
vendored
@ -1,21 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import 'typings-global';
|
|
||||||
import * as q from 'q';
|
|
||||||
import { SmartAcme } from './smartacme.classes.smartacme';
|
|
||||||
export interface IRsaKeypair {
|
|
||||||
publicKey: string;
|
|
||||||
privateKey: string;
|
|
||||||
}
|
|
||||||
export declare class SmartacmeHelper {
|
|
||||||
parentSmartAcme: SmartAcme;
|
|
||||||
constructor(smartAcmeArg: SmartAcme);
|
|
||||||
/**
|
|
||||||
* creates a keypair to use with requests and to generate JWK from
|
|
||||||
*/
|
|
||||||
createKeypair(bit?: number): IRsaKeypair;
|
|
||||||
/**
|
|
||||||
* gets an existing registration
|
|
||||||
* @executes ASYNC
|
|
||||||
*/
|
|
||||||
getReg(): q.Promise<{}>;
|
|
||||||
}
|
|
40
dist/smartacme.classes.helper.js
vendored
40
dist/smartacme.classes.helper.js
vendored
@ -1,40 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global");
|
|
||||||
const q = require("q");
|
|
||||||
let rsaKeygen = require('rsa-keygen');
|
|
||||||
class SmartacmeHelper {
|
|
||||||
constructor(smartAcmeArg) {
|
|
||||||
this.parentSmartAcme = smartAcmeArg;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* creates a keypair to use with requests and to generate JWK from
|
|
||||||
*/
|
|
||||||
createKeypair(bit = 2048) {
|
|
||||||
let result = rsaKeygen.generate(bit);
|
|
||||||
return {
|
|
||||||
publicKey: result.public_key,
|
|
||||||
privateKey: result.private_key
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* gets an existing registration
|
|
||||||
* @executes ASYNC
|
|
||||||
*/
|
|
||||||
getReg() {
|
|
||||||
let done = q.defer();
|
|
||||||
let body = { resource: 'reg' };
|
|
||||||
this.parentSmartAcme.rawacmeClient.post(this.parentSmartAcme.location, body, this.parentSmartAcme.keyPair, (err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('smartacme: something went wrong:');
|
|
||||||
console.log(err);
|
|
||||||
done.reject(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log(JSON.stringify(res.body));
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.SmartacmeHelper = SmartacmeHelper;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuaGVscGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZXMuaGVscGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFDdkIsdUJBQXNCO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UFDLElBQUksQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUE7WUFDckMsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2xCLENBQUMsQ0FDSixDQUFBO1FBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztDQUNKO0FBekNELDBDQXlDQyJ9
|
|
51
dist/smartacme.classes.smartacme.d.ts
vendored
51
dist/smartacme.classes.smartacme.d.ts
vendored
@ -1,57 +1,34 @@
|
|||||||
/// <reference types="q" />
|
/// <reference types="q" />
|
||||||
import 'typings-global';
|
|
||||||
import * as q from 'q';
|
import * as q from 'q';
|
||||||
import { SmartacmeHelper, IRsaKeypair } from './smartacme.classes.helper';
|
import { AcmeAccount } from './smartacme.classes.acmeaccount';
|
||||||
export declare type TChallengeType = 'dns-01' | 'http-01';
|
/**
|
||||||
export declare type TChallengeStatus = 'pending';
|
* a rsa keypair needed for account creation and subsequent requests
|
||||||
export interface ISmartAcmeChallenge {
|
*/
|
||||||
uri: string;
|
export interface IRsaKeypair {
|
||||||
status: TChallengeStatus;
|
publicKey: string;
|
||||||
type: TChallengeType;
|
privateKey: string;
|
||||||
token: string;
|
|
||||||
keyAuthorization: string;
|
|
||||||
}
|
|
||||||
export interface ISmartAcmeChallengeAccepted extends ISmartAcmeChallenge {
|
|
||||||
keyHash: string;
|
|
||||||
}
|
}
|
||||||
|
export { AcmeAccount } from './smartacme.classes.acmeaccount';
|
||||||
|
export { AcmeCert, ISmartAcmeChallenge, ISmartAcmeChallengeAccepted } from './smartacme.classes.acmecert';
|
||||||
/**
|
/**
|
||||||
* class SmartAcme exports methods for maintaining SSL Certificates
|
* class SmartAcme exports methods for maintaining SSL Certificates
|
||||||
*/
|
*/
|
||||||
export declare class SmartAcme {
|
export declare class SmartAcme {
|
||||||
helper: SmartacmeHelper;
|
|
||||||
acmeUrl: string;
|
acmeUrl: string;
|
||||||
productionBool: boolean;
|
productionBool: boolean;
|
||||||
keyPair: IRsaKeypair;
|
keyPair: IRsaKeypair;
|
||||||
location: string;
|
|
||||||
link: string;
|
|
||||||
rawacmeClient: any;
|
rawacmeClient: any;
|
||||||
JWK: any;
|
|
||||||
/**
|
/**
|
||||||
* the constructor for class SmartAcme
|
* the constructor for class SmartAcme
|
||||||
*/
|
*/
|
||||||
constructor(productionArg?: boolean);
|
constructor(productionArg?: boolean);
|
||||||
|
/**
|
||||||
|
* init the smartacme instance
|
||||||
|
*/
|
||||||
|
init(): q.Promise<{}>;
|
||||||
/**
|
/**
|
||||||
* creates an account if not currently present in module
|
* creates an account if not currently present in module
|
||||||
* @executes ASYNC
|
* @executes ASYNC
|
||||||
*/
|
*/
|
||||||
createAccount(): q.Promise<{}>;
|
createAccount(): q.Promise<AcmeAccount>;
|
||||||
agreeTos(): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* requests a challenge for a domain
|
|
||||||
* @param domainNameArg - the domain name to request a challenge for
|
|
||||||
* @param challengeType - the challenge type to request
|
|
||||||
*/
|
|
||||||
requestChallenge(domainNameArg: string, challengeTypeArg?: TChallengeType): q.Promise<ISmartAcmeChallengeAccepted>;
|
|
||||||
/**
|
|
||||||
* getCertificate - takes care of cooldown, validation polling and certificate retrieval
|
|
||||||
*/
|
|
||||||
getCertificate(): void;
|
|
||||||
/**
|
|
||||||
* validates a challenge
|
|
||||||
*/
|
|
||||||
validate(challenge: ISmartAcmeChallengeAccepted): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* accept a challenge - for private use only
|
|
||||||
*/
|
|
||||||
private acceptChallenge(challenge);
|
|
||||||
}
|
}
|
||||||
|
146
dist/smartacme.classes.smartacme.js
vendored
146
dist/smartacme.classes.smartacme.js
vendored
File diff suppressed because one or more lines are too long
6
dist/smartacme.helpers.d.ts
vendored
Normal file
6
dist/smartacme.helpers.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import 'typings-global';
|
||||||
|
import { IRsaKeypair } from './smartacme.classes.smartacme';
|
||||||
|
/**
|
||||||
|
* creates a keypair to use with requests and to generate JWK from
|
||||||
|
*/
|
||||||
|
export declare let createKeypair: (bit?: number) => IRsaKeypair;
|
34
dist/smartacme.helpers.js
vendored
Normal file
34
dist/smartacme.helpers.js
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
const q = require("q");
|
||||||
|
const plugins = require("./smartacme.plugins");
|
||||||
|
/**
|
||||||
|
* creates a keypair to use with requests and to generate JWK from
|
||||||
|
*/
|
||||||
|
exports.createKeypair = (bit = 2048) => {
|
||||||
|
let result = plugins.rsaKeygen.generate(bit);
|
||||||
|
return {
|
||||||
|
publicKey: result.public_key,
|
||||||
|
privateKey: result.private_key
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* gets an existing registration
|
||||||
|
* @executes ASYNC
|
||||||
|
*/
|
||||||
|
let getReg = (SmartAcmeArg, location) => {
|
||||||
|
let done = q.defer();
|
||||||
|
let body = { resource: 'reg' };
|
||||||
|
SmartAcmeArg.rawacmeClient.post(location, body, SmartAcmeArg.keyPair, (err, res) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('smartacme: something went wrong:');
|
||||||
|
console.log(err);
|
||||||
|
done.reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify(res.body));
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVCQUFzQjtBQUV0QiwrQ0FBOEM7QUFLOUM7O0dBR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FBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDdkIsQ0FBQyxDQUFBIn0=
|
8
dist/smartacme.plugins.d.ts
vendored
Normal file
8
dist/smartacme.plugins.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import 'typings-global';
|
||||||
|
declare let rsaKeygen: any;
|
||||||
|
declare let rawacme: any;
|
||||||
|
declare let nodeForge: any;
|
||||||
|
import * as smartfile from 'smartfile';
|
||||||
|
import * as smartstring from 'smartstring';
|
||||||
|
import * as paths from './smartacme.paths';
|
||||||
|
export { rsaKeygen, rawacme, nodeForge, smartfile, smartstring, paths };
|
16
dist/smartacme.plugins.js
vendored
Normal file
16
dist/smartacme.plugins.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global"); // typings for node
|
||||||
|
let rsaKeygen = require('rsa-keygen'); // rsa keygen
|
||||||
|
exports.rsaKeygen = rsaKeygen;
|
||||||
|
let rawacme = require('rawacme'); // acme helper functions
|
||||||
|
exports.rawacme = rawacme;
|
||||||
|
let nodeForge = require('node-forge');
|
||||||
|
exports.nodeForge = nodeForge;
|
||||||
|
// push.rocks modules here
|
||||||
|
const smartfile = require("smartfile");
|
||||||
|
exports.smartfile = smartfile;
|
||||||
|
const smartstring = require("smartstring");
|
||||||
|
exports.smartstring = smartstring;
|
||||||
|
const paths = require("./smartacme.paths");
|
||||||
|
exports.paths = paths;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCLENBQUMsbUJBQW1CO0FBRzNDLElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQSxDQUFDLGFBQWE7QUFVL0MsOEJBQVM7QUFUYixJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUEsQ0FBQyx3QkFBd0I7QUFVckQsMEJBQU87QUFUWCxJQUFJLFNBQVMsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUE7QUFVakMsOEJBQVM7QUFSYiwwQkFBMEI7QUFDMUIsdUNBQXNDO0FBUWxDLDhCQUFTO0FBUGIsMkNBQTBDO0FBUXRDLGtDQUFXO0FBUGYsMkNBQTBDO0FBUXRDLHNCQUFLIn0=
|
@ -35,6 +35,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.30",
|
"@types/should": "^8.1.30",
|
||||||
|
"cflare": "0.0.10",
|
||||||
"should": "^11.1.1",
|
"should": "^11.1.1",
|
||||||
"typings-test": "^1.0.3"
|
"typings-test": "^1.0.3"
|
||||||
}
|
}
|
||||||
|
32
test/test.js
32
test/test.js
@ -4,44 +4,42 @@ const should = require("should");
|
|||||||
// import the module to test
|
// import the module to test
|
||||||
const smartacme = require("../dist/index");
|
const smartacme = require("../dist/index");
|
||||||
describe('smartacme', function () {
|
describe('smartacme', function () {
|
||||||
let testAcme;
|
let testSmartAcme;
|
||||||
|
let testAcmeAccount;
|
||||||
let testChallenge;
|
let testChallenge;
|
||||||
it('should create a valid instance', function () {
|
it('should create a valid instance', function (done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
testAcme = new smartacme.SmartAcme();
|
testSmartAcme = new smartacme.SmartAcme();
|
||||||
should(testAcme).be.instanceOf(smartacme.SmartAcme);
|
testSmartAcme.init().then(() => {
|
||||||
|
should(testSmartAcme).be.instanceOf(smartacme.SmartAcme);
|
||||||
|
done();
|
||||||
|
}).catch(err => { done(err); });
|
||||||
});
|
});
|
||||||
it('should have created keyPair', function () {
|
it('should have created keyPair', function () {
|
||||||
should(testAcme.acmeUrl).be.of.type('string');
|
should(testSmartAcme.acmeUrl).be.of.type('string');
|
||||||
});
|
});
|
||||||
it('should register a new account', function (done) {
|
it('should register a new account', function (done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
testAcme.createAccount().then(x => {
|
testSmartAcme.createAccount().then(x => {
|
||||||
done();
|
done();
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should agree to ToS', function (done) {
|
it.skip('should request a cert for a domain', function (done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
testAcme.agreeTos().then(() => {
|
testAcmeAccount.requestChallenge('bleu.de').then((challengeAccepted) => {
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should request a challenge for a domain', function (done) {
|
|
||||||
this.timeout(10000);
|
|
||||||
testAcme.requestChallenge('bleu.de').then((challengeAccepted) => {
|
|
||||||
console.log(challengeAccepted);
|
console.log(challengeAccepted);
|
||||||
testChallenge = challengeAccepted;
|
testChallenge = challengeAccepted;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should poll for validation of a challenge', function (done) {
|
it.skip('should poll for validation of a challenge', function (done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
testAcme.validate(testChallenge).then(x => {
|
testSmartAcme.validate(testChallenge).then(x => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsNEJBQTRCO0FBQzVCLDJDQUEwQztBQUUxQyxRQUFRLENBQUMsV0FBVyx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lBQ2hCLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQTtRQUNiLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7SUFFRixFQUFFLENBQUMsSUFBSSxDQUFDLG9DQUFvQyxFQUFFLFVBQVUsSUFBSTtRQUN4RCxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLGVBQWUsQ0FBQyxnQkFBZ0IsQ0FBQyxTQUFTLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxpQkFBaUI7WUFDL0QsT0FBTyxDQUFDLEdBQUcsQ0FBQyxpQkFBaUIsQ0FBQyxDQUFBO1lBQzlCLGFBQWEsR0FBRyxpQkFBaUIsQ0FBQTtZQUNqQyxJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7SUFFRixFQUFFLENBQUMsSUFBSSxDQUFDLDJDQUEyQyxFQUFFLFVBQVUsSUFBSTtRQUMvRCxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLGFBQWEsQ0FBQyxRQUFRLENBQUMsYUFBYSxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDeEMsSUFBSSxFQUFFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
32
test/test.ts
32
test/test.ts
@ -1,25 +1,30 @@
|
|||||||
import 'typings-test'
|
import 'typings-test'
|
||||||
import * as should from 'should'
|
import * as should from 'should'
|
||||||
|
import * as cflare from 'cflare'
|
||||||
|
|
||||||
// import the module to test
|
// import the module to test
|
||||||
import * as smartacme from '../dist/index'
|
import * as smartacme from '../dist/index'
|
||||||
|
|
||||||
describe('smartacme', function () {
|
describe('smartacme', function () {
|
||||||
let testAcme: smartacme.SmartAcme
|
let testSmartAcme: smartacme.SmartAcme
|
||||||
|
let testAcmeAccount: smartacme.AcmeAccount
|
||||||
let testChallenge: smartacme.ISmartAcmeChallengeAccepted
|
let testChallenge: smartacme.ISmartAcmeChallengeAccepted
|
||||||
it('should create a valid instance', function () {
|
it('should create a valid instance', function (done) {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
testAcme = new smartacme.SmartAcme()
|
testSmartAcme = new smartacme.SmartAcme()
|
||||||
should(testAcme).be.instanceOf(smartacme.SmartAcme)
|
testSmartAcme.init().then(() => {
|
||||||
|
should(testSmartAcme).be.instanceOf(smartacme.SmartAcme)
|
||||||
|
done()
|
||||||
|
}).catch(err => { done(err) })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should have created keyPair', function () {
|
it('should have created keyPair', function () {
|
||||||
should(testAcme.acmeUrl).be.of.type('string')
|
should(testSmartAcme.acmeUrl).be.of.type('string')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should register a new account', function (done) {
|
it('should register a new account', function (done) {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
testAcme.createAccount().then(x => {
|
testSmartAcme.createAccount().then(x => {
|
||||||
done()
|
done()
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
@ -27,25 +32,18 @@ describe('smartacme', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should agree to ToS', function(done) {
|
it.skip('should request a cert for a domain', function (done) {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
testAcme.agreeTos().then(() => {
|
testAcmeAccount.requestChallenge('bleu.de').then((challengeAccepted) => {
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should request a challenge for a domain', function(done) {
|
|
||||||
this.timeout(10000)
|
|
||||||
testAcme.requestChallenge('bleu.de').then((challengeAccepted) => {
|
|
||||||
console.log(challengeAccepted)
|
console.log(challengeAccepted)
|
||||||
testChallenge = challengeAccepted
|
testChallenge = challengeAccepted
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should poll for validation of a challenge',function(done) {
|
it.skip('should poll for validation of a challenge', function (done) {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
testAcme.validate(testChallenge).then(x => {
|
testSmartAcme.validate(testChallenge).then(x => {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,8 +1,68 @@
|
|||||||
import 'typings-global'
|
import * as q from 'q'
|
||||||
|
|
||||||
|
import * as plugins from './smartacme.plugins'
|
||||||
|
import * as helpers from './smartacme.helpers'
|
||||||
|
|
||||||
|
import { SmartAcme, IRsaKeypair } from './smartacme.classes.smartacme'
|
||||||
|
import { AcmeCert } from './smartacme.classes.acmecert'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class AcmeAccount represents an AcmeAccount
|
* class AcmeAccount represents an AcmeAccount
|
||||||
*/
|
*/
|
||||||
export class AcmeAccount {
|
export class AcmeAccount {
|
||||||
|
parentSmartAcme: SmartAcme
|
||||||
|
location: string
|
||||||
|
link: string
|
||||||
|
JWK
|
||||||
|
constructor(smartAcmeParentArg: SmartAcme) {
|
||||||
|
this.parentSmartAcme = smartAcmeParentArg
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* register the account with letsencrypt
|
||||||
|
*/
|
||||||
|
register() {
|
||||||
|
let done = q.defer()
|
||||||
|
this.parentSmartAcme.rawacmeClient.newReg(
|
||||||
|
{
|
||||||
|
contact: ['mailto:domains@lossless.org']
|
||||||
|
},
|
||||||
|
(err, res) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('smartacme: something went wrong:')
|
||||||
|
console.log(err)
|
||||||
|
done.reject(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.JWK = res.body.key
|
||||||
|
this.link = res.headers.link
|
||||||
|
console.log(this.link)
|
||||||
|
this.location = res.headers.location
|
||||||
|
done.resolve()
|
||||||
|
})
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* agree to letsencrypr terms of service
|
||||||
|
*/
|
||||||
|
agreeTos() {
|
||||||
|
let done = q.defer()
|
||||||
|
let tosPart = this.link.split(',')[1]
|
||||||
|
let tosLinkPortion = tosPart.split(';')[0]
|
||||||
|
let url = tosLinkPortion.split(';')[0].trim().replace(/[<>]/g, '')
|
||||||
|
this.parentSmartAcme.rawacmeClient.post(this.location, { Agreement: url, resource: 'reg' }, (err, res) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err)
|
||||||
|
done.reject(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
done.resolve()
|
||||||
|
})
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
createAcmeCert(domainNameArg: string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -1,8 +1,226 @@
|
|||||||
import 'typings-global'
|
import * as q from 'q'
|
||||||
|
|
||||||
|
import * as plugins from './smartacme.plugins'
|
||||||
|
import * as helpers from './smartacme.helpers'
|
||||||
|
|
||||||
|
import { SmartAcme, IRsaKeypair } from './smartacme.classes.smartacme'
|
||||||
|
import { AcmeAccount } from './smartacme.classes.acmeaccount'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* types of challenges supported by letsencrypt and this module
|
||||||
|
*/
|
||||||
|
export type TChallengeType = 'dns-01' | 'http-01'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* values that a challenge's status can have
|
||||||
|
*/
|
||||||
|
export type TChallengeStatus = 'pending'
|
||||||
|
|
||||||
|
export interface ISmartAcmeChallenge {
|
||||||
|
uri: string
|
||||||
|
status: TChallengeStatus
|
||||||
|
type: TChallengeType
|
||||||
|
token: string
|
||||||
|
keyAuthorization: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ISmartAcmeChallengeAccepted extends ISmartAcmeChallenge {
|
||||||
|
keyHash: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IAcmeCsrConstructorOptions {
|
||||||
|
bit: number,
|
||||||
|
key: string,
|
||||||
|
domain: string,
|
||||||
|
country: string,
|
||||||
|
country_short: string,
|
||||||
|
locality: string,
|
||||||
|
organization: string,
|
||||||
|
organization_short: string,
|
||||||
|
password: string,
|
||||||
|
unstructured: string,
|
||||||
|
subject_alt_names: string[]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class AcmeCert represents a cert for domain
|
* class AcmeCert represents a cert for domain
|
||||||
*/
|
*/
|
||||||
export class AcmeCert {
|
export class AcmeCert {
|
||||||
|
attributes
|
||||||
fullchain: string
|
fullchain: string
|
||||||
|
parentAcmeAccount: AcmeAccount
|
||||||
|
csr
|
||||||
|
validFrom: Date
|
||||||
|
validTo: Date
|
||||||
|
keypair: IRsaKeypair
|
||||||
|
keyPairFinal: IRsaKeypair
|
||||||
|
constructor(optionsArg: IAcmeCsrConstructorOptions, parentSmartAcmeArg) {
|
||||||
|
this.parentAcmeAccount = parentSmartAcmeArg
|
||||||
|
this.keypair = helpers.createKeypair(optionsArg.bit)
|
||||||
|
let privateKeyForged = plugins.nodeForge.pki.privateKeyFromPem(this.keypair.privateKey)
|
||||||
|
let publicKeyForged = plugins.nodeForge.pki.publicKeyToPem(
|
||||||
|
plugins.nodeForge.pki.setRsaPublicKey(privateKeyForged.n, privateKeyForged.e)
|
||||||
|
)
|
||||||
|
this.keyPairFinal = {
|
||||||
|
privateKey: privateKeyForged,
|
||||||
|
publicKey: publicKeyForged
|
||||||
|
}
|
||||||
|
|
||||||
|
// set dates
|
||||||
|
this.validFrom = new Date()
|
||||||
|
this.validTo = new Date()
|
||||||
|
this.validTo.setDate(this.validFrom.getDate() + 90)
|
||||||
|
|
||||||
|
// set attributes
|
||||||
|
this.attributes = [
|
||||||
|
{ name: 'commonName', value: optionsArg.domain },
|
||||||
|
{ name: 'countryName', value: optionsArg.country },
|
||||||
|
{ shortName: 'ST', value: optionsArg.country_short },
|
||||||
|
{ name: 'localityName', value: optionsArg.locality },
|
||||||
|
{ name: 'organizationName', value: optionsArg.organization },
|
||||||
|
{ shortName: 'OU', value: optionsArg.organization_short },
|
||||||
|
{ name: 'challengePassword', value: optionsArg.password },
|
||||||
|
{ name: 'unstructuredName', value: optionsArg.unstructured }
|
||||||
|
]
|
||||||
|
|
||||||
|
// set up csr
|
||||||
|
this.csr = plugins.nodeForge.pki.createCertificationRequest()
|
||||||
|
this.csr.setSubject(this.attributes)
|
||||||
|
this.csr.setAttributes(this.attributes)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* requests a challenge for a domain
|
||||||
|
* @param domainNameArg - the domain name to request a challenge for
|
||||||
|
* @param challengeType - the challenge type to request
|
||||||
|
*/
|
||||||
|
requestChallenge(domainNameArg: string, challengeTypeArg: TChallengeType = 'dns-01') {
|
||||||
|
let done = q.defer<ISmartAcmeChallengeAccepted>()
|
||||||
|
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.newAuthz(
|
||||||
|
{
|
||||||
|
identifier: {
|
||||||
|
type: 'dns',
|
||||||
|
value: domainNameArg
|
||||||
|
}
|
||||||
|
},
|
||||||
|
this.parentAcmeAccount.parentSmartAcme.keyPair,
|
||||||
|
(err, res) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('smartacme: something went wrong:')
|
||||||
|
console.log(err)
|
||||||
|
done.reject(err)
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify(res.body))
|
||||||
|
let dnsChallenge = res.body.challenges.filter(x => {
|
||||||
|
return x.type === challengeTypeArg
|
||||||
|
})[0]
|
||||||
|
this.acceptChallenge(dnsChallenge)
|
||||||
|
.then((x: ISmartAcmeChallengeAccepted) => {
|
||||||
|
done.resolve(x)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* validates a challenge, only call after you have set the challenge at the expected location
|
||||||
|
*/
|
||||||
|
validate(challenge: ISmartAcmeChallengeAccepted) {
|
||||||
|
let done = q.defer()
|
||||||
|
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.poll(challenge.uri, function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err)
|
||||||
|
done.reject(err)
|
||||||
|
}
|
||||||
|
console.log(res.status)
|
||||||
|
console.log(JSON.stringify(res.body))
|
||||||
|
done.resolve()
|
||||||
|
})
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* requests a certificate
|
||||||
|
*/
|
||||||
|
requestCert() {
|
||||||
|
let done = q.defer()
|
||||||
|
let payload = {
|
||||||
|
csr: plugins.rawacme.base64.encode(
|
||||||
|
plugins.rawacme.toDer(
|
||||||
|
plugins.nodeForge.pki.certificationRequestToPem(
|
||||||
|
this.csr
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
notBefore: this.validFrom.toISOString(),
|
||||||
|
notAfter: this.validTo.toISOString()
|
||||||
|
}
|
||||||
|
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.newCert(
|
||||||
|
payload,
|
||||||
|
helpers.createKeypair(),
|
||||||
|
(err, res) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err)
|
||||||
|
done.reject(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getCertificate - takes care of cooldown, validation polling and certificate retrieval
|
||||||
|
*/
|
||||||
|
getCertificate() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* accept a challenge - for private use only
|
||||||
|
*/
|
||||||
|
private acceptChallenge(challenge: ISmartAcmeChallenge) {
|
||||||
|
let done = q.defer()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the key is needed to accept the challenge
|
||||||
|
*/
|
||||||
|
let authKey: string = plugins.rawacme.keyAuthz(
|
||||||
|
challenge.token,
|
||||||
|
this.parentAcmeAccount.parentSmartAcme.keyPair.publicKey
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* needed in case selected challenge is of type dns-01
|
||||||
|
*/
|
||||||
|
let keyHash: string = plugins.rawacme.dnsKeyAuthzHash(authKey) // needed if dns challenge is chosen
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the return challenge
|
||||||
|
*/
|
||||||
|
let returnDNSChallenge: ISmartAcmeChallengeAccepted = {
|
||||||
|
uri: challenge.uri,
|
||||||
|
type: challenge.type,
|
||||||
|
token: challenge.token,
|
||||||
|
keyAuthorization: challenge.keyAuthorization,
|
||||||
|
keyHash: keyHash,
|
||||||
|
status: challenge.status
|
||||||
|
}
|
||||||
|
|
||||||
|
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.post(
|
||||||
|
challenge.uri,
|
||||||
|
{
|
||||||
|
resource: 'challenge',
|
||||||
|
keyAuthorization: authKey
|
||||||
|
},
|
||||||
|
this.parentAcmeAccount.parentSmartAcme.keyPair,
|
||||||
|
(err, res) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err)
|
||||||
|
done.reject(err)
|
||||||
|
}
|
||||||
|
done.resolve(returnDNSChallenge)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return done.promise
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,52 +0,0 @@
|
|||||||
import * as plugins from './smartacme.plugins'
|
|
||||||
import * as helpers from './smartacme.helpers'
|
|
||||||
|
|
||||||
import { IRsaKeypair } from './smartacme.classes.smartacme'
|
|
||||||
|
|
||||||
export interface IAcmeCsrConstructorOptions {
|
|
||||||
bit: number,
|
|
||||||
key: string,
|
|
||||||
domain: string,
|
|
||||||
country: string,
|
|
||||||
country_short: string,
|
|
||||||
locality: string,
|
|
||||||
organization: string,
|
|
||||||
organization_short: string,
|
|
||||||
password: string,
|
|
||||||
unstructured: string,
|
|
||||||
subject_alt_names: string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AcmeCsr {
|
|
||||||
validFrom: Date
|
|
||||||
validTo: Date
|
|
||||||
keypair: IRsaKeypair
|
|
||||||
keyPairForged: IRsaKeypair
|
|
||||||
constructor(optionsArg: IAcmeCsrConstructorOptions) {
|
|
||||||
this.keypair = helpers.createKeypair(optionsArg.bit)
|
|
||||||
let privateKeyForged = plugins.nodeForge.pki.privateKeyFromPem(this.keypair.privateKey)
|
|
||||||
let publicKeyForged = plugins.nodeForge.pki.publicKeyToPem(
|
|
||||||
plugins.nodeForge.pki.setRsaPublicKey(privateKeyForged.n, privateKeyForged.e)
|
|
||||||
)
|
|
||||||
this.keyPairForged = {
|
|
||||||
privateKey: privateKeyForged,
|
|
||||||
publicKey: publicKeyForged
|
|
||||||
}
|
|
||||||
|
|
||||||
// set dates
|
|
||||||
this.validFrom = new Date()
|
|
||||||
this.validTo = new Date()
|
|
||||||
this.validTo.setDate(this.validFrom.getDate() + 90)
|
|
||||||
|
|
||||||
// create the csr
|
|
||||||
let attributes = [
|
|
||||||
{ name: "commonName", value: domain },
|
|
||||||
{ name: "countryName", value: country },
|
|
||||||
{ shortName: "ST", value: country_short },
|
|
||||||
{ name: "localityName", value: locality },
|
|
||||||
{ name: "organizationName", value: organization },
|
|
||||||
{ shortName: "OU", value: organization_short }
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,37 +3,27 @@ import * as q from 'q' // promises
|
|||||||
import * as plugins from './smartacme.plugins'
|
import * as plugins from './smartacme.plugins'
|
||||||
import * as helpers from './smartacme.helpers'
|
import * as helpers from './smartacme.helpers'
|
||||||
|
|
||||||
|
import { AcmeAccount } from './smartacme.classes.acmeaccount'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a rsa keypair needed for account creation and subsequent requests
|
||||||
|
*/
|
||||||
export interface IRsaKeypair {
|
export interface IRsaKeypair {
|
||||||
publicKey: string
|
publicKey: string
|
||||||
privateKey: string
|
privateKey: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TChallengeType = 'dns-01' | 'http-01'
|
export { AcmeAccount } from './smartacme.classes.acmeaccount'
|
||||||
export type TChallengeStatus = 'pending'
|
export { AcmeCert, ISmartAcmeChallenge, ISmartAcmeChallengeAccepted } from './smartacme.classes.acmecert'
|
||||||
|
|
||||||
export interface ISmartAcmeChallenge {
|
|
||||||
uri: string
|
|
||||||
status: TChallengeStatus
|
|
||||||
type: TChallengeType
|
|
||||||
token: string
|
|
||||||
keyAuthorization: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ISmartAcmeChallengeAccepted extends ISmartAcmeChallenge {
|
|
||||||
keyHash: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class SmartAcme exports methods for maintaining SSL Certificates
|
* class SmartAcme exports methods for maintaining SSL Certificates
|
||||||
*/
|
*/
|
||||||
export class SmartAcme {
|
export class SmartAcme {
|
||||||
acmeUrl: string // the acme url to use
|
acmeUrl: string // the acme url to use for this instance
|
||||||
productionBool: boolean // a boolean to quickly know wether we are in production or not
|
productionBool: boolean // a boolean to quickly know wether we are in production or not
|
||||||
keyPair: IRsaKeypair // the keyPair needed for account creation
|
keyPair: IRsaKeypair // the keyPair needed for account creation
|
||||||
location: string
|
|
||||||
link: string
|
|
||||||
rawacmeClient
|
rawacmeClient
|
||||||
JWK
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the constructor for class SmartAcme
|
* the constructor for class SmartAcme
|
||||||
@ -49,10 +39,9 @@ export class SmartAcme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates an account if not currently present in module
|
* init the smartacme instance
|
||||||
* @executes ASYNC
|
|
||||||
*/
|
*/
|
||||||
createAccount() {
|
init() {
|
||||||
let done = q.defer()
|
let done = q.defer()
|
||||||
plugins.rawacme.createClient(
|
plugins.rawacme.createClient(
|
||||||
{
|
{
|
||||||
@ -70,151 +59,24 @@ export class SmartAcme {
|
|||||||
|
|
||||||
// make client available in class
|
// make client available in class
|
||||||
this.rawacmeClient = client
|
this.rawacmeClient = client
|
||||||
|
|
||||||
// create the registration
|
|
||||||
client.newReg(
|
|
||||||
{
|
|
||||||
contact: ['mailto:domains@lossless.org']
|
|
||||||
},
|
|
||||||
(err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('smartacme: something went wrong:')
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.JWK = res.body.key
|
|
||||||
this.link = res.headers.link
|
|
||||||
console.log(this.link)
|
|
||||||
this.location = res.headers.location
|
|
||||||
done.resolve()
|
done.resolve()
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
agreeTos() {
|
|
||||||
let done = q.defer()
|
|
||||||
let tosPart = this.link.split(',')[1]
|
|
||||||
let tosLinkPortion = tosPart.split(';')[0]
|
|
||||||
let url = tosLinkPortion.split(';')[0].trim().replace(/[<>]/g, '')
|
|
||||||
this.rawacmeClient.post(this.location, { Agreement: url, resource: 'reg' }, (err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
done.resolve()
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* requests a challenge for a domain
|
|
||||||
* @param domainNameArg - the domain name to request a challenge for
|
|
||||||
* @param challengeType - the challenge type to request
|
|
||||||
*/
|
|
||||||
requestChallenge(domainNameArg: string, challengeTypeArg: TChallengeType = 'dns-01') {
|
|
||||||
let done = q.defer<ISmartAcmeChallengeAccepted>()
|
|
||||||
this.rawacmeClient.newAuthz(
|
|
||||||
{
|
|
||||||
identifier: {
|
|
||||||
type: 'dns',
|
|
||||||
value: domainNameArg
|
|
||||||
}
|
|
||||||
},
|
|
||||||
this.keyPair,
|
|
||||||
(err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('smartacme: something went wrong:')
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
}
|
|
||||||
console.log(JSON.stringify(res.body))
|
|
||||||
let dnsChallenge = res.body.challenges.filter(x => {
|
|
||||||
return x.type === challengeTypeArg
|
|
||||||
})[0]
|
|
||||||
this.acceptChallenge(dnsChallenge)
|
|
||||||
.then((x: ISmartAcmeChallengeAccepted) => {
|
|
||||||
done.resolve(x)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return done.promise
|
return done.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getCertificate - takes care of cooldown, validation polling and certificate retrieval
|
* creates an account if not currently present in module
|
||||||
|
* @executes ASYNC
|
||||||
*/
|
*/
|
||||||
getCertificate() {
|
createAccount() {
|
||||||
|
let done = q.defer<AcmeAccount>()
|
||||||
}
|
let acmeAccount = new AcmeAccount(this)
|
||||||
|
acmeAccount.register().then(() => {
|
||||||
/**
|
return acmeAccount.agreeTos()
|
||||||
* validates a challenge
|
}).then(() => {
|
||||||
*/
|
done.resolve(acmeAccount)
|
||||||
validate(challenge: ISmartAcmeChallengeAccepted) {
|
|
||||||
let done = q.defer()
|
|
||||||
this.rawacmeClient.poll(challenge.uri, function(err, res) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
}
|
|
||||||
console.log(res.status)
|
|
||||||
console.log(JSON.stringify(res.body))
|
|
||||||
done.resolve()
|
|
||||||
})
|
})
|
||||||
return done.promise
|
return done.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* accept a challenge - for private use only
|
|
||||||
*/
|
|
||||||
private acceptChallenge(challenge: ISmartAcmeChallenge) {
|
|
||||||
let done = q.defer()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the key is needed to accept the challenge
|
|
||||||
*/
|
|
||||||
let authKey: string = plugins.rawacme.keyAuthz(challenge.token, this.keyPair.publicKey)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* needed in case selected challenge is of type dns-01
|
|
||||||
*/
|
|
||||||
let keyHash: string = plugins.rawacme.dnsKeyAuthzHash(authKey) // needed if dns challenge is chosen
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the return challenge
|
|
||||||
*/
|
|
||||||
let returnDNSChallenge: ISmartAcmeChallengeAccepted = {
|
|
||||||
uri: challenge.uri,
|
|
||||||
type: challenge.type,
|
|
||||||
token: challenge.token,
|
|
||||||
keyAuthorization: challenge.keyAuthorization,
|
|
||||||
keyHash: keyHash,
|
|
||||||
status: challenge.status
|
|
||||||
}
|
|
||||||
|
|
||||||
this.rawacmeClient.post(
|
|
||||||
challenge.uri,
|
|
||||||
{
|
|
||||||
resource: 'challenge',
|
|
||||||
keyAuthorization: authKey
|
|
||||||
},
|
|
||||||
this.keyPair,
|
|
||||||
(err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
}
|
|
||||||
done.resolve(returnDNSChallenge)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@ import * as q from 'q'
|
|||||||
import * as plugins from './smartacme.plugins'
|
import * as plugins from './smartacme.plugins'
|
||||||
|
|
||||||
import { SmartAcme, IRsaKeypair } from './smartacme.classes.smartacme'
|
import { SmartAcme, IRsaKeypair } from './smartacme.classes.smartacme'
|
||||||
|
import { AcmeAccount } from './smartacme.classes.acmeaccount'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a keypair to use with requests and to generate JWK from
|
* creates a keypair to use with requests and to generate JWK from
|
||||||
@ -22,12 +21,13 @@ export let createKeypair = (bit = 2048): IRsaKeypair => {
|
|||||||
* gets an existing registration
|
* gets an existing registration
|
||||||
* @executes ASYNC
|
* @executes ASYNC
|
||||||
*/
|
*/
|
||||||
let getReg = (smartAcmeArg: SmartAcme) => {
|
let getReg = (SmartAcmeArg: SmartAcme, location: string) => {
|
||||||
let done = q.defer()
|
let done = q.defer()
|
||||||
let body = { resource: 'reg' }
|
let body = { resource: 'reg' }
|
||||||
smartAcmeArg.rawacmeClient.post(
|
SmartAcmeArg.rawacmeClient.post(
|
||||||
smartAcmeArg.location,
|
location,
|
||||||
body, smartAcmeArg.keyPair,
|
body,
|
||||||
|
SmartAcmeArg.keyPair,
|
||||||
(err, res) => {
|
(err, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('smartacme: something went wrong:')
|
console.error('smartacme: something went wrong:')
|
||||||
|
Loading…
Reference in New Issue
Block a user