Compare commits

...

8 Commits

Author SHA1 Message Date
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
4 changed files with 23 additions and 14 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartacme", "name": "@pushrocks/smartacme",
"version": "2.0.22", "version": "2.0.26",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartacme", "name": "@pushrocks/smartacme",
"version": "2.0.22", "version": "2.0.26",
"private": false, "private": false,
"description": "acme implementation in TypeScript", "description": "acme implementation in TypeScript",
"main": "dist/index.js", "main": "dist/index.js",
@ -35,7 +35,7 @@
"@pushrocks/smartstring": "^3.0.8", "@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",

View File

@ -35,7 +35,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
@ -64,8 +64,8 @@ export class CertManager {
*/ */
public async storeCertificate(optionsArg: ICert) { public async storeCertificate(optionsArg: 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) {

View File

@ -16,6 +16,7 @@ export interface ISmartAcmeOptions {
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>; validateRemoteRequest: () => Promise<boolean>;
environment: 'production' | 'integration';
} }
/** /**
@ -107,7 +108,13 @@ export class SmartAcme {
// 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
}); });
@ -123,9 +130,9 @@ export class SmartAcme {
} }
public async getCertificateForDomain(domainArg: string): Promise<Cert> { public async getCertificateForDomain(domainArg: string): Promise<Cert> {
const domain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg); const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
const retrievedCertificate = await this.certmanager.retrieveCertificate(domain); const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomain);
if (retrievedCertificate) { if (retrievedCertificate) {
return retrievedCertificate; return retrievedCertificate;
@ -133,7 +140,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 */
@ -152,6 +159,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);
@ -173,8 +182,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);
@ -186,14 +195,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;
} }
} }