diff --git a/package-lock.json b/package-lock.json index a2bb55e..12d3067 100644 --- a/package-lock.json +++ b/package-lock.json @@ -271,12 +271,12 @@ } }, "@pushrocks/smartstring": { - "version": "3.0.5", - "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.5.tgz", - "integrity": "sha512-Bws2s6+Pc0HIXA35QH6cl6LJywhZ1U5icjyYMx+1kH8nURG+njzkacfarr9NWqyVYYOVu7SgXLzp9sR0eH7k9g==", + "version": "3.0.8", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.8.tgz", + "integrity": "sha512-twmCGF47+TJoiCpj6t5MxwcKDDJEATuKqJXxftcHOlXWW743LJ/1bCpMueDdtumo5EheUfSxb43aRse3DU3wig==", "requires": { "crypto-random-string": "^1.0.0", - "js-base64": "^2.4.9", + "js-base64": "^2.5.0", "normalize-newline": "^3.0.0", "randomatic": "^3.1.1", "strip-indent": "^2.0.0" diff --git a/package.json b/package.json index ec76ec4..90fc475 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@pushrocks/smartexpress": "^3.0.0", "@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" diff --git a/test/test.ts b/test/test.ts index 5e66a0c..a4f5447 100644 --- a/test/test.ts +++ b/test/test.ts @@ -30,6 +30,13 @@ tap.test('should create a valid instance of SmartAcme', async () => { // 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(); }); diff --git a/ts/smartacme.classes.certmatcher.ts b/ts/smartacme.classes.certmatcher.ts new file mode 100644 index 0000000..d1e3d0a --- /dev/null +++ b/ts/smartacme.classes.certmatcher.ts @@ -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}`; + } + } +} diff --git a/ts/smartacme.classes.smartacme.ts b/ts/smartacme.classes.smartacme.ts index 09413d5..0cdc618 100644 --- a/ts/smartacme.classes.smartacme.ts +++ b/ts/smartacme.classes.smartacme.ts @@ -1,6 +1,7 @@ import * as plugins from './smartacme.plugins'; import { Cert } from './smartacme.classes.cert'; import { CertManager } from './smartacme.classes.certmanager'; +import { CertMatcher } from './smartacme.classes.certmatcher'; import * as interfaces from './interfaces'; import { request } from 'http'; @@ -44,6 +45,7 @@ export class SmartAcme { // certmanager private certmanager: CertManager; + private certmatcher: CertMatcher; private certremoteHandler: plugins.smartexpress.Handler; constructor(optionsArg: ISmartAcmeOptions) { @@ -68,6 +70,9 @@ export class SmartAcme { }); await this.certmanager.init(); + // CertMatcher + this.certmatcher = new CertMatcher(); + // CertRemoteHandler this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => { const requestBody: interfaces.ICertRemoteRequest = req.body; @@ -118,7 +123,7 @@ export class SmartAcme { } public async getCertificateForDomain(domainArg: string): Promise { - const domain = domainArg; + const domain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg); const retrievedCertificate = await this.certmanager.retrieveCertificate(domain); diff --git a/ts/smartacme.plugins.ts b/ts/smartacme.plugins.ts index 7f2c1fb..7b5a00f 100644 --- a/ts/smartacme.plugins.ts +++ b/ts/smartacme.plugins.ts @@ -7,9 +7,10 @@ import * as smartexpress from '@pushrocks/smartexpress'; 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, smarttime }; +export { lik, smartdata, smartdelay, smartdns, smartexpress, smartpromise, smartrequest, smartunique, smartstring, smarttime }; // thirs party scope import * as acme from 'acme-client';