Compare commits

...

30 Commits

Author SHA1 Message Date
2817a65e21 2.0.29 2019-01-15 23:59:21 +01:00
09a8bc5cb5 fix(core): update 2019-01-15 23:59:21 +01:00
a1134cf227 2.0.28 2019-01-15 23:39:31 +01:00
4ee1c4b08c fix(core): update 2019-01-15 23:39:31 +01:00
08c3eaa65f 2.0.27 2019-01-14 02:46:36 +01:00
2717f08476 fix(core): update 2019-01-14 02:46:36 +01:00
f16dbeea32 2.0.26 2019-01-13 21:40:40 +01:00
a0c0230419 fix(core): update 2019-01-13 21:40:40 +01:00
0d1ebf2d1a 2.0.25 2019-01-13 19:40:32 +01:00
6edbf3cb46 fix(core): update 2019-01-13 19:40:32 +01:00
b26f7ac3e9 2.0.24 2019-01-13 19:15:04 +01:00
5129c5d601 fix(core): update 2019-01-13 19:15:03 +01:00
d09b3fd1bc 2.0.23 2019-01-13 02:11:56 +01:00
14fccd40d8 fix(core): update 2019-01-13 02:11:56 +01:00
c0f45a10e0 2.0.22 2019-01-13 02:10:00 +01:00
f9db3d28fe fix(core): update 2019-01-13 02:10:00 +01:00
c3fd8750b2 2.0.21 2019-01-13 00:50:44 +01:00
2b3c28c7a1 fix(core): update 2019-01-13 00:50:43 +01:00
d6b1f942b3 2.0.20 2019-01-13 00:24:40 +01:00
7eff6ea36a fix(core): update 2019-01-13 00:24:39 +01:00
1ef3615a49 2.0.19 2019-01-13 00:06:00 +01:00
3653cdc797 fix(core): update 2019-01-13 00:06:00 +01:00
c0271648fc 2.0.18 2019-01-12 21:06:29 +01:00
5546fa5f49 fix(core): update 2019-01-12 21:06:29 +01:00
54fe89860e 2.0.17 2019-01-12 19:12:53 +01:00
d1edf75f6f fix(core): update 2019-01-12 19:12:52 +01:00
6f9c644221 2.0.16 2019-01-12 19:11:39 +01:00
0b26054687 fix(core): update 2019-01-12 19:11:39 +01:00
e3323ed4ef 2.0.15 2019-01-12 13:52:21 +01:00
24f692636c fix(core): update 2019-01-12 13:52:21 +01:00
9 changed files with 168 additions and 103 deletions

