Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
6c95cec709 | |||
59173b3ca8 | |||
c2036bba90 | |||
83afea95e6 | |||
ac515f5e80 | |||
6abbf58b83 |
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,5 +1,22 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
.nogit/
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
@ -1,10 +1,10 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
@ -20,62 +20,27 @@ mirror:
|
|||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
sast:
|
|
||||||
stage: security
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
|
||||||
variables:
|
|
||||||
DOCKER_DRIVER: overlay2
|
|
||||||
allow_failure: true
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
|
||||||
--volume "$PWD:/code"
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
|
||||||
artifacts:
|
|
||||||
reports:
|
|
||||||
sast: gl-sast-report.json
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
@ -84,6 +49,20 @@ testSTABLE:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -95,6 +74,7 @@ release:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -103,20 +83,14 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
@ -127,18 +101,20 @@ trigger:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci node install lts
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
|
2306
package-lock.json
generated
2306
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
54
package.json
54
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "2.1.0",
|
"version": "3.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "acme with an easy yet powerful interface in TypeScript",
|
"description": "acme with an easy yet powerful interface in TypeScript",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -25,28 +25,40 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.4",
|
"@pushrocks/lik": "^3.0.17",
|
||||||
"@pushrocks/smartdata": "^3.1.13",
|
"@pushrocks/smartdata": "^3.1.25",
|
||||||
"@pushrocks/smartdelay": "^2.0.2",
|
"@pushrocks/smartdelay": "^2.0.6",
|
||||||
"@pushrocks/smartdns": "^3.0.8",
|
"@pushrocks/smartdns": "^3.0.8",
|
||||||
"@pushrocks/smartexpress": "^3.0.6",
|
"@pushrocks/smartexpress": "^3.0.57",
|
||||||
"@pushrocks/smartlog": "^2.0.11",
|
"@pushrocks/smartlog": "^2.0.21",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartrequest": "^1.1.14",
|
"@pushrocks/smartrequest": "^1.1.47",
|
||||||
"@pushrocks/smartstring": "^3.0.8",
|
"@pushrocks/smartstring": "^3.0.18",
|
||||||
"@pushrocks/smarttime": "^3.0.5",
|
"@pushrocks/smarttime": "^3.0.12",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@pushrocks/smartunique": "^3.0.1",
|
||||||
"acme-client": "2.2.2"
|
"@tsclass/tsclass": "^3.0.4",
|
||||||
|
"acme-client": "^3.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.4",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@gitzone/tsrun": "^1.1.17",
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
"@gitzone/tstest": "^1.0.18",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@mojoio/cloudflare": "^2.0.0",
|
"@mojoio/cloudflare": "^4.0.3",
|
||||||
"@pushrocks/qenv": "^4.0.0",
|
"@pushrocks/qenv": "^4.0.6",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
"@types/node": "^10.12.18",
|
"@types/node": "^13.7.0",
|
||||||
"tslint": "^5.12.1",
|
"tslint": "^6.0.0",
|
||||||
"tslint-config-prettier": "^1.17.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_web/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
18
test/test.ts
18
test/test.ts
@ -1,7 +1,12 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import { Qenv } from '@pushrocks/qenv';
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
|
import * as cloudflare from '@mojoio/cloudflare';
|
||||||
|
|
||||||
const testQenv = new Qenv('./', './.nogit/');
|
const testQenv = new Qenv('./', './.nogit/');
|
||||||
|
const testCloudflare = new cloudflare.CloudflareAccount({
|
||||||
|
email: testQenv.getEnvVarOnDemand('CF_EMAIL'),
|
||||||
|
key: testQenv.getEnvVarOnDemand('CF_KEY')
|
||||||
|
});
|
||||||
|
|
||||||
import * as smartacme from '../ts/index';
|
import * as smartacme from '../ts/index';
|
||||||
|
|
||||||
@ -16,16 +21,19 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
|||||||
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
||||||
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL')
|
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL')
|
||||||
},
|
},
|
||||||
removeChallenge: async (...args) => {
|
removeChallenge: async (dnsChallenge) => {
|
||||||
console.log(args);
|
testCloudflare.convenience.acmeRemoveDnsChallenge(dnsChallenge);
|
||||||
},
|
},
|
||||||
setChallenge: async (...args) => {
|
setChallenge: async (dnsChallenge) => {
|
||||||
console.log(args);
|
testCloudflare.convenience.acmeSetDnsChallenge(dnsChallenge);
|
||||||
},
|
},
|
||||||
environment: 'integration'
|
environment: 'integration'
|
||||||
});
|
});
|
||||||
await smartAcmeInstance.init();
|
await smartAcmeInstance.init();
|
||||||
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
});
|
||||||
|
|
||||||
|
tap.test('should get a domain certificate', async () => {
|
||||||
|
await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('certmatcher should correctly match domains', async () => {
|
tap.test('certmatcher should correctly match domains', async () => {
|
||||||
|
@ -1,3 +1 @@
|
|||||||
export * from './smartacme.classes.smartacme';
|
export * from './smartacme.classes.smartacme';
|
||||||
|
|
||||||
export * from './smartacme.classes.certremoteclient';
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export type TCertStatus = 'existing' | 'nonexisting' | 'pending' | 'failed';
|
export type TCertStatus = 'existing' | 'nonexisting' | 'pending' | 'failed';
|
||||||
|
|
||||||
export interface ICert {
|
export interface IOldCert {
|
||||||
id: string;
|
id: string;
|
||||||
domainName: string;
|
domainName: string;
|
||||||
created: number;
|
created: number;
|
||||||
|
@ -9,7 +9,7 @@ import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
|||||||
@plugins.smartdata.Collection(() => {
|
@plugins.smartdata.Collection(() => {
|
||||||
return CertManager.activeDB;
|
return CertManager.activeDB;
|
||||||
})
|
})
|
||||||
export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements interfaces.ICert {
|
export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements plugins.tsclass.network.ICert {
|
||||||
@unI()
|
@unI()
|
||||||
public id: string;
|
public id: string;
|
||||||
|
|
||||||
@ -28,26 +28,30 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements inte
|
|||||||
@svDb()
|
@svDb()
|
||||||
public csr: string;
|
public csr: string;
|
||||||
|
|
||||||
|
@svDb()
|
||||||
|
public validUntil: number;
|
||||||
|
|
||||||
|
public isStillValid(): boolean {
|
||||||
/**
|
return this.validUntil >= Date.now();
|
||||||
* computed value for when the certificate is still valid
|
|
||||||
*/
|
|
||||||
get validUntil (): number {
|
|
||||||
return this.created + plugins.smarttime.getMilliSecondsFromUnits({
|
|
||||||
days: 90
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public shouldBeRenewed(): boolean {
|
||||||
get isStillValid (): boolean {
|
const shouldBeValidAtLeastUntil =
|
||||||
const shouldBeValitAtLeastUntil = Date.now() + plugins.smarttime.getMilliSecondsFromUnits({
|
Date.now() +
|
||||||
|
plugins.smarttime.getMilliSecondsFromUnits({
|
||||||
days: 10
|
days: 10
|
||||||
});
|
});
|
||||||
return this.validUntil >= shouldBeValitAtLeastUntil;
|
return this.validUntil >= shouldBeValidAtLeastUntil;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(optionsArg: interfaces.ICert) {
|
public update(certDataArg: plugins.tsclass.network.ICert) {
|
||||||
|
Object.keys(certDataArg).forEach(key => {
|
||||||
|
this[key] = certDataArg[key];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
constructor(optionsArg: plugins.tsclass.network.ICert) {
|
||||||
super();
|
super();
|
||||||
if (optionsArg) {
|
if (optionsArg) {
|
||||||
Object.keys(optionsArg).forEach(key => {
|
Object.keys(optionsArg).forEach(key => {
|
||||||
|
@ -16,7 +16,7 @@ export class CertManager {
|
|||||||
private mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
private mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
public smartdataDb: plugins.smartdata.SmartdataDb;
|
public smartdataDb: plugins.smartdata.SmartdataDb;
|
||||||
|
|
||||||
public pendingMap: plugins.lik.Stringmap;
|
public interestMap: plugins.lik.InterestMap<string, Cert>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
smartAcmeArg: SmartAcme,
|
smartAcmeArg: SmartAcme,
|
||||||
@ -34,18 +34,17 @@ export class CertManager {
|
|||||||
CertManager.activeDB = this.smartdataDb;
|
CertManager.activeDB = this.smartdataDb;
|
||||||
|
|
||||||
// Pending Map
|
// Pending Map
|
||||||
this.pendingMap = new plugins.lik.Stringmap();
|
this.interestMap = new plugins.lik.InterestMap((certName) => certName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* retrieves a certificate
|
* retrieves a certificate
|
||||||
* @returns the Cert class or null
|
* @returns the Cert class or null
|
||||||
* @param domainName the domain Name to retrieve the vcertificate for
|
* @param certDomainNameArg the domain Name to retrieve the vcertificate for
|
||||||
*/
|
*/
|
||||||
public async retrieveCertificate(domainName: string): Promise<Cert> {
|
public async retrieveCertificate(certDomainNameArg: string): Promise<Cert> {
|
||||||
await this.checkCerts();
|
|
||||||
const existingCertificate: Cert = await Cert.getInstance({
|
const existingCertificate: Cert = await Cert.getInstance({
|
||||||
domainName
|
domainName: certDomainNameArg
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingCertificate) {
|
if (existingCertificate) {
|
||||||
@ -59,44 +58,20 @@ export class CertManager {
|
|||||||
* stores the certificate
|
* stores the certificate
|
||||||
* @param optionsArg
|
* @param optionsArg
|
||||||
*/
|
*/
|
||||||
public async storeCertificate(optionsArg: interfaces.ICert) {
|
public async storeCertificate(optionsArg: plugins.tsclass.network.ICert) {
|
||||||
const cert = new Cert(optionsArg);
|
const cert = new Cert(optionsArg);
|
||||||
await cert.save();
|
await cert.save();
|
||||||
this.pendingMap.removeString(optionsArg.domainName);
|
const interest = this.interestMap.findInterest(cert.domainName);
|
||||||
|
if (interest) {
|
||||||
|
interest.fullfillInterest(cert);
|
||||||
|
interest.markLost();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteCertificate(domainNameArg: string) {}
|
public async deleteCertificate(certDomainNameArg: string) {
|
||||||
|
const cert: Cert = await Cert.getInstance({
|
||||||
/**
|
domainName: certDomainNameArg
|
||||||
* announce a certificate as being in the process of being retrieved
|
});
|
||||||
*/
|
await cert.delete();
|
||||||
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 = await this.retrieveCertificate(certDomainArg);
|
|
||||||
if (existingCertificate) {
|
|
||||||
return 'existing';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'nonexisting';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* checks all certs for expiration
|
|
||||||
*/
|
|
||||||
private async checkCerts() {
|
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
|
||||||
import * as interfaces 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
|
|
||||||
*/
|
|
||||||
public async getCertificateForDomain(domainNameArg: string): Promise<interfaces.ICert> {
|
|
||||||
let certificate: interfaces.ICert;
|
|
||||||
const doRequestCycle = async (): Promise<interfaces.ICert> => {
|
|
||||||
const responseBody: interfaces.ICertRemoteResponse = (await plugins.smartrequest.postJson(
|
|
||||||
this.remoteUrl,
|
|
||||||
{
|
|
||||||
requestBody: <interfaces.ICertRemoteRequest>{
|
|
||||||
domainName: domainNameArg,
|
|
||||||
secret: this.secret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)).body;
|
|
||||||
switch (responseBody.status as interfaces.TCertStatus) {
|
|
||||||
case 'pending':
|
|
||||||
this.logger.log('info', `request for ${domainNameArg} still pending!`);
|
|
||||||
await plugins.smartdelay.delayFor(5000);
|
|
||||||
const finalResponse = await doRequestCycle();
|
|
||||||
return finalResponse;
|
|
||||||
case 'existing':
|
|
||||||
this.logger.log('ok', `got certificate for ${domainNameArg}`);
|
|
||||||
return responseBody.certificate;
|
|
||||||
case 'failed':
|
|
||||||
default:
|
|
||||||
console.log(`could not retrieve certificate for ${domainNameArg}`);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
certificate = await doRequestCycle();
|
|
||||||
return certificate;
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,8 +13,8 @@ export interface ISmartAcmeOptions {
|
|||||||
accountPrivateKey?: string;
|
accountPrivateKey?: string;
|
||||||
accountEmail: string;
|
accountEmail: string;
|
||||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
setChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||||
removeChallenge: (domainName: string) => Promise<any>;
|
removeChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||||
environment: 'production' | 'integration';
|
environment: 'production' | 'integration';
|
||||||
logger?: plugins.smartlog.Smartlog;
|
logger?: plugins.smartlog.Smartlog;
|
||||||
}
|
}
|
||||||
@ -41,53 +41,13 @@ export class SmartAcme {
|
|||||||
private privateKey: string;
|
private privateKey: string;
|
||||||
|
|
||||||
// challenge fullfillment
|
// challenge fullfillment
|
||||||
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
private setChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||||
private removeChallenge: (domainName: string) => Promise<any>;
|
private removeChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||||
|
|
||||||
// certmanager
|
// certmanager
|
||||||
private certmanager: CertManager;
|
private certmanager: CertManager;
|
||||||
private certmatcher: CertMatcher;
|
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;
|
|
||||||
this.logger.log('ok', `got certificate request for ${requestBody.domainName}`);
|
|
||||||
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(
|
|
||||||
requestBody.domainName
|
|
||||||
);
|
|
||||||
this.logger.log('ok', `mapping ${requestBody.domainName} to ${certDomain}`);
|
|
||||||
let status: interfaces.TCertStatus = await this.certmanager.getCertificateStatus(certDomain);
|
|
||||||
let response: interfaces.ICertRemoteResponse;
|
|
||||||
switch (status) {
|
|
||||||
case 'existing':
|
|
||||||
this.logger.log('ok', `certificate exists for ${certDomain}. Sending certificate!`);
|
|
||||||
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;
|
||||||
this.options.logger
|
this.options.logger
|
||||||
@ -103,7 +63,7 @@ export class SmartAcme {
|
|||||||
*/
|
*/
|
||||||
public async init() {
|
public async init() {
|
||||||
this.privateKey =
|
this.privateKey =
|
||||||
this.options.accountPrivateKey || (await plugins.acme.forge.createPrivateKey());
|
this.options.accountPrivateKey || (await plugins.acme.forge.createPrivateKey()).toString();
|
||||||
this.setChallenge = this.options.setChallenge;
|
this.setChallenge = this.options.setChallenge;
|
||||||
this.removeChallenge = this.options.removeChallenge;
|
this.removeChallenge = this.options.removeChallenge;
|
||||||
|
|
||||||
@ -144,8 +104,8 @@ export class SmartAcme {
|
|||||||
* it runs through the following steps
|
* it runs through the following steps
|
||||||
*
|
*
|
||||||
* * look in the database
|
* * look in the database
|
||||||
* * if in the database return it
|
* * if in the database and still valid return it
|
||||||
* * of not in the database announce it
|
* * if not in the database announce it
|
||||||
* * then get it from letsencrypt
|
* * then get it from letsencrypt
|
||||||
* * store it
|
* * store it
|
||||||
* * remove it from the pending map (which it go onto by announcing it)
|
* * remove it from the pending map (which it go onto by announcing it)
|
||||||
@ -154,18 +114,29 @@ export class SmartAcme {
|
|||||||
* @param domainArg
|
* @param domainArg
|
||||||
*/
|
*/
|
||||||
public async getCertificateForDomain(domainArg: string): Promise<Cert> {
|
public async getCertificateForDomain(domainArg: string): Promise<Cert> {
|
||||||
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
const certDomainName = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
||||||
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomain);
|
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomainName);
|
||||||
|
|
||||||
if (retrievedCertificate) {
|
if (!retrievedCertificate && await this.certmanager.interestMap.checkInterest(certDomainName)) {
|
||||||
|
const existingCertificateInterest = this.certmanager.interestMap.findInterest(certDomainName);
|
||||||
|
const certificate = existingCertificateInterest.interestFullfilled;
|
||||||
|
return certificate;
|
||||||
|
} else if (retrievedCertificate && !retrievedCertificate.shouldBeRenewed()) {
|
||||||
return retrievedCertificate;
|
return retrievedCertificate;
|
||||||
} else {
|
} else if (retrievedCertificate && retrievedCertificate.shouldBeRenewed) {
|
||||||
await this.certmanager.announceCertificate(certDomain);
|
await retrievedCertificate.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lets make sure others get the same interest
|
||||||
|
await this.certmanager.interestMap.addInterest(certDomainName);
|
||||||
|
|
||||||
|
|
||||||
/* Place new order */
|
/* Place new order */
|
||||||
const order = await this.client.createOrder({
|
const order = await this.client.createOrder({
|
||||||
identifiers: [{ type: 'dns', value: certDomain }, { type: 'dns', value: `*.${certDomain}` }]
|
identifiers: [
|
||||||
|
{ type: 'dns', value: certDomainName },
|
||||||
|
{ type: 'dns', value: `*.${certDomainName}` }
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Get authorizations and select challenges */
|
/* Get authorizations and select challenges */
|
||||||
@ -173,7 +144,7 @@ export class SmartAcme {
|
|||||||
|
|
||||||
for (const authz of authorizations) {
|
for (const authz of authorizations) {
|
||||||
console.log(authz);
|
console.log(authz);
|
||||||
const domainDnsName: string = `_acme-challenge.${authz.identifier.value}`;
|
const fullHostName: string = `_acme-challenge.${authz.identifier.value}`;
|
||||||
const dnsChallenge: string = authz.challenges.find(challengeArg => {
|
const dnsChallenge: string = authz.challenges.find(challengeArg => {
|
||||||
return challengeArg.type === 'dns-01';
|
return challengeArg.type === 'dns-01';
|
||||||
});
|
});
|
||||||
@ -182,8 +153,11 @@ export class SmartAcme {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
/* Satisfy challenge */
|
/* Satisfy challenge */
|
||||||
await this.setChallenge(domainDnsName, keyAuthorization);
|
await this.setChallenge({
|
||||||
await this.smartdns.checkUntilAvailable(domainDnsName, 'TXT', keyAuthorization, 100, 5000);
|
hostName: fullHostName,
|
||||||
|
challenge: keyAuthorization
|
||||||
|
});
|
||||||
|
await this.smartdns.checkUntilAvailable(fullHostName, 'TXT', keyAuthorization, 100, 5000);
|
||||||
console.log('Cool down an extra 60 second for region availability');
|
console.log('Cool down an extra 60 second for region availability');
|
||||||
await plugins.smartdelay.delayFor(60000);
|
await plugins.smartdelay.delayFor(60000);
|
||||||
|
|
||||||
@ -198,7 +172,10 @@ export class SmartAcme {
|
|||||||
} finally {
|
} finally {
|
||||||
/* Clean up challenge response */
|
/* Clean up challenge response */
|
||||||
try {
|
try {
|
||||||
await this.removeChallenge(domainDnsName);
|
await this.removeChallenge({
|
||||||
|
hostName: fullHostName,
|
||||||
|
challenge: keyAuthorization
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
@ -207,8 +184,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: `*.${certDomain}`,
|
commonName: `*.${certDomainName}`,
|
||||||
altNames: [certDomain]
|
altNames: [certDomainName]
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.client.finalizeOrder(order, csr);
|
await this.client.finalizeOrder(order, csr);
|
||||||
@ -218,14 +195,19 @@ export class SmartAcme {
|
|||||||
|
|
||||||
await this.certmanager.storeCertificate({
|
await this.certmanager.storeCertificate({
|
||||||
id: plugins.smartunique.shortId(),
|
id: plugins.smartunique.shortId(),
|
||||||
domainName: certDomain,
|
domainName: certDomainName,
|
||||||
privateKey: key.toString(),
|
privateKey: key.toString(),
|
||||||
publicKey: cert.toString(),
|
publicKey: cert.toString(),
|
||||||
csr: csr.toString(),
|
csr: csr.toString(),
|
||||||
created: Date.now()
|
created: Date.now(),
|
||||||
|
validUntil:
|
||||||
|
Date.now() +
|
||||||
|
plugins.smarttime.getMilliSecondsFromUnits({
|
||||||
|
days: 90
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const newCertificate = await this.certmanager.retrieveCertificate(certDomain);
|
const newCertificate = await this.certmanager.retrieveCertificate(certDomainName);
|
||||||
return newCertificate;
|
return newCertificate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,14 @@ export {
|
|||||||
smarttime
|
smarttime
|
||||||
};
|
};
|
||||||
|
|
||||||
// thirs party scope
|
// @tsclass scope
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export {
|
||||||
|
tsclass
|
||||||
|
}
|
||||||
|
|
||||||
|
// third party scope
|
||||||
import * as acme from 'acme-client';
|
import * as acme from 'acme-client';
|
||||||
|
|
||||||
export { acme };
|
export { acme };
|
||||||
|
Reference in New Issue
Block a user