Compare commits

...

14 Commits

Author SHA1 Message Date
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
8 changed files with 50 additions and 19 deletions

10
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartacme", "name": "@pushrocks/smartacme",
"version": "2.0.15", "version": "2.0.22",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -271,12 +271,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"

View File

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

View File

@ -30,4 +30,15 @@ tap.test('should create a valid instance of SmartAcme', async () => {
// 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

@ -45,7 +45,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) {

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,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;
@ -17,8 +19,8 @@ export interface ISmartAcmeOptions {
} }
/** /**
* The main SmartAcme class * class SmartAcme
* can be used setting up communication with an ACME authority * can be used for setting up communication with an ACME authority
* *
* ```ts * ```ts
* const mySmartAcmeInstance = new SmartAcme({ * const mySmartAcmeInstance = new SmartAcme({
@ -43,6 +45,7 @@ export class SmartAcme {
// certmanager // certmanager
private certmanager: CertManager; private certmanager: CertManager;
private certmatcher: CertMatcher;
private certremoteHandler: plugins.smartexpress.Handler; private certremoteHandler: plugins.smartexpress.Handler;
constructor(optionsArg: ISmartAcmeOptions) { constructor(optionsArg: ISmartAcmeOptions) {
@ -67,6 +70,9 @@ export class SmartAcme {
}); });
await this.certmanager.init(); await this.certmanager.init();
// CertMatcher
this.certmatcher = new CertMatcher();
// CertRemoteHandler // CertRemoteHandler
this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => { this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => {
const requestBody: interfaces.ICertRemoteRequest = req.body; const requestBody: interfaces.ICertRemoteRequest = req.body;
@ -112,10 +118,12 @@ 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 domain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
const retrievedCertificate = await this.certmanager.retrieveCertificate(domain); const retrievedCertificate = await this.certmanager.retrieveCertificate(domain);

View File

@ -7,9 +7,10 @@ import * as smartexpress from '@pushrocks/smartexpress';
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, smartpromise, smartrequest, smartunique, smartstring, smarttime };
// thirs party scope // thirs party scope
import * as acme from 'acme-client'; import * as acme from 'acme-client';