Compare commits
63 Commits
Author | SHA1 | Date | |
---|---|---|---|
8cda69b3c2 | |||
3641d75e2f | |||
fd343c1558 | |||
76650ac199 | |||
d9ba5f20b1 | |||
941923e90f | |||
e38b4c1215 | |||
d405bf63a3 | |||
737f5bf5cc | |||
149cdf67bb | |||
c35ff8d711 | |||
f2bd9b65aa | |||
018a25ba6a | |||
3c052df1e7 | |||
17c85eb8b9 | |||
2bcb31e4d6 | |||
70aef3fe7e | |||
734bde4a98 | |||
c7d9a42feb | |||
f20bc72abb | |||
cd2cfce683 | |||
44ab180474 | |||
15557dfdd6 | |||
488f616d34 | |||
e920406ce9 | |||
e044fd81bd | |||
edaccc357d | |||
67f645ad50 | |||
bfeced5f34 | |||
24b9794a18 | |||
a781329a47 | |||
6b5e0a1207 | |||
2455adfbca | |||
a2cf86b62f | |||
7277906851 | |||
9da9ebb01e | |||
f70684b773 | |||
8b19b206a4 | |||
6be2866ddd | |||
ab55d3c91a | |||
c7ee7eb774 | |||
02daa13a2f | |||
28944b1100 | |||
7ec04d6d3d | |||
595d4d8894 | |||
04ed28f7d1 | |||
6c95cec709 | |||
59173b3ca8 | |||
c2036bba90 | |||
83afea95e6 | |||
ac515f5e80 | |||
6abbf58b83 | |||
9c25ecdc02 | |||
81a15da2d0 | |||
86929251ba | |||
1d8fb2b296 | |||
9d5f0d7a5d | |||
82b1d68576 | |||
e04b23aceb | |||
8e255938b5 | |||
f2eb9666a7 | |||
cbdb0c8b08 | |||
f821f4d9cc |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @gitzone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,5 +1,20 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
.nogit/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
150
.gitlab-ci.yml
150
.gitlab-ci.yml
@ -1,150 +0,0 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- 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
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
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
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--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:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
12
.snyk
12
.snyk
@ -1,12 +0,0 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.12.0
|
||||
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
|
||||
ignore:
|
||||
'npm:node-forge:20180226':
|
||||
- rsa-compat > node-forge:
|
||||
reason: None given
|
||||
expires: '2018-09-11T19:17:24.148Z'
|
||||
- acme-v2 > rsa-compat > node-forge:
|
||||
reason: None given
|
||||
expires: '2018-09-11T19:17:24.148Z'
|
||||
patch: {}
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
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", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
63
README.md
63
README.md
@ -1,63 +0,0 @@
|
||||
# smartacme
|
||||
|
||||
acme implementation in TypeScript
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/smartacme)
|
||||
[](https://GitLab.com/umbrellazone/smartacme)
|
||||
[](https://github.com/umbrellazone/smartacme)
|
||||
[](https://umbrellazone.gitlab.io/smartacme/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
||||
[](https://www.npmjs.com/package/smartacme)
|
||||
[](https://david-dm.org/umbrellazone/smartacme)
|
||||
[](https://www.bithound.io/github/umbrellazone/smartacme/master/dependencies/npm)
|
||||
[](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/)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```javascript
|
||||
import { SmartAcme } from 'smartacme';
|
||||
|
||||
let smac = new SmartAcme()(async () => {
|
||||
// learn async/await, it'll make your life easier
|
||||
|
||||
// optionally accepts a filePath Arg with a stored acmeaccount.json
|
||||
// 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
|
||||
|
||||
| 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)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://umbrella.zone
|
@ -1,4 +1,16 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartacme",
|
||||
"description": "acme with an easy yet powerful interface in TypeScript",
|
||||
"npmPackagename": "@push.rocks/smartacme",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
|
2579
package-lock.json
generated
2579
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
72
package.json
72
package.json
@ -1,13 +1,15 @@
|
||||
{
|
||||
"name": "@pushrocks/smartacme",
|
||||
"version": "2.0.32",
|
||||
"name": "@push.rocks/smartacme",
|
||||
"version": "4.0.6",
|
||||
"private": false,
|
||||
"description": "acme implementation in TypeScript",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"description": "acme with an easy yet powerful interface in TypeScript",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -25,28 +27,42 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^3.0.4",
|
||||
"@pushrocks/smartdata": "^3.1.13",
|
||||
"@pushrocks/smartdelay": "^2.0.2",
|
||||
"@pushrocks/smartdns": "^3.0.8",
|
||||
"@pushrocks/smartexpress": "^3.0.6",
|
||||
"@pushrocks/smartlog": "^2.0.11",
|
||||
"@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"
|
||||
"@apiglobal/typedserver": "^2.0.65",
|
||||
"@push.rocks/lik": "^6.0.3",
|
||||
"@push.rocks/smartdata": "^5.0.8",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartdns": "^5.0.2",
|
||||
"@push.rocks/smartlog": "^3.0.3",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/smartrequest": "^2.0.18",
|
||||
"@push.rocks/smartstring": "^4.0.5",
|
||||
"@push.rocks/smarttime": "^4.0.4",
|
||||
"@push.rocks/smartunique": "^3.0.3",
|
||||
"@tsclass/tsclass": "^4.0.42",
|
||||
"acme-client": "^4.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.4",
|
||||
"@gitzone/tsrun": "^1.1.17",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@mojoio/cloudflare": "^2.0.0",
|
||||
"@pushrocks/qenv": "^4.0.0",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.12.18",
|
||||
"tslint": "^5.12.1",
|
||||
"tslint-config-prettier": "^1.17.0"
|
||||
}
|
||||
"@apiclient.xyz/cloudflare": "^6.0.3",
|
||||
"@gitzone/tsbuild": "^2.1.66",
|
||||
"@gitzone/tsrun": "^1.2.44",
|
||||
"@gitzone/tstest": "^1.0.77",
|
||||
"@push.rocks/qenv": "^5.0.2",
|
||||
"@push.rocks/tapbundle": "^5.0.12",
|
||||
"@types/node": "^20.4.2"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
5981
pnpm-lock.yaml
generated
Normal file
5981
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
3
qenv.yml
3
qenv.yml
@ -1,6 +1,5 @@
|
||||
required:
|
||||
- CF_EMAIL
|
||||
- CF_KEY
|
||||
- CF_TOKEN
|
||||
- MONGODB_URL
|
||||
- MONGODB_PASSWORD
|
||||
- MONGODB_DATABASE
|
||||
|
64
readme.md
Normal file
64
readme.md
Normal file
@ -0,0 +1,64 @@
|
||||
# @push.rocks/smartacme
|
||||
acme with an easy yet powerful interface in TypeScript
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartacme)
|
||||
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartacme)
|
||||
* [github.com (source mirror)](https://github.com/push.rocks/smartacme)
|
||||
* [docs (typedoc)](https://push.rocks.gitlab.io/smartacme/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```javascript
|
||||
import { SmartAcme } from 'smartacme';
|
||||
|
||||
const run = async () => {
|
||||
smartAcmeInstance = new smartacme.SmartAcme({
|
||||
accountEmail: 'domains@lossless.org',
|
||||
accountPrivateKey: null,
|
||||
mongoDescriptor: {
|
||||
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
|
||||
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
||||
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL'),
|
||||
},
|
||||
removeChallenge: async (dnsChallenge) => {
|
||||
// somehow provide a function that is able to remove the dns challenge
|
||||
},
|
||||
setChallenge: async (dnsChallenge) => {
|
||||
// somehow provide a function that is able to the dns challenge
|
||||
},
|
||||
environment: 'integration',
|
||||
});
|
||||
await smartAcmeInstance.init();
|
||||
|
||||
// myCert has properties for public/private keys and csr ;)
|
||||
const myCert = await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||
};
|
||||
```
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
30
test/test.ts
30
test/test.ts
@ -1,9 +1,11 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import { Qenv } from '@pushrocks/qenv';
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { Qenv } from '@push.rocks/qenv';
|
||||
import * as cloudflare from '@apiclient.xyz/cloudflare';
|
||||
|
||||
const testQenv = new Qenv('./', './.nogit/');
|
||||
const testCloudflare = new cloudflare.CloudflareAccount(testQenv.getEnvVarOnDemand('CF_TOKEN'));
|
||||
|
||||
import * as smartacme from '../ts/index';
|
||||
import * as smartacme from '../ts/index.js';
|
||||
|
||||
let smartAcmeInstance: smartacme.SmartAcme;
|
||||
|
||||
@ -14,25 +16,29 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
||||
mongoDescriptor: {
|
||||
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
|
||||
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
||||
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL')
|
||||
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL'),
|
||||
},
|
||||
removeChallenge: async (...args) => {
|
||||
console.log(args);
|
||||
removeChallenge: async (dnsChallenge) => {
|
||||
testCloudflare.convenience.acmeRemoveDnsChallenge(dnsChallenge);
|
||||
},
|
||||
setChallenge: async (...args) => {
|
||||
console.log(args);
|
||||
setChallenge: async (dnsChallenge) => {
|
||||
testCloudflare.convenience.acmeSetDnsChallenge(dnsChallenge);
|
||||
},
|
||||
environment: "integration"
|
||||
environment: 'integration',
|
||||
});
|
||||
await smartAcmeInstance.init();
|
||||
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||
});
|
||||
|
||||
tap.test('should get a domain certificate', async () => {
|
||||
const certificate = await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||
console.log(certificate);
|
||||
});
|
||||
|
||||
tap.test('certmatcher should correctly match domains', async () => {
|
||||
const certMatcherMod = await import('../ts/smartacme.classes.certmatcher');
|
||||
const certMatcherMod = await import('../ts/smartacme.classes.certmatcher.js');
|
||||
const certMatcher = new certMatcherMod.CertMatcher();
|
||||
const matchedCert = certMatcher.getCertificateDomainNameByDomainName('level3.level2.level1');
|
||||
expect(matchedCert).to.equal('level2.level1');
|
||||
expect(matchedCert).toEqual('level2.level1');
|
||||
});
|
||||
|
||||
tap.test('should stop correctly', async () => {
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartacme',
|
||||
version: '4.0.6',
|
||||
description: 'acme with an easy yet powerful interface in TypeScript'
|
||||
}
|
@ -1,3 +1 @@
|
||||
export * from './smartacme.classes.smartacme';
|
||||
|
||||
export * from './smartacme.classes.certremoteclient';
|
||||
export * from './smartacme.classes.smartacme.js';
|
||||
|
@ -1,10 +0,0 @@
|
||||
export type TCertStatus = 'existing' | 'nonexisting' | 'pending' | 'failed';
|
||||
|
||||
export interface ICert {
|
||||
id: string;
|
||||
domainName: string;
|
||||
created: number;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
csr: string;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
import { ICert, TCertStatus } from './cert';
|
||||
|
||||
export interface ICertRemoteRequest {
|
||||
secret: string;
|
||||
domainName: string;
|
||||
}
|
||||
|
||||
export interface ICertRemoteResponse {
|
||||
status: TCertStatus;
|
||||
certificate?: ICert;
|
||||
}
|
@ -1,3 +1 @@
|
||||
export * from './accountdata';
|
||||
export * from './cert';
|
||||
export * from './certremote';
|
||||
export * from './accountdata.js';
|
||||
|
@ -1,16 +1,18 @@
|
||||
import * as plugins from './smartacme.plugins';
|
||||
import * as plugins from './smartacme.plugins.js';
|
||||
|
||||
import * as interfaces from './interfaces';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
import { CertManager } from './smartacme.classes.certmanager';
|
||||
import { CertManager } from './smartacme.classes.certmanager.js';
|
||||
|
||||
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
||||
import { ICert } from './interfaces';
|
||||
import { Collection, svDb, unI } from '@push.rocks/smartdata';
|
||||
|
||||
@plugins.smartdata.Collection(() => {
|
||||
return CertManager.activeDB;
|
||||
})
|
||||
export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements interfaces.ICert {
|
||||
export class Cert
|
||||
extends plugins.smartdata.SmartDataDbDoc<Cert, plugins.tsclass.network.ICert>
|
||||
implements plugins.tsclass.network.ICert
|
||||
{
|
||||
@unI()
|
||||
public id: string;
|
||||
|
||||
@ -29,10 +31,32 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements inte
|
||||
@svDb()
|
||||
public csr: string;
|
||||
|
||||
constructor(optionsArg: ICert) {
|
||||
@svDb()
|
||||
public validUntil: number;
|
||||
|
||||
public isStillValid(): boolean {
|
||||
return this.validUntil >= Date.now();
|
||||
}
|
||||
|
||||
public shouldBeRenewed(): boolean {
|
||||
const shouldBeValidAtLeastUntil =
|
||||
Date.now() +
|
||||
plugins.smarttime.getMilliSecondsFromUnits({
|
||||
days: 10,
|
||||
});
|
||||
return !(this.validUntil >= shouldBeValidAtLeastUntil);
|
||||
}
|
||||
|
||||
public update(certDataArg: plugins.tsclass.network.ICert) {
|
||||
Object.keys(certDataArg).forEach((key) => {
|
||||
this[key] = certDataArg[key];
|
||||
});
|
||||
}
|
||||
|
||||
constructor(optionsArg: plugins.tsclass.network.ICert) {
|
||||
super();
|
||||
if (optionsArg) {
|
||||
Object.keys(optionsArg).forEach(key => {
|
||||
Object.keys(optionsArg).forEach((key) => {
|
||||
this[key] = optionsArg[key];
|
||||
});
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
import * as plugins from './smartacme.plugins';
|
||||
import { Cert } from './smartacme.classes.cert';
|
||||
import { SmartAcme } from './smartacme.classes.smartacme';
|
||||
|
||||
import * as interfaces from './interfaces';
|
||||
import * as plugins from './smartacme.plugins.js';
|
||||
import { Cert } from './smartacme.classes.cert.js';
|
||||
import { SmartAcme } from './smartacme.classes.smartacme.js';
|
||||
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
export class CertManager {
|
||||
// =========
|
||||
@ -11,18 +10,20 @@ export class CertManager {
|
||||
// =========
|
||||
public static activeDB: plugins.smartdata.SmartdataDb;
|
||||
|
||||
|
||||
// =========
|
||||
// INSTANCE
|
||||
// =========
|
||||
private mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||
public smartdataDb: plugins.smartdata.SmartdataDb;
|
||||
|
||||
public pendingMap: plugins.lik.Stringmap;
|
||||
public interestMap: plugins.lik.InterestMap<string, Cert>;
|
||||
|
||||
constructor(smartAcmeArg: SmartAcme,optionsArg: {
|
||||
constructor(
|
||||
smartAcmeArg: SmartAcme,
|
||||
optionsArg: {
|
||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||
}) {
|
||||
}
|
||||
) {
|
||||
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
||||
}
|
||||
|
||||
@ -33,18 +34,17 @@ export class CertManager {
|
||||
CertManager.activeDB = this.smartdataDb;
|
||||
|
||||
// Pending Map
|
||||
this.pendingMap = new plugins.lik.Stringmap();
|
||||
this.interestMap = new plugins.lik.InterestMap((certName) => certName);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieves a certificate
|
||||
* @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> {
|
||||
await this.checkCerts();
|
||||
const existingCertificate: Cert = await Cert.getInstance({
|
||||
domainName
|
||||
public async retrieveCertificate(certDomainNameArg: string): Promise<Cert> {
|
||||
const existingCertificate: Cert = await Cert.getInstance<Cert>({
|
||||
domainName: certDomainNameArg,
|
||||
});
|
||||
|
||||
if (existingCertificate) {
|
||||
@ -52,53 +52,26 @@ export class CertManager {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* stores the certificate
|
||||
* @param optionsArg
|
||||
*/
|
||||
public async storeCertificate(optionsArg: interfaces.ICert) {
|
||||
public async storeCertificate(optionsArg: plugins.tsclass.network.ICert) {
|
||||
const cert = new Cert(optionsArg);
|
||||
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<Cert>({
|
||||
domainName: certDomainNameArg,
|
||||
});
|
||||
await cert.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = await this.retrieveCertificate(certDomainArg);
|
||||
if (existingCertificate) {
|
||||
return 'existing';
|
||||
}
|
||||
|
||||
return 'nonexisting';
|
||||
}
|
||||
|
||||
/**
|
||||
* checks all certs for expiration
|
||||
*/
|
||||
private async checkCerts() {
|
||||
// TODO
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,15 @@
|
||||
import * as plugins from './smartacme.plugins';
|
||||
import * as plugins from './smartacme.plugins.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
@ -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;
|
||||
console.log(responseBody);
|
||||
switch (responseBody.status as interfaces.TCertStatus) {
|
||||
case '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;
|
||||
}
|
||||
}
|
@ -1,10 +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';
|
||||
import * as plugins from './smartacme.plugins.js';
|
||||
import { Cert } from './smartacme.classes.cert.js';
|
||||
import { CertManager } from './smartacme.classes.certmanager.js';
|
||||
import { CertMatcher } from './smartacme.classes.certmatcher.js';
|
||||
|
||||
/**
|
||||
* the options for the class @see SmartAcme
|
||||
@ -13,10 +10,9 @@ export interface ISmartAcmeOptions {
|
||||
accountPrivateKey?: string;
|
||||
accountEmail: string;
|
||||
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||
setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
||||
removeChallenge: (domainName: string) => Promise<any>;
|
||||
setChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||
removeChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||
environment: 'production' | 'integration';
|
||||
logger?: plugins.smartlog.Smartlog;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,63 +30,23 @@ export class SmartAcme {
|
||||
|
||||
// the acme client
|
||||
private client: any;
|
||||
private smartdns = new plugins.smartdns.Smartdns();
|
||||
public logger: plugins.smartlog.Smartlog;
|
||||
private smartdns = new plugins.smartdns.Smartdns({});
|
||||
public logger: plugins.smartlog.ConsoleLog;
|
||||
|
||||
// the account private key
|
||||
private privateKey: string;
|
||||
|
||||
// challenge fullfillment
|
||||
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
||||
private removeChallenge: (domainName: string) => Promise<any>;
|
||||
private setChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||
private removeChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||
|
||||
// certmanager
|
||||
private certmanager: CertManager;
|
||||
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;
|
||||
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(
|
||||
requestBody.domainName
|
||||
);
|
||||
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) {
|
||||
this.options = optionsArg;
|
||||
this.options.logger
|
||||
? (this.logger = optionsArg.logger)
|
||||
: (this.logger = plugins.smartlog.defaultLogger);
|
||||
this.logger = new plugins.smartlog.ConsoleLog();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,13 +57,13 @@ export class SmartAcme {
|
||||
*/
|
||||
public async init() {
|
||||
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.removeChallenge = this.options.removeChallenge;
|
||||
|
||||
// CertMangaer
|
||||
this.certmanager = new CertManager(this, {
|
||||
mongoDescriptor: this.options.mongoDescriptor
|
||||
mongoDescriptor: this.options.mongoDescriptor,
|
||||
});
|
||||
await this.certmanager.init();
|
||||
|
||||
@ -123,13 +79,13 @@ export class SmartAcme {
|
||||
return plugins.acme.directory.letsencrypt.staging;
|
||||
}
|
||||
})(),
|
||||
accountKey: this.privateKey
|
||||
accountKey: this.privateKey,
|
||||
});
|
||||
|
||||
/* Register account */
|
||||
await this.client.createAccount({
|
||||
termsOfServiceAgreed: true,
|
||||
contact: [`mailto:${this.options.accountEmail}`]
|
||||
contact: [`mailto:${this.options.accountEmail}`],
|
||||
});
|
||||
}
|
||||
|
||||
@ -137,18 +93,46 @@ export class SmartAcme {
|
||||
await this.certmanager.smartdataDb.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a certificate
|
||||
* it runs through the following steps
|
||||
*
|
||||
* * look in the database
|
||||
* * if in the database and still valid return it
|
||||
* * if 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> {
|
||||
const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
||||
await this.certmanager.announceCertificate(certDomain);
|
||||
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomain);
|
||||
const certDomainName = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
||||
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;
|
||||
} else if (retrievedCertificate && retrievedCertificate.shouldBeRenewed()) {
|
||||
await retrievedCertificate.delete();
|
||||
}
|
||||
|
||||
// lets make sure others get the same interest
|
||||
const currentDomainInterst = await this.certmanager.interestMap.addInterest(certDomainName);
|
||||
|
||||
/* Place new order */
|
||||
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 */
|
||||
@ -156,8 +140,8 @@ export class SmartAcme {
|
||||
|
||||
for (const authz of authorizations) {
|
||||
console.log(authz);
|
||||
const domainDnsName: string = `_acme-challenge.${authz.identifier.value}`;
|
||||
const dnsChallenge: string = authz.challenges.find(challengeArg => {
|
||||
const fullHostName: string = `_acme-challenge.${authz.identifier.value}`;
|
||||
const dnsChallenge: string = authz.challenges.find((challengeArg) => {
|
||||
return challengeArg.type === 'dns-01';
|
||||
});
|
||||
// process.exit(1);
|
||||
@ -165,8 +149,12 @@ export class SmartAcme {
|
||||
|
||||
try {
|
||||
/* Satisfy challenge */
|
||||
await this.setChallenge(domainDnsName, keyAuthorization);
|
||||
await this.smartdns.checkUntilAvailable(domainDnsName, 'TXT', keyAuthorization, 100, 5000);
|
||||
await this.setChallenge({
|
||||
hostName: fullHostName,
|
||||
challenge: keyAuthorization,
|
||||
});
|
||||
await plugins.smartdelay.delayFor(30000);
|
||||
await this.smartdns.checkUntilAvailable(fullHostName, 'TXT', keyAuthorization, 100, 5000);
|
||||
console.log('Cool down an extra 60 second for region availability');
|
||||
await plugins.smartdelay.delayFor(60000);
|
||||
|
||||
@ -181,7 +169,10 @@ export class SmartAcme {
|
||||
} finally {
|
||||
/* Clean up challenge response */
|
||||
try {
|
||||
await this.removeChallenge(domainDnsName);
|
||||
await this.removeChallenge({
|
||||
hostName: fullHostName,
|
||||
challenge: keyAuthorization,
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
@ -190,8 +181,8 @@ export class SmartAcme {
|
||||
|
||||
/* Finalize order */
|
||||
const [key, csr] = await plugins.acme.forge.createCsr({
|
||||
commonName: `*.${certDomain}`,
|
||||
altNames: [certDomain]
|
||||
commonName: `*.${certDomainName}`,
|
||||
altNames: [certDomainName],
|
||||
});
|
||||
|
||||
await this.client.finalizeOrder(order, csr);
|
||||
@ -201,14 +192,21 @@ export class SmartAcme {
|
||||
|
||||
await this.certmanager.storeCertificate({
|
||||
id: plugins.smartunique.shortId(),
|
||||
domainName: certDomain,
|
||||
domainName: certDomainName,
|
||||
privateKey: key.toString(),
|
||||
publicKey: cert.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);
|
||||
currentDomainInterst.fullfillInterest(newCertificate);
|
||||
currentDomainInterst.destroy();
|
||||
return newCertificate;
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,39 @@
|
||||
// @apiglobal scope
|
||||
import * as typedserver from '@apiglobal/typedserver';
|
||||
|
||||
export { typedserver };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
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';
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartdata from '@push.rocks/smartdata';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartdns from '@push.rocks/smartdns';
|
||||
import * as smartlog from '@push.rocks/smartlog';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartunique from '@push.rocks/smartunique';
|
||||
import * as smartstring from '@push.rocks/smartstring';
|
||||
import * as smarttime from '@push.rocks/smarttime';
|
||||
|
||||
export { lik, smartdata, smartdelay, smartdns, smartexpress, smartlog, smartpromise, smartrequest, smartunique, smartstring, smarttime };
|
||||
export {
|
||||
lik,
|
||||
smartdata,
|
||||
smartdelay,
|
||||
smartdns,
|
||||
smartlog,
|
||||
smartpromise,
|
||||
smartrequest,
|
||||
smartunique,
|
||||
smartstring,
|
||||
smarttime,
|
||||
};
|
||||
|
||||
// thirs party scope
|
||||
// @tsclass scope
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
export { tsclass };
|
||||
|
||||
// third party scope
|
||||
import * as acme from 'acme-client';
|
||||
|
||||
export { acme };
|
||||
|
@ -1,7 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"target": "es2017",
|
||||
"module": "commonjs"
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
}
|
||||
}
|
||||
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user