Compare commits
43 Commits
Author | SHA1 | Date | |
---|---|---|---|
c2036bba90 | |||
83afea95e6 | |||
ac515f5e80 | |||
6abbf58b83 | |||
9c25ecdc02 | |||
81a15da2d0 | |||
86929251ba | |||
1d8fb2b296 | |||
9d5f0d7a5d | |||
82b1d68576 | |||
e04b23aceb | |||
8e255938b5 | |||
f2eb9666a7 | |||
cbdb0c8b08 | |||
f821f4d9cc | |||
6cfcf21d95 | |||
a33090bb5e | |||
3151829f85 | |||
eca63e588c | |||
9d23e205d8 | |||
5ecdf7c9fd | |||
2817a65e21 | |||
09a8bc5cb5 | |||
a1134cf227 | |||
4ee1c4b08c | |||
08c3eaa65f | |||
2717f08476 | |||
f16dbeea32 | |||
a0c0230419 | |||
0d1ebf2d1a | |||
6edbf3cb46 | |||
b26f7ac3e9 | |||
5129c5d601 | |||
d09b3fd1bc | |||
14fccd40d8 | |||
c0f45a10e0 | |||
f9db3d28fe | |||
c3fd8750b2 | |||
2b3c28c7a1 | |||
d6b1f942b3 | |||
7eff6ea36a | |||
1ef3615a49 | |||
3653cdc797 |
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
|
134
.gitlab-ci.yml
134
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
|||||||
# 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
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,127 +18,103 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- 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:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- 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
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
testSTABLE:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
# ====================
|
# ====================
|
||||||
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:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- 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:
|
||||||
@ -146,5 +122,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
63
README.md
63
README.md
@ -1,24 +1,19 @@
|
|||||||
# smartacme
|
# @pushrocks/smartuniverse
|
||||||
|
acme with an easy yet powerful interface in TypeScript
|
||||||
|
|
||||||
acme implementation in TypeScript
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||||
## Availabililty
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartuniverse)
|
||||||
[](https://www.npmjs.com/package/smartacme)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/)
|
||||||
[](https://GitLab.com/umbrellazone/smartacme)
|
|
||||||
[](https://github.com/umbrellazone/smartacme)
|
|
||||||
[](https://umbrellazone.gitlab.io/smartacme/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||||
[](https://www.npmjs.com/package/smartacme)
|
[](https://snyk.io/test/npm/@pushrocks/smartuniverse)
|
||||||
[](https://david-dm.org/umbrellazone/smartacme)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://www.bithound.io/github/umbrellazone/smartacme/master/dependencies/npm)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://www.bithound.io/github/umbrellazone/smartacme)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -28,36 +23,14 @@ Use TypeScript for best in class instellisense.
|
|||||||
```javascript
|
```javascript
|
||||||
import { SmartAcme } from 'smartacme';
|
import { SmartAcme } from 'smartacme';
|
||||||
|
|
||||||
let smac = new SmartAcme()(async () => {
|
let smac = new SmartAcme()
|
||||||
// learn async/await, it'll make your life easier
|
|
||||||
|
|
||||||
// optionally accepts a filePath Arg with a stored acmeaccount.json
|
// TODO
|
||||||
// will create an account and
|
|
||||||
let myAccount = await smac.createAcmeAccount();
|
|
||||||
|
|
||||||
// will return a dnsHash to set in your DNS record
|
|
||||||
let myCert = await myAccount.createAcmeCert('example.com');
|
|
||||||
|
|
||||||
// gets and accepts the specified challenge
|
|
||||||
// first argument optional, defaults to dns-01 (which is the cleanest method for production use)
|
|
||||||
let myChallenge = await myCert.getChallenge('dns-01');
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
Now you need to set the challenge in your DNS
|
|
||||||
myChallenge.domainNamePrefixed is the address for the record
|
|
||||||
myChallenge.dnsKeyHash is the ready to use txt record value expected by letsencrypt
|
|
||||||
-------------*/
|
|
||||||
})();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Other relevant npm modules
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
| module name | description |
|
|
||||||
| ----------- | ------------------------------------------------------------------- |
|
|
||||||
| cert | a higlevel production module that uses smartacme to manage certs |
|
|
||||||
| smartnginx | a highlevel production tool for docker environments to manage nginx |
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
[](https://umbrella.zone
|
[](https://maintainedby.lossless.com)
|
||||||
|
@ -1,4 +1,16 @@
|
|||||||
{
|
{
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartuniverse",
|
||||||
|
"shortDescription": "acme with an easy yet powerful interface in TypeScript",
|
||||||
|
"npmPackagename": "@pushrocks/smartuniverse",
|
||||||
|
"license": "MIT",
|
||||||
|
"projectDomain": "push.rocks"
|
||||||
|
}
|
||||||
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
2321
package-lock.json
generated
2321
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
53
package.json
53
package.json
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "2.0.18",
|
"version": "2.1.2",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "acme implementation in TypeScript",
|
"description": "acme with an easy yet powerful interface in TypeScript",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -25,26 +25,39 @@
|
|||||||
},
|
},
|
||||||
"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.0",
|
"@pushrocks/smartexpress": "^3.0.57",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartlog": "^2.0.21",
|
||||||
"@pushrocks/smartrequest": "^1.1.14",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smarttime": "^3.0.5",
|
"@pushrocks/smartrequest": "^1.1.47",
|
||||||
|
"@pushrocks/smartstring": "^3.0.18",
|
||||||
|
"@pushrocks/smarttime": "^3.0.12",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@pushrocks/smartunique": "^3.0.1",
|
||||||
"acme-client": "^2.2.2"
|
"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": "^3.0.5",
|
||||||
"@pushrocks/qenv": "^3.0.2",
|
"@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.0",
|
"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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
22
test/test.ts
22
test/test.ts
@ -12,9 +12,9 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
|||||||
accountEmail: 'domains@lossless.org',
|
accountEmail: 'domains@lossless.org',
|
||||||
accountPrivateKey: null,
|
accountPrivateKey: null,
|
||||||
mongoDescriptor: {
|
mongoDescriptor: {
|
||||||
mongoDbName: testQenv.getEnvVarOnDemand('MONGODB_DATABASE'),
|
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
|
||||||
mongoDbPass: testQenv.getEnvVarOnDemand('MONGODB_PASSWORD'),
|
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
||||||
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGODB_URL')
|
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL')
|
||||||
},
|
},
|
||||||
removeChallenge: async (...args) => {
|
removeChallenge: async (...args) => {
|
||||||
console.log(args);
|
console.log(args);
|
||||||
@ -22,12 +22,20 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
|||||||
setChallenge: async (...args) => {
|
setChallenge: async (...args) => {
|
||||||
console.log(args);
|
console.log(args);
|
||||||
},
|
},
|
||||||
validateRemoteRequest: async () => {
|
environment: 'integration'
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
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 () => {
|
||||||
|
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 () => {
|
tap.test('should stop correctly', async () => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export type TCertStatus = 'existing' | 'nonexisting' | 'pending' | 'failed';
|
export type TCertStatus = 'existing' | 'nonexisting' | 'pending' | 'failed';
|
||||||
|
|
||||||
export interface ICert {
|
export interface ICert {
|
||||||
|
id: string;
|
||||||
domainName: string;
|
domainName: string;
|
||||||
created: number;
|
created: number;
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
|
@ -5,14 +5,13 @@ import * as interfaces from './interfaces';
|
|||||||
import { CertManager } from './smartacme.classes.certmanager';
|
import { CertManager } from './smartacme.classes.certmanager';
|
||||||
|
|
||||||
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
||||||
import { ICert } from './interfaces';
|
|
||||||
|
|
||||||
@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 interfaces.ICert {
|
||||||
@unI()
|
@unI()
|
||||||
public index: string;
|
public id: string;
|
||||||
|
|
||||||
@svDb()
|
@svDb()
|
||||||
public domainName: string;
|
public domainName: string;
|
||||||
@ -29,12 +28,33 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements inte
|
|||||||
@svDb()
|
@svDb()
|
||||||
public csr: string;
|
public csr: string;
|
||||||
|
|
||||||
constructor(optionsArg: ICert) {
|
/**
|
||||||
|
* computed value for when the certificate is still valid
|
||||||
|
*/
|
||||||
|
get validUntil(): number {
|
||||||
|
return (
|
||||||
|
this.created +
|
||||||
|
plugins.smarttime.getMilliSecondsFromUnits({
|
||||||
|
days: 90
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isStillValid(): boolean {
|
||||||
|
const shouldBeValitAtLeastUntil =
|
||||||
|
Date.now() +
|
||||||
|
plugins.smarttime.getMilliSecondsFromUnits({
|
||||||
|
days: 10
|
||||||
|
});
|
||||||
|
return this.validUntil >= shouldBeValitAtLeastUntil;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(optionsArg: interfaces.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;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@ import { Cert } from './smartacme.classes.cert';
|
|||||||
import { SmartAcme } from './smartacme.classes.smartacme';
|
import { SmartAcme } from './smartacme.classes.smartacme';
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
import { ICert } from './interfaces';
|
|
||||||
|
|
||||||
|
|
||||||
export class CertManager {
|
export class CertManager {
|
||||||
// =========
|
// =========
|
||||||
@ -12,7 +10,6 @@ export class CertManager {
|
|||||||
// =========
|
// =========
|
||||||
public static activeDB: plugins.smartdata.SmartdataDb;
|
public static activeDB: plugins.smartdata.SmartdataDb;
|
||||||
|
|
||||||
|
|
||||||
// =========
|
// =========
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
// =========
|
// =========
|
||||||
@ -21,13 +18,16 @@ export class CertManager {
|
|||||||
|
|
||||||
public pendingMap: plugins.lik.Stringmap;
|
public pendingMap: plugins.lik.Stringmap;
|
||||||
|
|
||||||
constructor(smartAcmeArg: SmartAcme,optionsArg: {
|
constructor(
|
||||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
smartAcmeArg: SmartAcme,
|
||||||
}) {
|
optionsArg: {
|
||||||
|
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
|
}
|
||||||
|
) {
|
||||||
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init () {
|
public async init() {
|
||||||
// Smartdata DB
|
// Smartdata DB
|
||||||
this.smartdataDb = new plugins.smartdata.SmartdataDb(this.mongoDescriptor);
|
this.smartdataDb = new plugins.smartdata.SmartdataDb(this.mongoDescriptor);
|
||||||
await this.smartdataDb.init();
|
await this.smartdataDb.init();
|
||||||
@ -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
|
||||||
@ -45,40 +45,47 @@ 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) {
|
||||||
return existingCertificate;
|
return existingCertificate;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stores the certificate with the
|
* stores the certificate
|
||||||
* @param publicKeyArg
|
* @param optionsArg
|
||||||
* @param privateKeyArg
|
|
||||||
* @param csrArg
|
|
||||||
*/
|
*/
|
||||||
public async storeCertificate(optionsArg: ICert) {
|
public async storeCertificate(optionsArg: interfaces.ICert) {
|
||||||
const cert = new Cert(optionsArg);
|
const cert = new Cert(optionsArg);
|
||||||
cert.save();
|
await cert.save();
|
||||||
};
|
this.pendingMap.removeString(optionsArg.domainName);
|
||||||
|
|
||||||
public async deleteCertificate(domainNameArg: string) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getCertificateStatus(domainNameArg: string): Promise<interfaces.TCertStatus> {
|
public async deleteCertificate(domainNameArg: string) {}
|
||||||
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) {
|
if (isPending) {
|
||||||
return 'pending';
|
return 'pending';
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise lets continue
|
// otherwise lets continue
|
||||||
const existingCertificate = this.retrieveCertificate(domainNameArg);
|
const existingCertificate = await this.retrieveCertificate(certDomainArg);
|
||||||
if (existingCertificate) {
|
if (existingCertificate) {
|
||||||
return 'existing';
|
return 'existing';
|
||||||
}
|
}
|
||||||
@ -89,5 +96,7 @@ export class CertManager {
|
|||||||
/**
|
/**
|
||||||
* checks all certs for expiration
|
* checks all certs for expiration
|
||||||
*/
|
*/
|
||||||
private async checkCerts() {};
|
private async checkCerts() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
19
ts/smartacme.classes.certmatcher.ts
Normal file
19
ts/smartacme.classes.certmatcher.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import * as plugins from './smartacme.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* certmatcher is responsible for matching certificates
|
||||||
|
*/
|
||||||
|
export class CertMatcher {
|
||||||
|
/**
|
||||||
|
* creates a domainName for the certificate that will include the broadest scope
|
||||||
|
* for wild card certificates
|
||||||
|
* @param domainNameArg the domainNameArg to create the scope from
|
||||||
|
*/
|
||||||
|
public getCertificateDomainNameByDomainName(domainNameArg: string): string {
|
||||||
|
const originalDomain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
|
if (!originalDomain.level4) {
|
||||||
|
return `${originalDomain.level2}.${originalDomain.level1}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,40 +1,48 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
import * as plugins from './smartacme.plugins';
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
import { ICertRemoteResponse } from './interfaces';
|
|
||||||
|
|
||||||
// tslint:disable-next-line: max-classes-per-file
|
// tslint:disable-next-line: max-classes-per-file
|
||||||
export class CertRemoteClient {
|
export class CertRemoteClient {
|
||||||
private remoteUrl: string;
|
private remoteUrl: string;
|
||||||
private secret: string;
|
private secret: string;
|
||||||
|
private logger: plugins.smartlog.Smartlog;
|
||||||
|
|
||||||
constructor(optionsArg: {
|
constructor(optionsArg: {
|
||||||
remoteUrl: string;
|
remoteUrl: string;
|
||||||
secret: string;
|
secret: string;
|
||||||
|
logger?: plugins.smartlog.Smartlog;
|
||||||
}) {
|
}) {
|
||||||
this.remoteUrl = optionsArg.remoteUrl;
|
this.remoteUrl = optionsArg.remoteUrl;
|
||||||
this.secret = optionsArg.secret;
|
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;
|
let certificate: interfaces.ICert;
|
||||||
const doRequestCycle = async (): Promise<interfaces.ICert> => {
|
const doRequestCycle = async (): Promise<interfaces.ICert> => {
|
||||||
const response: ICertRemoteResponse = (await plugins.smartrequest.postJson(this.remoteUrl, {
|
const responseBody: interfaces.ICertRemoteResponse = (
|
||||||
requestBody: <interfaces.ICertRemoteRequest>{
|
await plugins.smartrequest.postJson(this.remoteUrl, {
|
||||||
domainName: domainNameArg,
|
requestBody: <interfaces.ICertRemoteRequest>{
|
||||||
secret: this.secret
|
domainName: domainNameArg,
|
||||||
}
|
secret: this.secret
|
||||||
})).body;
|
}
|
||||||
switch(response.status) {
|
})
|
||||||
|
).body;
|
||||||
|
switch (responseBody.status as interfaces.TCertStatus) {
|
||||||
case 'pending':
|
case 'pending':
|
||||||
|
this.logger.log('info', `request for ${domainNameArg} still pending!`);
|
||||||
await plugins.smartdelay.delayFor(5000);
|
await plugins.smartdelay.delayFor(5000);
|
||||||
const finalResponse = await doRequestCycle();
|
const finalResponse = await doRequestCycle();
|
||||||
return finalResponse;
|
return finalResponse;
|
||||||
case 'existing':
|
case 'existing':
|
||||||
return response.certificate;
|
this.logger.log('ok', `got certificate for ${domainNameArg}`);
|
||||||
|
return responseBody.certificate;
|
||||||
case 'failed':
|
case 'failed':
|
||||||
default:
|
default:
|
||||||
console.log(`could not retrieve certificate for ${domainNameArg}`);
|
console.log(`could not retrieve certificate for ${domainNameArg}`);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
import * as plugins from './smartacme.plugins';
|
||||||
import { Cert } from './smartacme.classes.cert';
|
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';
|
||||||
@ -14,7 +15,8 @@ export interface ISmartAcmeOptions {
|
|||||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
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>;
|
environment: 'production' | 'integration';
|
||||||
|
logger?: plugins.smartlog.Smartlog;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,6 +35,7 @@ export class SmartAcme {
|
|||||||
// the acme client
|
// the acme client
|
||||||
private client: any;
|
private client: any;
|
||||||
private smartdns = new plugins.smartdns.Smartdns();
|
private smartdns = new plugins.smartdns.Smartdns();
|
||||||
|
public logger: plugins.smartlog.Smartlog;
|
||||||
|
|
||||||
// the account private key
|
// the account private key
|
||||||
private privateKey: string;
|
private privateKey: string;
|
||||||
@ -40,14 +43,56 @@ export class SmartAcme {
|
|||||||
// challenge fullfillment
|
// challenge fullfillment
|
||||||
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
||||||
private removeChallenge: (domainName: string) => Promise<any>;
|
private removeChallenge: (domainName: string) => Promise<any>;
|
||||||
private validateRemoteRequest: () => Promise<boolean>;
|
|
||||||
|
|
||||||
// certmanager
|
// certmanager
|
||||||
private certmanager: CertManager;
|
private certmanager: CertManager;
|
||||||
private certremoteHandler: plugins.smartexpress.Handler;
|
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.logger = optionsArg.logger)
|
||||||
|
: (this.logger = plugins.smartlog.defaultLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,7 +103,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;
|
||||||
|
|
||||||
@ -68,41 +113,18 @@ export class SmartAcme {
|
|||||||
});
|
});
|
||||||
await this.certmanager.init();
|
await this.certmanager.init();
|
||||||
|
|
||||||
// CertRemoteHandler
|
// CertMatcher
|
||||||
this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => {
|
this.certmatcher = new CertMatcher();
|
||||||
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
|
// 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
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -117,18 +139,36 @@ export class SmartAcme {
|
|||||||
await this.certmanager.smartdataDb.close();
|
await this.certmanager.smartdataDb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets a certificate
|
||||||
|
* it runs through the following steps
|
||||||
|
*
|
||||||
|
* * look in the database
|
||||||
|
* * if in the database return it
|
||||||
|
* * of not in the database announce it
|
||||||
|
* * then get it from letsencrypt
|
||||||
|
* * store it
|
||||||
|
* * remove it from the pending map (which it go onto by announcing it)
|
||||||
|
* * retrieve it from the databse and return it
|
||||||
|
*
|
||||||
|
* @param domainArg
|
||||||
|
*/
|
||||||
public async getCertificateForDomain(domainArg: string): Promise<Cert> {
|
public async getCertificateForDomain(domainArg: string): Promise<Cert> {
|
||||||
const domain = domainArg;
|
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
||||||
|
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomain);
|
||||||
const retrievedCertificate = await this.certmanager.retrieveCertificate(domain);
|
|
||||||
|
|
||||||
if (retrievedCertificate) {
|
if (retrievedCertificate) {
|
||||||
return retrievedCertificate;
|
return retrievedCertificate;
|
||||||
|
} else {
|
||||||
|
await this.certmanager.announceCertificate(certDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 */
|
||||||
@ -147,6 +187,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);
|
||||||
@ -168,27 +210,25 @@ 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);
|
||||||
const cert = await this.client.getCertificate(order);
|
const cert = await this.client.getCertificate(order);
|
||||||
|
|
||||||
/* Done */
|
/* Done */
|
||||||
console.log(`CSR:\n${csr.toString()}`);
|
|
||||||
console.log(`Private key:\n${key.toString()}`);
|
|
||||||
console.log(`Certificate:\n${cert.toString()}`);
|
|
||||||
|
|
||||||
await this.certmanager.storeCertificate({
|
await this.certmanager.storeCertificate({
|
||||||
domainName: domainArg,
|
id: plugins.smartunique.shortId(),
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,26 @@ import * as smartdata from '@pushrocks/smartdata';
|
|||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smartdns from '@pushrocks/smartdns';
|
import * as smartdns from '@pushrocks/smartdns';
|
||||||
import * as smartexpress from '@pushrocks/smartexpress';
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
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,
|
||||||
|
smartlog,
|
||||||
|
smartpromise,
|
||||||
|
smartrequest,
|
||||||
|
smartunique,
|
||||||
|
smartstring,
|
||||||
|
smarttime
|
||||||
|
};
|
||||||
|
|
||||||
// thirs party scope
|
// thirs party scope
|
||||||
import * as acme from 'acme-client';
|
import * as acme from 'acme-client';
|
||||||
|
Reference in New Issue
Block a user