35
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartacme", "name": "@pushrocks/smartacme",
"version": "2.0.14", "version": "2.0.29",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -104,9 +104,9 @@
} }
}, },
"@pushrocks/qenv": { "@pushrocks/qenv": {
"version": "3.0.2", "version": "4.0.0",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fqenv/-/qenv-3.0.2.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fqenv/-/qenv-4.0.0.tgz",
"integrity": "sha512-gXW9Cib6izqY7W1MssryFBrjIoKwadftjv5G3y/BE4LboCkGazqjMJsea6z6G79rwvX1M+yxEEcIdIsDvBBSiA==", "integrity": "sha512-3/odPJaGp3ALtcSG/+N3dGtFX/CVBed9a5XKDa0bv7LoKCgYZeQwpF3jkCnNPjs7GKyzOzALHHID1L+zcb1RXw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@pushrocks/smartfile": "^6.0.6", "@pushrocks/smartfile": "^6.0.6",
@ -170,13 +170,14 @@
} }
}, },
"@pushrocks/smartexpress": { "@pushrocks/smartexpress": {
"version": "3.0.0", "version": "3.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartexpress/-/smartexpress-3.0.0.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartexpress/-/smartexpress-3.0.6.tgz",
"integrity": "sha512-F3x+AFUxkKxb5WgQuIZsfkrNzMz0PaYYIw4gdQbAPn5N/UCEP4eE2OQWXnAcCSYwsXI8hgjEuUOC9gTbCSPDRg==", "integrity": "sha512-Y/Av43ttryHO93BtrKAalPMQxymEn3HTjylnkgXFOTE5Ir4epGX8cG7FDnKUQIuM9Gx8nzFJfW16a90KUpExxQ==",
"requires": { "requires": {
"@pushrocks/lik": "^3.0.4", "@pushrocks/lik": "^3.0.4",
"@pushrocks/smartfile": "^6.0.11", "@pushrocks/smartfile": "^6.0.11",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartrequest": "^1.1.14",
"@types/express": "^4.16.0", "@types/express": "^4.16.0",
"@types/finalhandler": "0.0.33", "@types/finalhandler": "0.0.33",
"@types/helmet": "0.0.42", "@types/helmet": "0.0.42",
@ -205,9 +206,9 @@
} }
}, },
"@pushrocks/smartlog": { "@pushrocks/smartlog": {
"version": "2.0.9", "version": "2.0.10",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog/-/smartlog-2.0.9.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog/-/smartlog-2.0.10.tgz",
"integrity": "sha512-F2u3O8OOQ7QXgg9o0lI7HnqEhSQZo2A8u0EuNbQH+Kj2oL62xDwjAg6KkINwH7ObSWpaldZ+I28prG0JxaRzvg==", "integrity": "sha512-4Ir4/JvfL+d5VsN+O8BpFSgUc1mWgr9s6S/cwYBCAIrWdqGomUM5RsZs57RMDn9MWW0JGJjGhUA0M+A8LSSgHw==",
"requires": { "requires": {
"@pushrocks/smartlog-interfaces": "^2.0.2" "@pushrocks/smartlog-interfaces": "^2.0.2"
} }
@ -271,12 +272,12 @@
} }
}, },
"@pushrocks/smartstring": { "@pushrocks/smartstring": {
"version": "3.0.5", "version": "3.0.8",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.5.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.8.tgz",
"integrity": "sha512-Bws2s6+Pc0HIXA35QH6cl6LJywhZ1U5icjyYMx+1kH8nURG+njzkacfarr9NWqyVYYOVu7SgXLzp9sR0eH7k9g==", "integrity": "sha512-twmCGF47+TJoiCpj6t5MxwcKDDJEATuKqJXxftcHOlXWW743LJ/1bCpMueDdtumo5EheUfSxb43aRse3DU3wig==",
"requires": { "requires": {
"crypto-random-string": "^1.0.0", "crypto-random-string": "^1.0.0",
"js-base64": "^2.4.9", "js-base64": "^2.5.0",
"normalize-newline": "^3.0.0", "normalize-newline": "^3.0.0",
"randomatic": "^3.1.1", "randomatic": "^3.1.1",
"strip-indent": "^2.0.0" "strip-indent": "^2.0.0"
@ -2350,9 +2351,9 @@
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
}, },
"tslint": { "tslint": {
"version": "5.12.0", "version": "5.12.1",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.12.0.tgz", "resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.12.1.tgz",
"integrity": "sha512-CKEcH1MHUBhoV43SA/Jmy1l24HJJgI0eyLbBNSRyFlsQvb9v6Zdq+Nz2vEOH00nC5SUx4SneJ59PZUS/ARcokQ==", "integrity": "sha512-sfodBHOucFg6egff8d1BvuofoOQ/nOeYNfbp7LDlKBcLNrL3lmS5zoiDGyOMdT7YsEXAwWpTdAHwOGOc8eRZAw==",
"dev": true, "dev": true,
"requires": { "requires": {
"babel-code-frame": "^6.22.0", "babel-code-frame": "^6.22.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartacme", "name": "@pushrocks/smartacme",
"version": "2.0.14", "version": "2.0.29",
"private": false, "private": false,
"description": "acme implementation in TypeScript", "description": "acme implementation in TypeScript",
"main": "dist/index.js", "main": "dist/index.js",
@ -29,22 +29,24 @@
"@pushrocks/smartdata": "^3.1.13", "@pushrocks/smartdata": "^3.1.13",
"@pushrocks/smartdelay": "^2.0.2", "@pushrocks/smartdelay": "^2.0.2",
"@pushrocks/smartdns": "^3.0.8", "@pushrocks/smartdns": "^3.0.8",
"@pushrocks/smartexpress": "^3.0.0", "@pushrocks/smartexpress": "^3.0.6",
"@pushrocks/smartlog": "^2.0.10",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartrequest": "^1.1.14", "@pushrocks/smartrequest": "^1.1.14",
"@pushrocks/smartstring": "^3.0.8",
"@pushrocks/smarttime": "^3.0.5", "@pushrocks/smarttime": "^3.0.5",
"@pushrocks/smartunique": "^3.0.1", "@pushrocks/smartunique": "^3.0.1",
"acme-client": "^2.2.2" "acme-client": "2.2.2"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.4", "@gitzone/tsbuild": "^2.1.4",
"@gitzone/tsrun": "^1.1.17", "@gitzone/tsrun": "^1.1.17",
"@gitzone/tstest": "^1.0.18", "@gitzone/tstest": "^1.0.18",
"@mojoio/cloudflare": "^2.0.0", "@mojoio/cloudflare": "^2.0.0",
"@pushrocks/qenv": "^3.0.2", "@pushrocks/qenv": "^4.0.0",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.18", "@types/node": "^10.12.18",
"tslint": "^5.12.0", "tslint": "^5.12.1",
"tslint-config-prettier": "^1.17.0" "tslint-config-prettier": "^1.17.0"
} }
} }

View File

@ -12,9 +12,9 @@ tap.test('should create a valid instance of SmartAcme', async () => {
accountEmail: 'domains@lossless.org', accountEmail: 'domains@lossless.org',
accountPrivateKey: null, accountPrivateKey: null,
mongoDescriptor: { mongoDescriptor: {
mongoDbName: testQenv.getEnvVarOnDemand('MONGODB_DATABASE'), mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
mongoDbPass: testQenv.getEnvVarOnDemand('MONGODB_PASSWORD'), mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGODB_URL') mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL')
}, },
removeChallenge: async (...args) => { removeChallenge: async (...args) => {
console.log(args); console.log(args);
@ -22,12 +22,21 @@ tap.test('should create a valid instance of SmartAcme', async () => {
setChallenge: async (...args) => { setChallenge: async (...args) => {
console.log(args); console.log(args);
}, },
validateRemoteRequest: async () => { environment: "integration"
return true;
}
}); });
await smartAcmeInstance.init(); await smartAcmeInstance.init();
// await smartAcmeInstance.getCertificateForDomain('bleu.de'); // await smartAcmeInstance.getCertificateForDomain('bleu.de');
}); });
tap.test('certmatcher should correctly match domains', async () => {
const certMatcherMod = await import('../ts/smartacme.classes.certmatcher');
const certMatcher = new certMatcherMod.CertMatcher();
const matchedCert = certMatcher.getCertificateDomainNameByDomainName('level3.level2.level1');
expect(matchedCert).to.equal('level2.level1');
});
tap.test('should stop correctly', async () => {
await smartAcmeInstance.stop();
});
tap.start(); tap.start();

