Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
bfeced5f34 | |||
24b9794a18 | |||
a781329a47 | |||
6b5e0a1207 | |||
2455adfbca | |||
a2cf86b62f | |||
7277906851 | |||
9da9ebb01e | |||
f70684b773 | |||
8b19b206a4 | |||
6be2866ddd | |||
ab55d3c91a | |||
c7ee7eb774 | |||
02daa13a2f | |||
28944b1100 | |||
7ec04d6d3d | |||
595d4d8894 | |||
04ed28f7d1 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@ -19,22 +19,35 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -49,9 +62,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@ -62,9 +73,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -84,6 +93,8 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
36
README.md
36
README.md
@ -1,36 +0,0 @@
|
|||||||
# @pushrocks/smartuniverse
|
|
||||||
acme with an easy yet powerful interface in TypeScript
|
|
||||||
|
|
||||||
## Availabililty and Links
|
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartuniverse)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartuniverse)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { SmartAcme } from 'smartacme';
|
|
||||||
|
|
||||||
let smac = new SmartAcme()
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
```
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
@ -4,9 +4,9 @@
|
|||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartuniverse",
|
"gitrepo": "smartacme",
|
||||||
"shortDescription": "acme with an easy yet powerful interface in TypeScript",
|
"shortDescription": "acme with an easy yet powerful interface in TypeScript",
|
||||||
"npmPackagename": "@pushrocks/smartuniverse",
|
"npmPackagename": "@pushrocks/smartacme",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks"
|
||||||
}
|
}
|
||||||
|
10023
package-lock.json
generated
10023
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
52
package.json
52
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "3.0.0",
|
"version": "3.0.9",
|
||||||
"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_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,40 +25,44 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.17",
|
"@pushrocks/lik": "^4.0.17",
|
||||||
"@pushrocks/smartdata": "^3.1.25",
|
"@pushrocks/smartdata": "^3.1.54",
|
||||||
"@pushrocks/smartdelay": "^2.0.6",
|
"@pushrocks/smartdelay": "^2.0.10",
|
||||||
"@pushrocks/smartdns": "^3.0.8",
|
"@pushrocks/smartdns": "^4.0.4",
|
||||||
"@pushrocks/smartexpress": "^3.0.57",
|
"@pushrocks/smartexpress": "^3.0.97",
|
||||||
"@pushrocks/smartlog": "^2.0.21",
|
"@pushrocks/smartlog": "^2.0.39",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@pushrocks/smartrequest": "^1.1.47",
|
"@pushrocks/smartrequest": "^1.1.51",
|
||||||
"@pushrocks/smartstring": "^3.0.18",
|
"@pushrocks/smartstring": "^3.0.18",
|
||||||
"@pushrocks/smarttime": "^3.0.12",
|
"@pushrocks/smarttime": "^3.0.37",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@pushrocks/smartunique": "^3.0.3",
|
||||||
"@tsclass/tsclass": "^3.0.4",
|
"@tsclass/tsclass": "^3.0.29",
|
||||||
"acme-client": "^3.3.1"
|
"acme-client": "^3.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@mojoio/cloudflare": "^4.0.3",
|
"@mojoio/cloudflare": "^5.0.6",
|
||||||
"@pushrocks/qenv": "^4.0.6",
|
"@pushrocks/qenv": "^4.0.10",
|
||||||
"@pushrocks/tapbundle": "^3.2.0",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^13.7.0",
|
"@types/node": "^14.14.7",
|
||||||
"tslint": "^6.0.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
"ts_web/**/*",
|
"ts_web/**/*",
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
"dist_web/**/*",
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
3
qenv.yml
3
qenv.yml
@ -1,6 +1,5 @@
|
|||||||
required:
|
required:
|
||||||
- CF_EMAIL
|
- CF_TOKEN
|
||||||
- CF_KEY
|
|
||||||
- MONGODB_URL
|
- MONGODB_URL
|
||||||
- MONGODB_PASSWORD
|
- MONGODB_PASSWORD
|
||||||
- MONGODB_DATABASE
|
- MONGODB_DATABASE
|
||||||
|
66
readme.md
Normal file
66
readme.md
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# @pushrocks/smartacme
|
||||||
|
acme with an easy yet powerful interface in TypeScript
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartacme)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartacme)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartacme)
|
||||||
|
* [docs (typedoc)](https://pushrocks.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)
|
||||||
|
Platform support | [](https://lossless.cloud) [](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.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
@ -3,10 +3,7 @@ import { Qenv } from '@pushrocks/qenv';
|
|||||||
import * as cloudflare from '@mojoio/cloudflare';
|
import * as cloudflare from '@mojoio/cloudflare';
|
||||||
|
|
||||||
const testQenv = new Qenv('./', './.nogit/');
|
const testQenv = new Qenv('./', './.nogit/');
|
||||||
const testCloudflare = new cloudflare.CloudflareAccount({
|
const testCloudflare = new cloudflare.CloudflareAccount(testQenv.getEnvVarOnDemand('CF_TOKEN'));
|
||||||
email: testQenv.getEnvVarOnDemand('CF_EMAIL'),
|
|
||||||
key: testQenv.getEnvVarOnDemand('CF_KEY')
|
|
||||||
});
|
|
||||||
|
|
||||||
import * as smartacme from '../ts/index';
|
import * as smartacme from '../ts/index';
|
||||||
|
|
||||||
@ -19,7 +16,7 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
|||||||
mongoDescriptor: {
|
mongoDescriptor: {
|
||||||
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
|
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
|
||||||
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
|
||||||
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL')
|
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL'),
|
||||||
},
|
},
|
||||||
removeChallenge: async (dnsChallenge) => {
|
removeChallenge: async (dnsChallenge) => {
|
||||||
testCloudflare.convenience.acmeRemoveDnsChallenge(dnsChallenge);
|
testCloudflare.convenience.acmeRemoveDnsChallenge(dnsChallenge);
|
||||||
@ -27,7 +24,7 @@ tap.test('should create a valid instance of SmartAcme', async () => {
|
|||||||
setChallenge: async (dnsChallenge) => {
|
setChallenge: async (dnsChallenge) => {
|
||||||
testCloudflare.convenience.acmeSetDnsChallenge(dnsChallenge);
|
testCloudflare.convenience.acmeSetDnsChallenge(dnsChallenge);
|
||||||
},
|
},
|
||||||
environment: 'integration'
|
environment: 'integration',
|
||||||
});
|
});
|
||||||
await smartAcmeInstance.init();
|
await smartAcmeInstance.init();
|
||||||
});
|
});
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
export type TCertStatus = 'existing' | 'nonexisting' | 'pending' | 'failed';
|
|
||||||
|
|
||||||
export interface IOldCert {
|
|
||||||
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 './accountdata';
|
||||||
export * from './cert';
|
|
||||||
export * from './certremote';
|
|
||||||
|
@ -9,7 +9,8 @@ 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 plugins.tsclass.network.ICert {
|
export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert, plugins.tsclass.network.ICert>
|
||||||
|
implements plugins.tsclass.network.ICert {
|
||||||
@unI()
|
@unI()
|
||||||
public id: string;
|
public id: string;
|
||||||
|
|
||||||
@ -39,22 +40,21 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements plug
|
|||||||
const shouldBeValidAtLeastUntil =
|
const shouldBeValidAtLeastUntil =
|
||||||
Date.now() +
|
Date.now() +
|
||||||
plugins.smarttime.getMilliSecondsFromUnits({
|
plugins.smarttime.getMilliSecondsFromUnits({
|
||||||
days: 10
|
days: 10,
|
||||||
});
|
});
|
||||||
return this.validUntil >= shouldBeValidAtLeastUntil;
|
return !(this.validUntil >= shouldBeValidAtLeastUntil);
|
||||||
}
|
}
|
||||||
|
|
||||||
public update(certDataArg: plugins.tsclass.network.ICert) {
|
public update(certDataArg: plugins.tsclass.network.ICert) {
|
||||||
Object.keys(certDataArg).forEach(key => {
|
Object.keys(certDataArg).forEach((key) => {
|
||||||
this[key] = certDataArg[key];
|
this[key] = certDataArg[key];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor(optionsArg: plugins.tsclass.network.ICert) {
|
constructor(optionsArg: plugins.tsclass.network.ICert) {
|
||||||
super();
|
super();
|
||||||
if (optionsArg) {
|
if (optionsArg) {
|
||||||
Object.keys(optionsArg).forEach(key => {
|
Object.keys(optionsArg).forEach((key) => {
|
||||||
this[key] = optionsArg[key];
|
this[key] = optionsArg[key];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ export class CertManager {
|
|||||||
* @param certDomainNameArg the domain Name to retrieve the vcertificate for
|
* @param certDomainNameArg the domain Name to retrieve the vcertificate for
|
||||||
*/
|
*/
|
||||||
public async retrieveCertificate(certDomainNameArg: string): Promise<Cert> {
|
public async retrieveCertificate(certDomainNameArg: string): Promise<Cert> {
|
||||||
const existingCertificate: Cert = await Cert.getInstance({
|
const existingCertificate: Cert = await Cert.getInstance<Cert>({
|
||||||
domainName: certDomainNameArg
|
domainName: certDomainNameArg,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingCertificate) {
|
if (existingCertificate) {
|
||||||
@ -69,8 +69,8 @@ export class CertManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async deleteCertificate(certDomainNameArg: string) {
|
public async deleteCertificate(certDomainNameArg: string) {
|
||||||
const cert: Cert = await Cert.getInstance({
|
const cert: Cert = await Cert.getInstance<Cert>({
|
||||||
domainName: certDomainNameArg
|
domainName: certDomainNameArg,
|
||||||
});
|
});
|
||||||
await cert.delete();
|
await cert.delete();
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,6 @@ 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 { CertMatcher } from './smartacme.classes.certmatcher';
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
|
||||||
import { request } from 'http';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the options for the class @see SmartAcme
|
* the options for the class @see SmartAcme
|
||||||
*/
|
*/
|
||||||
@ -16,7 +13,6 @@ export interface ISmartAcmeOptions {
|
|||||||
setChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
setChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||||
removeChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
removeChallenge: (dnsChallengeArg: plugins.tsclass.network.IDnsChallenge) => Promise<any>;
|
||||||
environment: 'production' | 'integration';
|
environment: 'production' | 'integration';
|
||||||
logger?: plugins.smartlog.Smartlog;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,8 +30,8 @@ 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;
|
public logger: plugins.smartlog.ConsoleLog;
|
||||||
|
|
||||||
// the account private key
|
// the account private key
|
||||||
private privateKey: string;
|
private privateKey: string;
|
||||||
@ -50,9 +46,7 @@ export class SmartAcme {
|
|||||||
|
|
||||||
constructor(optionsArg: ISmartAcmeOptions) {
|
constructor(optionsArg: ISmartAcmeOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
this.options.logger
|
this.logger = new plugins.smartlog.ConsoleLog();
|
||||||
? (this.logger = optionsArg.logger)
|
|
||||||
: (this.logger = plugins.smartlog.defaultLogger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +63,7 @@ export class SmartAcme {
|
|||||||
|
|
||||||
// CertMangaer
|
// CertMangaer
|
||||||
this.certmanager = new CertManager(this, {
|
this.certmanager = new CertManager(this, {
|
||||||
mongoDescriptor: this.options.mongoDescriptor
|
mongoDescriptor: this.options.mongoDescriptor,
|
||||||
});
|
});
|
||||||
await this.certmanager.init();
|
await this.certmanager.init();
|
||||||
|
|
||||||
@ -85,13 +79,13 @@ export class SmartAcme {
|
|||||||
return plugins.acme.directory.letsencrypt.staging;
|
return plugins.acme.directory.letsencrypt.staging;
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
accountKey: this.privateKey
|
accountKey: this.privateKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Register account */
|
/* Register account */
|
||||||
await this.client.createAccount({
|
await this.client.createAccount({
|
||||||
termsOfServiceAgreed: true,
|
termsOfServiceAgreed: true,
|
||||||
contact: [`mailto:${this.options.accountEmail}`]
|
contact: [`mailto:${this.options.accountEmail}`],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,26 +111,28 @@ export class SmartAcme {
|
|||||||
const certDomainName = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
const certDomainName = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
||||||
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomainName);
|
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomainName);
|
||||||
|
|
||||||
if (!retrievedCertificate && await this.certmanager.interestMap.checkInterest(certDomainName)) {
|
if (
|
||||||
|
!retrievedCertificate &&
|
||||||
|
(await this.certmanager.interestMap.checkInterest(certDomainName))
|
||||||
|
) {
|
||||||
const existingCertificateInterest = this.certmanager.interestMap.findInterest(certDomainName);
|
const existingCertificateInterest = this.certmanager.interestMap.findInterest(certDomainName);
|
||||||
const certificate = existingCertificateInterest.interestFullfilled;
|
const certificate = existingCertificateInterest.interestFullfilled;
|
||||||
return certificate;
|
return certificate;
|
||||||
} else if (retrievedCertificate && !retrievedCertificate.shouldBeRenewed()) {
|
} else if (retrievedCertificate && !retrievedCertificate.shouldBeRenewed()) {
|
||||||
return retrievedCertificate;
|
return retrievedCertificate;
|
||||||
} else if (retrievedCertificate && retrievedCertificate.shouldBeRenewed) {
|
} else if (retrievedCertificate && retrievedCertificate.shouldBeRenewed()) {
|
||||||
await retrievedCertificate.delete();
|
await retrievedCertificate.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// lets make sure others get the same interest
|
// lets make sure others get the same interest
|
||||||
await this.certmanager.interestMap.addInterest(certDomainName);
|
const currentDomainInterst = 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: [
|
identifiers: [
|
||||||
{ type: 'dns', value: certDomainName },
|
{ type: 'dns', value: certDomainName },
|
||||||
{ type: 'dns', value: `*.${certDomainName}` }
|
{ type: 'dns', value: `*.${certDomainName}` },
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Get authorizations and select challenges */
|
/* Get authorizations and select challenges */
|
||||||
@ -145,7 +141,7 @@ export class SmartAcme {
|
|||||||
for (const authz of authorizations) {
|
for (const authz of authorizations) {
|
||||||
console.log(authz);
|
console.log(authz);
|
||||||
const fullHostName: 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';
|
||||||
});
|
});
|
||||||
// process.exit(1);
|
// process.exit(1);
|
||||||
@ -155,8 +151,9 @@ export class SmartAcme {
|
|||||||
/* Satisfy challenge */
|
/* Satisfy challenge */
|
||||||
await this.setChallenge({
|
await this.setChallenge({
|
||||||
hostName: fullHostName,
|
hostName: fullHostName,
|
||||||
challenge: keyAuthorization
|
challenge: keyAuthorization,
|
||||||
});
|
});
|
||||||
|
await plugins.smartdelay.delayFor(30000);
|
||||||
await this.smartdns.checkUntilAvailable(fullHostName, 'TXT', keyAuthorization, 100, 5000);
|
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);
|
||||||
@ -174,7 +171,7 @@ export class SmartAcme {
|
|||||||
try {
|
try {
|
||||||
await this.removeChallenge({
|
await this.removeChallenge({
|
||||||
hostName: fullHostName,
|
hostName: fullHostName,
|
||||||
challenge: keyAuthorization
|
challenge: keyAuthorization,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
@ -185,7 +182,7 @@ export class SmartAcme {
|
|||||||
/* Finalize order */
|
/* Finalize order */
|
||||||
const [key, csr] = await plugins.acme.forge.createCsr({
|
const [key, csr] = await plugins.acme.forge.createCsr({
|
||||||
commonName: `*.${certDomainName}`,
|
commonName: `*.${certDomainName}`,
|
||||||
altNames: [certDomainName]
|
altNames: [certDomainName],
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.client.finalizeOrder(order, csr);
|
await this.client.finalizeOrder(order, csr);
|
||||||
@ -203,11 +200,13 @@ export class SmartAcme {
|
|||||||
validUntil:
|
validUntil:
|
||||||
Date.now() +
|
Date.now() +
|
||||||
plugins.smarttime.getMilliSecondsFromUnits({
|
plugins.smarttime.getMilliSecondsFromUnits({
|
||||||
days: 90
|
days: 90,
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const newCertificate = await this.certmanager.retrieveCertificate(certDomainName);
|
const newCertificate = await this.certmanager.retrieveCertificate(certDomainName);
|
||||||
|
currentDomainInterst.fullfillInterest(newCertificate);
|
||||||
|
currentDomainInterst.destroy();
|
||||||
return newCertificate;
|
return newCertificate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,15 +22,13 @@ export {
|
|||||||
smartrequest,
|
smartrequest,
|
||||||
smartunique,
|
smartunique,
|
||||||
smartstring,
|
smartstring,
|
||||||
smarttime
|
smarttime,
|
||||||
};
|
};
|
||||||
|
|
||||||
// @tsclass scope
|
// @tsclass scope
|
||||||
import * as tsclass from '@tsclass/tsclass';
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
export {
|
export { tsclass };
|
||||||
tsclass
|
|
||||||
}
|
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import * as acme from 'acme-client';
|
import * as acme from 'acme-client';
|
||||||
|
Reference in New Issue
Block a user