Compare commits

...

14 Commits

Author SHA1 Message Date
9d23e205d8 2.0.30 2019-01-16 02:34:48 +01:00
5ecdf7c9fd fix(core): update 2019-01-16 02:34:47 +01:00
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
7 changed files with 109 additions and 85 deletions

27
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartacme",
"version": "2.0.23",
"version": "2.0.30",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -104,9 +104,9 @@
}
},
"@pushrocks/qenv": {
"version": "3.0.2",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fqenv/-/qenv-3.0.2.tgz",
"integrity": "sha512-gXW9Cib6izqY7W1MssryFBrjIoKwadftjv5G3y/BE4LboCkGazqjMJsea6z6G79rwvX1M+yxEEcIdIsDvBBSiA==",
"version": "4.0.0",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fqenv/-/qenv-4.0.0.tgz",
"integrity": "sha512-3/odPJaGp3ALtcSG/+N3dGtFX/CVBed9a5XKDa0bv7LoKCgYZeQwpF3jkCnNPjs7GKyzOzALHHID1L+zcb1RXw==",
"dev": true,
"requires": {
"@pushrocks/smartfile": "^6.0.6",
@ -170,13 +170,14 @@
}
},
"@pushrocks/smartexpress": {
"version": "3.0.0",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartexpress/-/smartexpress-3.0.0.tgz",
"integrity": "sha512-F3x+AFUxkKxb5WgQuIZsfkrNzMz0PaYYIw4gdQbAPn5N/UCEP4eE2OQWXnAcCSYwsXI8hgjEuUOC9gTbCSPDRg==",
"version": "3.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartexpress/-/smartexpress-3.0.6.tgz",
"integrity": "sha512-Y/Av43ttryHO93BtrKAalPMQxymEn3HTjylnkgXFOTE5Ir4epGX8cG7FDnKUQIuM9Gx8nzFJfW16a90KUpExxQ==",
"requires": {
"@pushrocks/lik": "^3.0.4",
"@pushrocks/smartfile": "^6.0.11",
"@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartrequest": "^1.1.14",
"@types/express": "^4.16.0",
"@types/finalhandler": "0.0.33",
"@types/helmet": "0.0.42",
@ -205,9 +206,9 @@
}
},
"@pushrocks/smartlog": {
"version": "2.0.9",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog/-/smartlog-2.0.9.tgz",
"integrity": "sha512-F2u3O8OOQ7QXgg9o0lI7HnqEhSQZo2A8u0EuNbQH+Kj2oL62xDwjAg6KkINwH7ObSWpaldZ+I28prG0JxaRzvg==",
"version": "2.0.10",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog/-/smartlog-2.0.10.tgz",
"integrity": "sha512-4Ir4/JvfL+d5VsN+O8BpFSgUc1mWgr9s6S/cwYBCAIrWdqGomUM5RsZs57RMDn9MWW0JGJjGhUA0M+A8LSSgHw==",
"requires": {
"@pushrocks/smartlog-interfaces": "^2.0.2"
}
@ -2350,9 +2351,9 @@
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
},
"tslint": {
"version": "5.12.0",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.12.0.tgz",
"integrity": "sha512-CKEcH1MHUBhoV43SA/Jmy1l24HJJgI0eyLbBNSRyFlsQvb9v6Zdq+Nz2vEOH00nC5SUx4SneJ59PZUS/ARcokQ==",
"version": "5.12.1",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.12.1.tgz",
"integrity": "sha512-sfodBHOucFg6egff8d1BvuofoOQ/nOeYNfbp7LDlKBcLNrL3lmS5zoiDGyOMdT7YsEXAwWpTdAHwOGOc8eRZAw==",
"dev": true,
"requires": {
"babel-code-frame": "^6.22.0",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartacme",
"version": "2.0.23",
"version": "2.0.30",
"private": false,
"description": "acme implementation in TypeScript",
"main": "dist/index.js",
@ -29,23 +29,24 @@
"@pushrocks/smartdata": "^3.1.13",
"@pushrocks/smartdelay": "^2.0.2",
"@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/smartrequest": "^1.1.14",
"@pushrocks/smartstring": "^3.0.8",
"@pushrocks/smarttime": "^3.0.5",
"@pushrocks/smartunique": "^3.0.1",
"acme-client": "^2.2.2"
"acme-client": "2.2.2"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.4",
"@gitzone/tsrun": "^1.1.17",
"@gitzone/tstest": "^1.0.18",
"@mojoio/cloudflare": "^2.0.0",
"@pushrocks/qenv": "^3.0.2",
"@pushrocks/qenv": "^4.0.0",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.18",
"tslint": "^5.12.0",
"tslint": "^5.12.1",
"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',
accountPrivateKey: null,
mongoDescriptor: {
mongoDbName: testQenv.getEnvVarOnDemand('MONGODB_DATABASE'),
mongoDbPass: testQenv.getEnvVarOnDemand('MONGODB_PASSWORD'),
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGODB_URL')
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL')
},
removeChallenge: async (...args) => {
console.log(args);
@ -22,9 +22,7 @@ tap.test('should create a valid instance of SmartAcme', async () => {
setChallenge: async (...args) => {
console.log(args);
},
validateRemoteRequest: async () => {
return true;
}
environment: "integration"
});
await smartAcmeInstance.init();
// await smartAcmeInstance.getCertificateForDomain('bleu.de');

View File

@ -3,7 +3,6 @@ import { Cert } from './smartacme.classes.cert';
import { SmartAcme } from './smartacme.classes.smartacme';
import * as interfaces from './interfaces';
import { ICert } from './interfaces';
export class CertManager {
@ -35,7 +34,7 @@ export class CertManager {
// Pending Map
this.pendingMap = new plugins.lik.Stringmap();
};
}
/**
* retrieves a certificate
@ -57,28 +56,37 @@ export class CertManager {
}
/**
* stores the certificate with the
* @param publicKeyArg
* @param privateKeyArg
* @param csrArg
* stores the certificate
* @param optionsArg
*/
public async storeCertificate(optionsArg: ICert) {
public async storeCertificate(optionsArg: interfaces.ICert) {
const cert = new Cert(optionsArg);
cert.save();
};
await cert.save();
}
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) {
return 'pending';
}
// otherwise lets continue
const existingCertificate = this.retrieveCertificate(domainNameArg);
const existingCertificate = await this.retrieveCertificate(certDomainArg);
if (existingCertificate) {
return 'existing';
}

View File

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

View File

@ -15,13 +15,13 @@ export interface ISmartAcmeOptions {
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
setChallenge: (domainName: string, keyAuthorization: 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
@ -41,12 +41,44 @@ export class SmartAcme {
// challenge fullfillment
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
private removeChallenge: (domainName: string) => Promise<any>;
private validateRemoteRequest: () => Promise<boolean>;
// certmanager
private certmanager: CertManager;
private certmatcher: CertMatcher;
private certremoteHandler: plugins.smartexpress.Handler;
/**
* 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) {
this.options = optionsArg;
@ -73,41 +105,15 @@ export class SmartAcme {
// CertMatcher
this.certmatcher = new CertMatcher();
// CertRemoteHandler
this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => {
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
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
});
@ -124,7 +130,7 @@ export class SmartAcme {
public async getCertificateForDomain(domainArg: string): Promise<Cert> {
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
await this.certmanager.announceCertificate(certDomain);
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomain);
if (retrievedCertificate) {
@ -152,6 +158,8 @@ export class SmartAcme {
/* Satisfy challenge */
await this.setChallenge(domainDnsName, keyAuthorization);
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 */
await this.client.verifyChallenge(authz, dnsChallenge);

View File

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