View File

@ -31,10 +31,10 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements inte
constructor(optionsArg: ICert) { constructor(optionsArg: ICert) {
super(); super();
this.created = optionsArg.created; if (optionsArg) {
this.domainName = optionsArg.domainName; Object.keys(optionsArg).forEach(key => {
this.privateKey = optionsArg.privateKey; this[key] = optionsArg[key];
this.publicKey = optionsArg.publicKey; });
this.csr = optionsArg.csr; }
} }
} }

View File

@ -3,7 +3,6 @@ import { Cert } from './smartacme.classes.cert';
import { SmartAcme } from './smartacme.classes.smartacme'; import { SmartAcme } from './smartacme.classes.smartacme';
import * as interfaces from './interfaces'; import * as interfaces from './interfaces';
import { ICert } from './interfaces';
export class CertManager { export class CertManager {
@ -35,7 +34,7 @@ export class CertManager {
// Pending Map // Pending Map
this.pendingMap = new plugins.lik.Stringmap(); this.pendingMap = new plugins.lik.Stringmap();
}; }
/** /**
* retrieves a certificate * retrieves a certificate
@ -45,7 +44,7 @@ export class CertManager {
public async retrieveCertificate(domainName: string): Promise<Cert> { public async retrieveCertificate(domainName: string): Promise<Cert> {
await this.checkCerts(); await this.checkCerts();
const existingCertificate: Cert = await Cert.getInstance({ const existingCertificate: Cert = await Cert.getInstance({
name: domainName domainName
}); });
if(existingCertificate) { if(existingCertificate) {
@ -57,28 +56,37 @@ export class CertManager {
} }
/** /**
* stores the certificate with the * stores the certificate
* @param publicKeyArg * @param optionsArg
* @param privateKeyArg
* @param csrArg
*/ */
public async storeCertificate(optionsArg: ICert) { public async storeCertificate(optionsArg: interfaces.ICert) {
const cert = new Cert(optionsArg); const cert = new Cert(optionsArg);
cert.save(); await cert.save();
}; }
public async deleteCertificate(domainNameArg: string) { public async deleteCertificate(domainNameArg: string) {
} }
public async getCertificateStatus(domainNameArg: string): Promise<interfaces.TCertStatus> { /**
const isPending = this.pendingMap.checkString('domainNameArg'); * announce a certificate as being in the process of being retrieved
*/
public async announceCertificate (domainNameArg: string) {
this.pendingMap.addString(domainNameArg);
}
/**
* gets the status of a certificate by certDomain name
* @param certDomainArg
*/
public async getCertificateStatus(certDomainArg: string): Promise<interfaces.TCertStatus> {
const isPending = this.pendingMap.checkString(certDomainArg);
if (isPending) { if (isPending) {
return 'pending'; return 'pending';
} }
// otherwise lets continue // otherwise lets continue
const existingCertificate = this.retrieveCertificate(domainNameArg); const existingCertificate = this.retrieveCertificate(certDomainArg);
if (existingCertificate) { if (existingCertificate) {
return 'existing'; return 'existing';
} }

View File

@ -0,0 +1,10 @@
import * as plugins from './smartacme.plugins';
export class CertMatcher {
public getCertificateDomainNameByDomainName(domainNameArg: string): string {
const originalDomain = new plugins.smartstring.Domain(domainNameArg);
if (!originalDomain.level4) {
return `${originalDomain.level2}.${originalDomain.level1}`;
}
}
}

View File

@ -1,34 +1,41 @@
import * as plugins from './smartacme.plugins'; import * as plugins from './smartacme.plugins';
import * as interfaces from './interfaces'; import * as interfaces from './interfaces';
import { ICertRemoteResponse } from './interfaces';
// tslint:disable-next-line: max-classes-per-file // tslint:disable-next-line: max-classes-per-file
export class CertRemoteClient { export class CertRemoteClient {
private remoteUrl: string; private remoteUrl: string;
private secret: string; private secret: string;
private logger: plugins.smartlog.Smartlog;
constructor(optionsArg: { constructor(optionsArg: {
remoteUrl: string; remoteUrl: string;
secret: string; secret: string;
logger?: plugins.smartlog.Smartlog;
}) { }) {
this.remoteUrl = optionsArg.remoteUrl; this.remoteUrl = optionsArg.remoteUrl;
this.secret = optionsArg.secret; this.secret = optionsArg.secret;
optionsArg.logger
? (this.logger = optionsArg.logger)
: (this.logger = plugins.smartlog.defaultLogger);
} }
/** /**
* *
* @param domainNameArg * @param domainNameArg
*/ */
async getCertificateForDomain(domainNameArg: string): Promise<interfaces.ICert> { public async getCertificateForDomain(domainNameArg: string): Promise<interfaces.ICert> {
let certificate: interfaces.ICert; let certificate: interfaces.ICert;
const doRequestCycle = async (): Promise<interfaces.ICert> => { const doRequestCycle = async (): Promise<interfaces.ICert> => {
const response: ICertRemoteResponse = (await plugins.smartrequest.postJson(this.remoteUrl, { const response: interfaces.ICertRemoteResponse = (await plugins.smartrequest.postJson(
requestBody: <interfaces.ICertRemoteRequest>{ this.remoteUrl,
domainName: domainNameArg, {
secret: this.secret requestBody: <interfaces.ICertRemoteRequest>{
domainName: domainNameArg,
secret: this.secret
}
} }
})).body; )).body;
switch(response.status) { switch (response.status as interfaces.TCertStatus) {
case 'pending': case 'pending':
await plugins.smartdelay.delayFor(5000); await plugins.smartdelay.delayFor(5000);
const finalResponse = await doRequestCycle(); const finalResponse = await doRequestCycle();

View File

@ -1,11 +1,13 @@
import * as plugins from './smartacme.plugins'; import * as plugins from './smartacme.plugins';
import { Cert } from './smartacme.classes.cert';
import { CertManager } from './smartacme.classes.certmanager'; import { CertManager } from './smartacme.classes.certmanager';
import { CertMatcher } from './smartacme.classes.certmatcher';
import * as interfaces from './interfaces'; import * as interfaces from './interfaces';
import { request } from 'http'; import { request } from 'http';
/** /**
* * the options for the class @see SmartAcme
*/ */
export interface ISmartAcmeOptions { export interface ISmartAcmeOptions {
accountPrivateKey?: string; accountPrivateKey?: string;
@ -13,9 +15,19 @@ export interface ISmartAcmeOptions {
mongoDescriptor: plugins.smartdata.IMongoDescriptor; mongoDescriptor: plugins.smartdata.IMongoDescriptor;
setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>; setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
removeChallenge: (domainName: string) => Promise<any>; removeChallenge: (domainName: string) => Promise<any>;
validateRemoteRequest: () => Promise<boolean>; environment: 'production' | 'integration';
} }
/**
* class SmartAcme
* can be used for setting up communication with an ACME authority
*
* ```ts
* const mySmartAcmeInstance = new SmartAcme({
* // see ISmartAcmeOptions for options
* })
* ```
*/
export class SmartAcme { export class SmartAcme {
private options: ISmartAcmeOptions; private options: ISmartAcmeOptions;
@ -29,11 +41,44 @@ export class SmartAcme {
// challenge fullfillment // challenge fullfillment
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>; private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
private removeChallenge: (domainName: string) => Promise<any>; private removeChallenge: (domainName: string) => Promise<any>;
private validateRemoteRequest: () => Promise<boolean>;
// certmanager // certmanager
private certmanager: CertManager; private certmanager: CertManager;
private certremoteHandler: plugins.smartexpress.Handler; private certmatcher: CertMatcher;
/**
* the remote handler to hand the request and response to.
*/
public certremoteHandler = async (req: plugins.smartexpress.Request, res: plugins.smartexpress.Response) => {
const requestBody: interfaces.ICertRemoteRequest = req.body;
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(requestBody.domainName);
let status: interfaces.TCertStatus = await this.certmanager.getCertificateStatus(
certDomain
);
let response: interfaces.ICertRemoteResponse;
switch (status) {
case 'existing':
response = {
status,
certificate: await (await this.certmanager.retrieveCertificate(
certDomain
)).createSavableObject()
};
break;
default:
if (status === "nonexisting") {
this.getCertificateForDomain(certDomain);
status = 'pending';
}
response = {
status
};
break;
}
res.status(200);
res.send(response);
res.end();
}
constructor(optionsArg: ISmartAcmeOptions) { constructor(optionsArg: ISmartAcmeOptions) {
this.options = optionsArg; this.options = optionsArg;
@ -57,41 +102,18 @@ export class SmartAcme {
}); });
await this.certmanager.init(); await this.certmanager.init();
// CertRemoteHandler // CertMatcher
this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => { this.certmatcher = new CertMatcher();
const requestBody: interfaces.ICertRemoteRequest = req.body;
const status: interfaces.TCertStatus = await this.certmanager.getCertificateStatus(requestBody.domainName);
const existingCertificate = await this.certmanager.retrieveCertificate(
requestBody.domainName
);
let response: interfaces.ICertRemoteResponse;
switch (status) {
case 'existing':
response = {
status,
certificate: {
created: existingCertificate.created,
csr: existingCertificate.csr,
domainName: existingCertificate.domainName,
privateKey: existingCertificate.privateKey,
publicKey: existingCertificate.publicKey
}
};
break;
default:
response = {
status
};
break;
}
res.status(200);
res.send(response);
res.end();
});
// ACME Client // ACME Client
this.client = new plugins.acme.Client({ this.client = new plugins.acme.Client({
directoryUrl: plugins.acme.directory.letsencrypt.staging, directoryUrl: (() => {
if (this.options.environment === 'production') {
return plugins.acme.directory.letsencrypt.production;
} else {
return plugins.acme.directory.letsencrypt.staging;
}
})(),
accountKey: this.privateKey accountKey: this.privateKey
}); });
@ -102,12 +124,14 @@ export class SmartAcme {
}); });
} }
public async stop() {}; public async stop() {
await this.certmanager.smartdataDb.close();
}
public async getCertificateForDomain(domainArg: string) { public async getCertificateForDomain(domainArg: string): Promise<Cert> {
const domain = domainArg; const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
await this.certmanager.announceCertificate(certDomain);
const retrievedCertificate = await this.certmanager.retrieveCertificate(domain); const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomain);
if (retrievedCertificate) { if (retrievedCertificate) {
return retrievedCertificate; return retrievedCertificate;
@ -115,7 +139,7 @@ export class SmartAcme {
/* Place new order */ /* Place new order */
const order = await this.client.createOrder({ const order = await this.client.createOrder({
identifiers: [{ type: 'dns', value: domain }, { type: 'dns', value: `*.${domain}` }] identifiers: [{ type: 'dns', value: certDomain }, { type: 'dns', value: `*.${certDomain}` }]
}); });
/* Get authorizations and select challenges */ /* Get authorizations and select challenges */
@ -134,6 +158,8 @@ export class SmartAcme {
/* Satisfy challenge */ /* Satisfy challenge */
await this.setChallenge(domainDnsName, keyAuthorization); await this.setChallenge(domainDnsName, keyAuthorization);
await this.smartdns.checkUntilAvailable(domainDnsName, 'TXT', keyAuthorization, 100, 5000); await this.smartdns.checkUntilAvailable(domainDnsName, 'TXT', keyAuthorization, 100, 5000);
console.log('Cool down an extra 60 second for region availability');
await plugins.smartdelay.delayFor(60000);
/* Verify that challenge is satisfied */ /* Verify that challenge is satisfied */
await this.client.verifyChallenge(authz, dnsChallenge); await this.client.verifyChallenge(authz, dnsChallenge);
@ -155,8 +181,8 @@ export class SmartAcme {
/* Finalize order */ /* Finalize order */
const [key, csr] = await plugins.acme.forge.createCsr({ const [key, csr] = await plugins.acme.forge.createCsr({
commonName: `*.${domain}`, commonName: `*.${certDomain}`,
altNames: [domain] altNames: [certDomain]
}); });
await this.client.finalizeOrder(order, csr); await this.client.finalizeOrder(order, csr);
@ -168,14 +194,14 @@ export class SmartAcme {
console.log(`Certificate:\n${cert.toString()}`); console.log(`Certificate:\n${cert.toString()}`);
await this.certmanager.storeCertificate({ await this.certmanager.storeCertificate({
domainName: domainArg, domainName: certDomain,
privateKey: key.toString(), privateKey: key.toString(),
publicKey: cert.toString(), publicKey: cert.toString(),
csr: csr.toString(), csr: csr.toString(),
created: Date.now() created: Date.now()
}); });
const newCertificate = await this.certmanager.retrieveCertificate(domainArg); const newCertificate = await this.certmanager.retrieveCertificate(certDomain);
return newCertificate; return newCertificate;
} }
} }

View File

@ -4,12 +4,14 @@ import * as smartdata from '@pushrocks/smartdata';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
import * as smartdns from '@pushrocks/smartdns'; import * as smartdns from '@pushrocks/smartdns';
import * as smartexpress from '@pushrocks/smartexpress'; import * as smartexpress from '@pushrocks/smartexpress';
import * as smartlog from '@pushrocks/smartlog';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
import * as smartunique from '@pushrocks/smartunique'; import * as smartunique from '@pushrocks/smartunique';
import * as smartstring from '@pushrocks/smartstring';
import * as smarttime from '@pushrocks/smarttime'; import * as smarttime from '@pushrocks/smarttime';
export { lik, smartdata, smartdelay, smartdns, smartexpress, smartpromise, smartrequest, smartunique, smarttime }; export { lik, smartdata, smartdelay, smartdns, smartexpress, smartlog, smartpromise, smartrequest, smartunique, smartstring, smarttime };
// thirs party scope // thirs party scope
import * as acme from 'acme-client'; import * as acme from 'acme-client';