Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
ed4ba0cb61 | |||
a8ab27045d | |||
975c3ed190 | |||
a99dea549b | |||
f8b78c433a | |||
6c33111074 | |||
280335f6f6 | |||
b90092c043 | |||
9e1c73febf | |||
dcf1915816 | |||
748c911168 | |||
3a48cb4ea8 | |||
a035c5c0b0 | |||
f9c521b7b3 | |||
19cfe8bdc5 | |||
601d6b30d3 | |||
57ffc82c43 | |||
312d3c01cd |
107
.gitlab-ci.yml
107
.gitlab-ci.yml
@ -3,69 +3,148 @@ image: hosttoday/ht-docker-node:npmci
|
|||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .yarn/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- trigger
|
- metadata
|
||||||
- pages
|
|
||||||
|
|
||||||
testLEGACY:
|
# ====================
|
||||||
stage: test
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci test legacy
|
- npmci git mirror
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- 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
|
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:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test lts
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci publish
|
- npmci node install stable
|
||||||
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- 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:
|
trigger:
|
||||||
stage: trigger
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: pages
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
12
.snyk
Normal file
12
.snyk
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# 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: {}
|
40
README.md
40
README.md
@ -1,13 +1,16 @@
|
|||||||
# smartacme
|
# smartacme
|
||||||
|
|
||||||
acme implementation in TypeScript
|
acme implementation in TypeScript
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/smartacme)
|
[](https://www.npmjs.com/package/smartacme)
|
||||||
[](https://GitLab.com/umbrellazone/smartacme)
|
[](https://GitLab.com/umbrellazone/smartacme)
|
||||||
[](https://github.com/umbrellazone/smartacme)
|
[](https://github.com/umbrellazone/smartacme)
|
||||||
[](https://umbrellazone.gitlab.io/smartacme/)
|
[](https://umbrellazone.gitlab.io/smartacme/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
||||||
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
[](https://GitLab.com/umbrellazone/smartacme/commits/master)
|
||||||
[](https://www.npmjs.com/package/smartacme)
|
[](https://www.npmjs.com/package/smartacme)
|
||||||
@ -19,11 +22,42 @@ acme implementation in TypeScript
|
|||||||
[](http://standardjs.com/)
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
```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)
|
> 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://umbrella.zone
|
||||||
|
@ -1,59 +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,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
"npmAccessLevel": "public"
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
1502
package-lock.json
generated
1502
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
package.json
@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "1.1.1",
|
"version": "2.0.6",
|
||||||
|
"private": false,
|
||||||
"description": "acme implementation in TypeScript",
|
"description": "acme implementation in TypeScript",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)"
|
"test": "(tstest test/)",
|
||||||
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,16 +27,17 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.2",
|
"@pushrocks/smartdelay": "^2.0.2",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"acme-v2": "^1.2.0",
|
"acme-client": "^2.2.1"
|
||||||
"rsa-compat": "^1.5.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.4",
|
||||||
"@gitzone/tsrun": "^1.1.12",
|
"@gitzone/tsrun": "^1.1.17",
|
||||||
"@gitzone/tstest": "^1.0.13",
|
"@gitzone/tstest": "^1.0.18",
|
||||||
"@types/node": "^10.5.8",
|
"@mojoio/cloudflare": "^2.0.0",
|
||||||
"cflare": "^1.0.5",
|
"@pushrocks/qenv": "^3.0.2",
|
||||||
"qenv": "^1.1.7",
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"tapbundle": "^2.0.2"
|
"@types/node": "^10.12.18",
|
||||||
|
"tslint": "^5.12.0",
|
||||||
|
"tslint-config-prettier": "^1.17.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
test/test.ts
18
test/test.ts
@ -1,4 +1,4 @@
|
|||||||
import { tap, expect } from 'tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import * as smartacme from '../ts/index';
|
import * as smartacme from '../ts/index';
|
||||||
|
|
||||||
@ -6,9 +6,17 @@ let smartAcmeInstance: smartacme.SmartAcme;
|
|||||||
|
|
||||||
tap.test('should create a valid instance of SmartAcme', async () => {
|
tap.test('should create a valid instance of SmartAcme', async () => {
|
||||||
smartAcmeInstance = new smartacme.SmartAcme();
|
smartAcmeInstance = new smartacme.SmartAcme();
|
||||||
await smartAcmeInstance.init()
|
await smartAcmeInstance.init({
|
||||||
console.log(smartAcmeInstance.directoryUrls);
|
accountEmail: 'domains@lossless.org',
|
||||||
await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
accountPrivateKey: null,
|
||||||
})
|
removeChallenge: async (...args) => {
|
||||||
|
console.log(args);
|
||||||
|
},
|
||||||
|
setChallenge: async (...args) => {
|
||||||
|
console.log(args);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
@ -1 +1 @@
|
|||||||
export * from './smartacme.classes.smartacme'
|
export * from './smartacme.classes.smartacme';
|
||||||
|
8
ts/interfaces/accountdata.ts
Normal file
8
ts/interfaces/accountdata.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export interface IAccountData {
|
||||||
|
id: number;
|
||||||
|
key: { kty: 'RSA'; n: string; e: string; kid: string };
|
||||||
|
contact: string[];
|
||||||
|
initialIp: string;
|
||||||
|
createdAt: string;
|
||||||
|
status: string;
|
||||||
|
}
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './accountdata';
|
@ -1,27 +0,0 @@
|
|||||||
import * as plugins from './smartacme.plugins';
|
|
||||||
const rsa = require('rsa-compat').RSA;
|
|
||||||
|
|
||||||
export class KeyPair {
|
|
||||||
rsaKeyPair: any
|
|
||||||
|
|
||||||
/**
|
|
||||||
* generates a fresh rsa keyPair
|
|
||||||
*/
|
|
||||||
static async generateFresh(): Promise<KeyPair> {
|
|
||||||
const done = plugins.smartpromise.defer();
|
|
||||||
var options = { bitlen: 2048, exp: 65537, public: true, pem: true, internal: true };
|
|
||||||
rsa.generateKeypair(options, function(err, keypair) {
|
|
||||||
if(err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
done.resolve(keypair);
|
|
||||||
});
|
|
||||||
const result: any = await done.promise;
|
|
||||||
const keyPair = new KeyPair(result);
|
|
||||||
return keyPair;
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(rsaKeyPairArg) {
|
|
||||||
this.rsaKeyPair = rsaKeyPairArg;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +1,101 @@
|
|||||||
const acme = require('acme-v2').ACME.create({
|
|
||||||
RSA: require('rsa-compat').RSA,
|
|
||||||
|
|
||||||
// other overrides
|
|
||||||
promisify: require('util').promisify,
|
|
||||||
|
|
||||||
// used for constructing user-agent
|
|
||||||
os: require('os'),
|
|
||||||
process: require('process'),
|
|
||||||
|
|
||||||
// used for overriding the default user-agent
|
|
||||||
userAgent: 'My custom UA String',
|
|
||||||
getUserAgentString: function(deps) {
|
|
||||||
return 'My custom UA String';
|
|
||||||
},
|
|
||||||
|
|
||||||
// don't try to validate challenges locally
|
|
||||||
skipChallengeTest: true
|
|
||||||
});
|
|
||||||
|
|
||||||
import { KeyPair } from './smartacme.classes.keypair';
|
|
||||||
import * as plugins from './smartacme.plugins';
|
import * as plugins from './smartacme.plugins';
|
||||||
const rsa = require('rsa-compat').RSA;
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export interface ISmartAcmeStorage {}
|
||||||
|
|
||||||
export class SmartAcme {
|
export class SmartAcme {
|
||||||
domainKeyPair: KeyPair;
|
// the acme client
|
||||||
accountKeyPair: KeyPair;
|
private client: any;
|
||||||
accountData: any;
|
|
||||||
directoryUrls: any;
|
|
||||||
|
|
||||||
async init() {
|
// the account private key
|
||||||
// get directory url
|
private privateKey: string;
|
||||||
this.directoryUrls = await acme.init('https://acme-staging-v02.api.letsencrypt.org/directory');
|
|
||||||
|
|
||||||
// create keyPairs
|
// challenge fullfillment
|
||||||
this.domainKeyPair = await KeyPair.generateFresh();
|
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
||||||
this.accountKeyPair = await KeyPair.generateFresh();
|
private removeChallenge: (domainName: string) => Promise<any>;
|
||||||
|
|
||||||
// get account
|
public async init(optionsArg: {
|
||||||
const registrationData = await acme.accounts
|
accountPrivateKey?: string;
|
||||||
.create({
|
accountEmail: string;
|
||||||
email: 'domains@lossless.org', // valid email (server checks MX records)
|
setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>
|
||||||
accountKeypair: this.accountKeyPair.rsaKeyPair,
|
removeChallenge: (domainName: string) => Promise<any>;
|
||||||
agreeToTerms: async tosUrl => {
|
}) {
|
||||||
return tosUrl;
|
this.privateKey = optionsArg.accountPrivateKey || (await plugins.acme.forge.createPrivateKey());
|
||||||
}
|
this.setChallenge = optionsArg.setChallenge;
|
||||||
})
|
this.removeChallenge = optionsArg.removeChallenge;
|
||||||
.catch(e => {
|
this.client = new plugins.acme.Client({
|
||||||
console.log(e);
|
directoryUrl: plugins.acme.directory.letsencrypt.staging,
|
||||||
|
accountKey: this.privateKey
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Register account */
|
||||||
|
await this.client.createAccount({
|
||||||
|
termsOfServiceAgreed: true,
|
||||||
|
contact: [`mailto:${optionsArg.accountEmail}`]
|
||||||
});
|
});
|
||||||
this.accountData = registrationData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCertificateForDomain(domain) {
|
public async getCertificateForDomain(domainArg: string) {
|
||||||
const result = await acme.certificates
|
const domain = domainArg;
|
||||||
.create({
|
|
||||||
domainKeypair: this.domainKeyPair.rsaKeyPair,
|
|
||||||
accountKeypair: this.accountKeyPair.rsaKeyPair,
|
|
||||||
domains: ['bleu.de'],
|
|
||||||
challengeType: 'dns-01',
|
|
||||||
|
|
||||||
setChallenge: async (hostname, key, val, cb) => {
|
/* Place new order */
|
||||||
console.log('set challenge');
|
const order = await this.client.createOrder({
|
||||||
console.log(hostname);
|
identifiers: [{ type: 'dns', value: domain }, { type: 'dns', value: `*.${domain}` }]
|
||||||
//console.log(key);
|
});
|
||||||
//console.log(val);
|
|
||||||
const dnsKey = rsa.utils.toWebsafeBase64(
|
|
||||||
require('crypto')
|
|
||||||
.createHash('sha256')
|
|
||||||
.update(val)
|
|
||||||
.digest('base64')
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(dnsKey);
|
/* Get authorizations and select challenges */
|
||||||
await plugins.smartdelay.delayFor(20000);
|
const authorizations = await this.client.getAuthorizations(order);
|
||||||
console.log('ready!');
|
|
||||||
cb();
|
const promises = authorizations.map(async authz => {
|
||||||
}, // return Promise
|
console.log(authz);
|
||||||
removeChallenge: async (hostname, key) => {
|
const domainDnsName: string = `_acme-challenge.${authz.identifier.value}`;
|
||||||
console.log('removing challenge');
|
const dnsChallenge: string = authz.challenges.find(challengeArg => {
|
||||||
return;
|
return challengeArg.type === 'dns-01';
|
||||||
} // return Promise
|
});
|
||||||
})
|
// process.exit(1);
|
||||||
.catch(e => {
|
const keyAuthorization: string = await this.client.getChallengeKeyAuthorization(dnsChallenge);
|
||||||
|
|
||||||
|
try {
|
||||||
|
/* Satisfy challenge */
|
||||||
|
await this.setChallenge(domainDnsName, keyAuthorization);
|
||||||
|
|
||||||
|
/* Verify that challenge is satisfied */
|
||||||
|
await this.client.verifyChallenge(authz, dnsChallenge);
|
||||||
|
|
||||||
|
/* Notify ACME provider that challenge is satisfied */
|
||||||
|
await this.client.completeChallenge(dnsChallenge);
|
||||||
|
|
||||||
|
/* Wait for ACME provider to respond with valid status */
|
||||||
|
await this.client.waitForValidStatus(dnsChallenge);
|
||||||
|
} finally {
|
||||||
|
/* Clean up challenge response */
|
||||||
|
try {
|
||||||
|
await this.removeChallenge(domainDnsName);
|
||||||
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}); // returns Promise<pems={ privkey (key), cert, chain (ca) }>
|
|
||||||
console.log(result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Wait for challenges to complete */
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
|
/* Finalize order */
|
||||||
|
const [key, csr] = await plugins.acme.forge.createCsr({
|
||||||
|
commonName: `*.${domain}`,
|
||||||
|
altNames: [domain]
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.client.finalizeOrder(order, csr);
|
||||||
|
const cert = await this.client.getCertificate(order);
|
||||||
|
|
||||||
|
/* Done */
|
||||||
|
console.log(`CSR:\n${csr.toString()}`);
|
||||||
|
console.log(`Private key:\n${key.toString()}`);
|
||||||
|
console.log(`Certificate:\n${cert.toString()}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
toStorageObject() {}
|
||||||
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
// @pushrocks scope
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
|
|
||||||
export {
|
export { smartpromise, smartdelay };
|
||||||
smartpromise,
|
|
||||||
smartdelay
|
// thirs party scope
|
||||||
}
|
import * as acme from 'acme-client';
|
||||||
|
|
||||||
|
export { acme };
|
||||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"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