Compare commits
50 Commits
Author | SHA1 | Date | |
---|---|---|---|
ad54bf41ea | |||
060ebf1b29 | |||
a87c6acb8a | |||
62d27619f4 | |||
0faebf2a79 | |||
29ea50796c | |||
26d1b7cbf0 | |||
c0c97835ea | |||
d4d50b7dcf | |||
2492fd4de2 | |||
bef54799b6 | |||
dbe09f320a | |||
18045dadaf | |||
ee300c3e12 | |||
ed4ba0cb61 | |||
a8ab27045d | |||
975c3ed190 | |||
a99dea549b | |||
f8b78c433a | |||
6c33111074 | |||
280335f6f6 | |||
b90092c043 | |||
9e1c73febf | |||
dcf1915816 | |||
748c911168 | |||
3a48cb4ea8 | |||
a035c5c0b0 | |||
f9c521b7b3 | |||
19cfe8bdc5 | |||
601d6b30d3 | |||
57ffc82c43 | |||
312d3c01cd | |||
8814c1fc62 | |||
223a47c997 | |||
651ef6d281 | |||
9eda0da9a7 | |||
3e350dfed5 | |||
6fc280e168 | |||
a9efae65d6 | |||
0f09bdaf9f | |||
84177cd575 | |||
7d16ada760 | |||
b4de8cc2be | |||
68e570c32a | |||
20ea599f9d | |||
5fa530456b | |||
2cd1794e7e | |||
1f38e12bd3 | |||
1c777f6f05 | |||
aad113a8ea |
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ node_modules/
|
|||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
.nogit/
|
||||||
|
117
.gitlab-ci.yml
117
.gitlab-ci.yml
@ -1,59 +1,150 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
# gitzone standard
|
||||||
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .npmci_cache/
|
||||||
|
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
|
||||||
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/
|
||||||
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/
|
||||||
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:npmpage
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: pages
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npmpage --host gitlab
|
- 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:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
4
.npmignore
Normal file
4
.npmignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
node_modules/
|
||||||
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
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: {}
|
61
README.md
61
README.md
@ -1,36 +1,63 @@
|
|||||||
# smartacme
|
# smartacme
|
||||||
|
|
||||||
acme implementation in TypeScript
|
acme implementation in TypeScript
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty
|
||||||
[](https://www.npmjs.com/package/smartacme)
|
|
||||||
[](https://GitLab.com/pushrocks/smartacme)
|
[](https://www.npmjs.com/package/smartacme)
|
||||||
[](https://github.com/pushrocks/smartacme)
|
[](https://GitLab.com/umbrellazone/smartacme)
|
||||||
[](https://pushrocks.gitlab.io/smartacme/)
|
[](https://github.com/umbrellazone/smartacme)
|
||||||
|
[](https://umbrellazone.gitlab.io/smartacme/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://GitLab.com/pushrocks/smartacme/commits/master)
|
|
||||||
[](https://GitLab.com/pushrocks/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)
|
||||||
[](https://david-dm.org/pushrocks/smartacme)
|
[](https://david-dm.org/umbrellazone/smartacme)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartacme/master/dependencies/npm)
|
[](https://www.bithound.io/github/umbrellazone/smartacme/master/dependencies/npm)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartacme)
|
[](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/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
[](http://standardjs.com/)
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import { SmartAcme } from 'smartacme'
|
import { SmartAcme } from 'smartacme';
|
||||||
|
|
||||||
let smac = new SmartAcme()
|
let smac = new SmartAcme()(async () => {
|
||||||
|
// learn async/await, it'll make your life easier
|
||||||
|
|
||||||
let myAccount = smac.getAccount() // optionally accepts a filePath Arg with a stored acmeaccount.json
|
// optionally accepts a filePath Arg with a stored acmeaccount.json
|
||||||
let myCert = myAccount.getChallenge('example.com','dns-01') // will return a dnsHash to set in your DNS record
|
// will create an account and
|
||||||
myCert.get().then(() => {
|
let myAccount = await smac.createAcmeAccount();
|
||||||
console.log(myCert.certificate) // your certificate, ready to use in whatever way you prefer
|
|
||||||
})
|
// 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
|
||||||
|
-------------*/
|
||||||
|
})();
|
||||||
```
|
```
|
||||||
|
|
||||||
[](https://push.rocks)
|
## 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
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export * from './smartacme.classes.smartacme';
|
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -1,6 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
function __export(m) {
|
|
||||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
||||||
}
|
|
||||||
__export(require("./smartacme.classes.smartacme"));
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsbURBQTZDIn0=
|
|
23
dist/smartacme.classes.acmeaccount.d.ts
vendored
23
dist/smartacme.classes.acmeaccount.d.ts
vendored
@ -1,23 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as q from 'q';
|
|
||||||
import { SmartAcme } from './smartacme.classes.smartacme';
|
|
||||||
import { AcmeCert } from './smartacme.classes.acmecert';
|
|
||||||
/**
|
|
||||||
* class AcmeAccount represents an AcmeAccount
|
|
||||||
*/
|
|
||||||
export declare class AcmeAccount {
|
|
||||||
parentSmartAcme: SmartAcme;
|
|
||||||
location: string;
|
|
||||||
link: string;
|
|
||||||
JWK: any;
|
|
||||||
constructor(smartAcmeParentArg: SmartAcme);
|
|
||||||
/**
|
|
||||||
* register the account with letsencrypt
|
|
||||||
*/
|
|
||||||
register(): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* agree to letsencrypr terms of service
|
|
||||||
*/
|
|
||||||
agreeTos(): q.Promise<{}>;
|
|
||||||
createAcmeCert(domainNameArg: string, countryArg?: string, countryShortArg?: string, city?: string, companyArg?: string, companyShortArg?: string): q.Promise<AcmeCert>;
|
|
||||||
}
|
|
71
dist/smartacme.classes.acmeaccount.js
vendored
71
dist/smartacme.classes.acmeaccount.js
vendored
@ -1,71 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const q = require("q");
|
|
||||||
const smartacme_classes_acmecert_1 = require("./smartacme.classes.acmecert");
|
|
||||||
/**
|
|
||||||
* class AcmeAccount represents an AcmeAccount
|
|
||||||
*/
|
|
||||||
class AcmeAccount {
|
|
||||||
constructor(smartAcmeParentArg) {
|
|
||||||
this.parentSmartAcme = smartAcmeParentArg;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* register the account with letsencrypt
|
|
||||||
*/
|
|
||||||
register() {
|
|
||||||
let done = q.defer();
|
|
||||||
this.parentSmartAcme.rawacmeClient.newReg({
|
|
||||||
contact: ['mailto:domains@lossless.org']
|
|
||||||
}, (err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('smartacme: something went wrong:');
|
|
||||||
console.log(err);
|
|
||||||
done.reject(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.JWK = res.body.key;
|
|
||||||
this.link = res.headers.link;
|
|
||||||
console.log(this.link);
|
|
||||||
this.location = res.headers.location;
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* agree to letsencrypr terms of service
|
|
||||||
*/
|
|
||||||
agreeTos() {
|
|
||||||
let done = q.defer();
|
|
||||||
let tosPart = this.link.split(',')[1];
|
|
||||||
let tosLinkPortion = tosPart.split(';')[0];
|
|
||||||
let url = tosLinkPortion.split(';')[0].trim().replace(/[<>]/g, '');
|
|
||||||
this.parentSmartAcme.rawacmeClient.post(this.location, { Agreement: url, resource: 'reg' }, (err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
done.reject(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
createAcmeCert(domainNameArg, countryArg = 'Germany', countryShortArg = 'DE', city = 'Bremen', companyArg = 'Some Company', companyShortArg = 'SC') {
|
|
||||||
let done = q.defer();
|
|
||||||
let acmeCert = new smartacme_classes_acmecert_1.AcmeCert({
|
|
||||||
bit: 2064,
|
|
||||||
key: null,
|
|
||||||
domain: domainNameArg,
|
|
||||||
country: countryArg,
|
|
||||||
country_short: countryShortArg,
|
|
||||||
locality: city,
|
|
||||||
organization: companyArg,
|
|
||||||
organization_short: companyShortArg,
|
|
||||||
password: null,
|
|
||||||
unstructured: null,
|
|
||||||
subject_alt_names: null
|
|
||||||
}, this);
|
|
||||||
done.resolve(acmeCert);
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.AcmeAccount = AcmeAccount;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuYWNtZWFjY291bnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUuY2xhc3Nlcy5hY21lYWNjb3VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsdUJBQXNCO0FBTXRCLDZFQUF1RDtBQUV2RDs7R0FFRztBQUNIO0lBS0ksWUFBWSxrQkFBNkI7UUFDckMsSUFBSSxDQUFDLGVBQWUsR0FBRyxrQkFBa0IsQ0FBQTtJQUM3QyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxRQUFRO1FBQ0osSUFBSSxJQUFJLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQ3BCLElBQUksQ0FBQyxlQUFlLENBQUMsYUFBYSxDQUFDLE1BQU0sQ0FDckM7WUFDSSxPQUFPLEVBQUUsQ0FBQyw2QkFBNkIsQ0FBQztTQUMzQyxFQUNELENBQUMsR0FBRyxFQUFFLEdBQUc7WUFDTCxFQUFFLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDO2dCQUNOLE9BQU8sQ0FBQyxLQUFLLENBQUMsa0NBQWtDLENBQUMsQ0FBQTtnQkFDakQsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQTtnQkFDaEIsSUFBSSxDQUFDLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQTtnQkFDaEIsTUFBTSxDQUFBO1lBQ1YsQ0FBQztZQUNELElBQUksQ0FBQyxHQUFHLEdBQUcsR0FBRyxDQUFDLElBQUksQ0FBQyxHQU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rRkMifQ==
|
|
79
dist/smartacme.classes.acmecert.d.ts
vendored
79
dist/smartacme.classes.acmecert.d.ts
vendored
@ -1,79 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as q from 'q';
|
|
||||||
import { IRsaKeypair } from './smartacme.classes.smartacme';
|
|
||||||
import { AcmeAccount } from './smartacme.classes.acmeaccount';
|
|
||||||
/**
|
|
||||||
* types of challenges supported by letsencrypt and this module
|
|
||||||
*/
|
|
||||||
export declare type TChallengeType = 'dns-01' | 'http-01';
|
|
||||||
/**
|
|
||||||
* values that a challenge's status can have
|
|
||||||
*/
|
|
||||||
export declare type TChallengeStatus = 'pending';
|
|
||||||
export interface ISmartAcmeChallenge {
|
|
||||||
uri: string;
|
|
||||||
status: TChallengeStatus;
|
|
||||||
type: TChallengeType;
|
|
||||||
token: string;
|
|
||||||
keyAuthorization: string;
|
|
||||||
}
|
|
||||||
export interface ISmartAcmeChallengeAccepted extends ISmartAcmeChallenge {
|
|
||||||
dnsKeyHash: string;
|
|
||||||
domainName: string;
|
|
||||||
domainNamePrefixed: string;
|
|
||||||
}
|
|
||||||
export interface IAcmeCsrConstructorOptions {
|
|
||||||
bit: number;
|
|
||||||
key: string;
|
|
||||||
domain: string;
|
|
||||||
country: string;
|
|
||||||
country_short: string;
|
|
||||||
locality: string;
|
|
||||||
organization: string;
|
|
||||||
organization_short: string;
|
|
||||||
password: string;
|
|
||||||
unstructured: string;
|
|
||||||
subject_alt_names: string[];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* class AcmeCert represents a cert for domain
|
|
||||||
*/
|
|
||||||
export declare class AcmeCert {
|
|
||||||
domainName: string;
|
|
||||||
attributes: any;
|
|
||||||
acceptedChallenge: ISmartAcmeChallengeAccepted;
|
|
||||||
fullchain: string;
|
|
||||||
parentAcmeAccount: AcmeAccount;
|
|
||||||
csr: any;
|
|
||||||
validFrom: Date;
|
|
||||||
validTo: Date;
|
|
||||||
keypair: IRsaKeypair;
|
|
||||||
keyPairFinal: IRsaKeypair;
|
|
||||||
constructor(optionsArg: IAcmeCsrConstructorOptions, parentAcmeAccount: AcmeAccount);
|
|
||||||
/**
|
|
||||||
* requests a challenge for a domain
|
|
||||||
* @param domainNameArg - the domain name to request a challenge for
|
|
||||||
* @param challengeType - the challenge type to request
|
|
||||||
*/
|
|
||||||
requestChallenge(challengeTypeArg?: TChallengeType): q.Promise<ISmartAcmeChallengeAccepted>;
|
|
||||||
/**
|
|
||||||
* checks if DNS records are set
|
|
||||||
*/
|
|
||||||
checkDns(): Promise<any>;
|
|
||||||
/**
|
|
||||||
* validates a challenge, only call after you have set the challenge at the expected location
|
|
||||||
*/
|
|
||||||
requestValidation(): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* requests a certificate
|
|
||||||
*/
|
|
||||||
requestCert(): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* getCertificate - takes care of cooldown, validation polling and certificate retrieval
|
|
||||||
*/
|
|
||||||
getCertificate(): void;
|
|
||||||
/**
|
|
||||||
* accept a challenge - for private use only
|
|
||||||
*/
|
|
||||||
private acceptChallenge(challengeArg);
|
|
||||||
}
|
|
181
dist/smartacme.classes.acmecert.js
vendored
181
dist/smartacme.classes.acmecert.js
vendored
File diff suppressed because one or more lines are too long
34
dist/smartacme.classes.smartacme.d.ts
vendored
34
dist/smartacme.classes.smartacme.d.ts
vendored
@ -1,34 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as q from 'q';
|
|
||||||
import { AcmeAccount } from './smartacme.classes.acmeaccount';
|
|
||||||
/**
|
|
||||||
* a rsa keypair needed for account creation and subsequent requests
|
|
||||||
*/
|
|
||||||
export interface IRsaKeypair {
|
|
||||||
publicKey: string;
|
|
||||||
privateKey: string;
|
|
||||||
}
|
|
||||||
export { AcmeAccount } from './smartacme.classes.acmeaccount';
|
|
||||||
export { AcmeCert, ISmartAcmeChallenge, ISmartAcmeChallengeAccepted } from './smartacme.classes.acmecert';
|
|
||||||
/**
|
|
||||||
* class SmartAcme exports methods for maintaining SSL Certificates
|
|
||||||
*/
|
|
||||||
export declare class SmartAcme {
|
|
||||||
acmeUrl: string;
|
|
||||||
productionBool: boolean;
|
|
||||||
keyPair: IRsaKeypair;
|
|
||||||
rawacmeClient: any;
|
|
||||||
/**
|
|
||||||
* the constructor for class SmartAcme
|
|
||||||
*/
|
|
||||||
constructor(productionArg?: boolean);
|
|
||||||
/**
|
|
||||||
* init the smartacme instance
|
|
||||||
*/
|
|
||||||
init(): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* creates an account if not currently present in module
|
|
||||||
* @executes ASYNC
|
|
||||||
*/
|
|
||||||
createAccount(): q.Promise<AcmeAccount>;
|
|
||||||
}
|
|
66
dist/smartacme.classes.smartacme.js
vendored
66
dist/smartacme.classes.smartacme.js
vendored
@ -1,66 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
// third party modules
|
|
||||||
const q = require("q"); // promises
|
|
||||||
const plugins = require("./smartacme.plugins");
|
|
||||||
const helpers = require("./smartacme.helpers");
|
|
||||||
const smartacme_classes_acmeaccount_1 = require("./smartacme.classes.acmeaccount");
|
|
||||||
var smartacme_classes_acmeaccount_2 = require("./smartacme.classes.acmeaccount");
|
|
||||||
exports.AcmeAccount = smartacme_classes_acmeaccount_2.AcmeAccount;
|
|
||||||
var smartacme_classes_acmecert_1 = require("./smartacme.classes.acmecert");
|
|
||||||
exports.AcmeCert = smartacme_classes_acmecert_1.AcmeCert;
|
|
||||||
/**
|
|
||||||
* class SmartAcme exports methods for maintaining SSL Certificates
|
|
||||||
*/
|
|
||||||
class SmartAcme {
|
|
||||||
/**
|
|
||||||
* the constructor for class SmartAcme
|
|
||||||
*/
|
|
||||||
constructor(productionArg = false) {
|
|
||||||
this.productionBool = productionArg;
|
|
||||||
this.keyPair = helpers.createKeypair();
|
|
||||||
if (this.productionBool) {
|
|
||||||
this.acmeUrl = plugins.rawacme.LETSENCRYPT_URL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.acmeUrl = plugins.rawacme.LETSENCRYPT_STAGING_URL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* init the smartacme instance
|
|
||||||
*/
|
|
||||||
init() {
|
|
||||||
let done = q.defer();
|
|
||||||
plugins.rawacme.createClient({
|
|
||||||
url: this.acmeUrl,
|
|
||||||
publicKey: this.keyPair.publicKey,
|
|
||||||
privateKey: this.keyPair.privateKey
|
|
||||||
}, (err, client) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('smartacme: something went wrong:');
|
|
||||||
console.log(err);
|
|
||||||
done.reject(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// make client available in class
|
|
||||||
this.rawacmeClient = client;
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* creates an account if not currently present in module
|
|
||||||
* @executes ASYNC
|
|
||||||
*/
|
|
||||||
createAccount() {
|
|
||||||
let done = q.defer();
|
|
||||||
let acmeAccount = new smartacme_classes_acmeaccount_1.AcmeAccount(this);
|
|
||||||
acmeAccount.register().then(() => {
|
|
||||||
return acmeAccount.agreeTos();
|
|
||||||
}).then(() => {
|
|
||||||
done.resolve(acmeAccount);
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.SmartAcme = SmartAcme;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxzQkFBc0I7QUFDdEIsdUJBQXNCLENBQUMsV0FBVztBQUNsQywrQ0FBOEM7QUFDOUMsK0NBQThDO0FBRTlDLG1GQUE2RDtBQVU3RCxpRkFBNkQ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0FBQyxDQUFBO2dCQUNoQixJQUFJLENBQUMsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFBO2dCQUNoQixNQUFNLENBQUE7WUFDVixDQUFDO1lBRUQsa0NBQWtDO1lBQ2xDLElBQUksQ0FBQyxhQUFhLEdBQUcsTUFBTSxDQUFBO1lBQzNCLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNsQixDQUFDLENBQ0osQ0FBQTtRQUNELE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRDs7O09BR0c7SUFDSCxhQUFhO1FBQ1QsSUFBSSxJQUFJLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBZSxDQUFBO1FBQ2pDLElBQUksV0FBVyxHQUFHLElBQUksMkNBQVcsQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUN2QyxXQUFXLENBQUMsUUFBUSxFQUFFLENBQUMsSUFBSSxDQUFDO1lBQ3hCLE1BQU0sQ0FBQyxXQUFXLENBQUMsUUFBUSxFQUFFLENBQUE7UUFDakMsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDO1lBQ0osSUFBSSxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQTtRQUM3QixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7Q0FDSjtBQTVERCw4QkE0REMifQ==
|
|
10
dist/smartacme.helpers.d.ts
vendored
10
dist/smartacme.helpers.d.ts
vendored
@ -1,10 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
import { IRsaKeypair } from './smartacme.classes.smartacme';
|
|
||||||
/**
|
|
||||||
* creates a keypair to use with requests and to generate JWK from
|
|
||||||
*/
|
|
||||||
export declare let createKeypair: (bit?: number) => IRsaKeypair;
|
|
||||||
/**
|
|
||||||
* prefix a domain name to make sure it complies with letsencrypt
|
|
||||||
*/
|
|
||||||
export declare let prefixName: (domainNameArg: string) => string;
|
|
40
dist/smartacme.helpers.js
vendored
40
dist/smartacme.helpers.js
vendored
@ -1,40 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global");
|
|
||||||
const q = require("q");
|
|
||||||
const plugins = require("./smartacme.plugins");
|
|
||||||
/**
|
|
||||||
* creates a keypair to use with requests and to generate JWK from
|
|
||||||
*/
|
|
||||||
exports.createKeypair = (bit = 2048) => {
|
|
||||||
let result = plugins.rsaKeygen.generate(bit);
|
|
||||||
return {
|
|
||||||
publicKey: result.public_key,
|
|
||||||
privateKey: result.private_key
|
|
||||||
};
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* prefix a domain name to make sure it complies with letsencrypt
|
|
||||||
*/
|
|
||||||
exports.prefixName = (domainNameArg) => {
|
|
||||||
return '_acme-challenge.' + domainNameArg;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* gets an existing registration
|
|
||||||
* @executes ASYNC
|
|
||||||
*/
|
|
||||||
let getReg = (SmartAcmeArg, location) => {
|
|
||||||
let done = q.defer();
|
|
||||||
let body = { resource: 'reg' };
|
|
||||||
SmartAcmeArg.rawacmeClient.post(location, body, SmartAcmeArg.keyPair, (err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('smartacme: something went wrong:');
|
|
||||||
console.log(err);
|
|
||||||
done.reject(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log(JSON.stringify(res.body));
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHVCQUFzQjtBQUV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sR0FBRyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUE7UUFDckMsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO0lBQ2xCLENBQUMsQ0FDSixDQUFBO0lBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDdkIsQ0FBQyxDQUFBIn0=
|
|
2
dist/smartacme.paths.d.ts
vendored
2
dist/smartacme.paths.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
export declare let packageDir: string;
|
|
||||||
export declare let assetDir: string;
|
|
7
dist/smartacme.paths.js
vendored
7
dist/smartacme.paths.js
vendored
@ -1,7 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const path = require("path");
|
|
||||||
const smartfile = require("smartfile");
|
|
||||||
exports.packageDir = path.join(__dirname, '../');
|
|
||||||
exports.assetDir = path.join(exports.packageDir, 'assets/');
|
|
||||||
smartfile.fs.ensureDirSync(exports.assetDir);
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw2QkFBNEI7QUFDNUIsdUNBQXNDO0FBRTNCLFFBQUEsVUFBVSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFBO0FBQ3ZDLFFBQUEsUUFBUSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsa0JBQVUsRUFBQyxTQUFTLENBQUMsQ0FBQTtBQUNyRCxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyxnQkFBUSxDQUFDLENBQUEifQ==
|
|
8
dist/smartacme.plugins.d.ts
vendored
8
dist/smartacme.plugins.d.ts
vendored
@ -1,8 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
declare let rsaKeygen: any;
|
|
||||||
declare let rawacme: any;
|
|
||||||
declare let nodeForge: any;
|
|
||||||
import * as dnsly from 'dnsly';
|
|
||||||
import * as smartfile from 'smartfile';
|
|
||||||
import * as smartstring from 'smartstring';
|
|
||||||
export { dnsly, rsaKeygen, rawacme, nodeForge, smartfile, smartstring };
|
|
16
dist/smartacme.plugins.js
vendored
16
dist/smartacme.plugins.js
vendored
@ -1,16 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global"); // typings for node
|
|
||||||
let rsaKeygen = require('rsa-keygen'); // rsa keygen
|
|
||||||
exports.rsaKeygen = rsaKeygen;
|
|
||||||
let rawacme = require('rawacme'); // acme helper functions
|
|
||||||
exports.rawacme = rawacme;
|
|
||||||
let nodeForge = require('node-forge');
|
|
||||||
exports.nodeForge = nodeForge;
|
|
||||||
// push.rocks modules here
|
|
||||||
const dnsly = require("dnsly");
|
|
||||||
exports.dnsly = dnsly;
|
|
||||||
const smartfile = require("smartfile");
|
|
||||||
exports.smartfile = smartfile;
|
|
||||||
const smartstring = require("smartstring");
|
|
||||||
exports.smartstring = smartstring;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCLENBQUMsbUJBQW1CO0FBRzNDLElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQSxDQUFDLGFBQWE7QUFXL0MsOEJBQVM7QUFWYixJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUEsQ0FBQyx3QkFBd0I7QUFXckQsMEJBQU87QUFWWCxJQUFJLFNBQVMsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUE7QUFXakMsOEJBQVM7QUFUYiwwQkFBMEI7QUFDMUIsK0JBQThCO0FBSzFCLHNCQUFLO0FBSlQsdUNBQXNDO0FBUWxDLDhCQUFTO0FBUGIsMkNBQTBDO0FBUXRDLGtDQUFXIn0=
|
|
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
"npmAccessLevel": "public"
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
2578
package-lock.json
generated
Normal file
2578
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
48
package.json
48
package.json
@ -1,15 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "smartacme",
|
"name": "@pushrocks/smartacme",
|
||||||
"version": "1.0.6",
|
"version": "2.0.13",
|
||||||
|
"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": "(npmts --nodocs)"
|
"test": "(tstest test/)",
|
||||||
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartacme.git"
|
"url": "git+ssh://git@gitlab.com/umbrellazone/smartacme.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"TypeScript",
|
"TypeScript",
|
||||||
@ -19,26 +21,30 @@
|
|||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pushrocks/smartacme/issues"
|
"url": "https://gitlab.com/umbrellazone/smartacme/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartacme#README",
|
"homepage": "https://gitlab.com/umbrellazone/smartacme#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node-forge": "^0.6.5",
|
"@pushrocks/lik": "^3.0.4",
|
||||||
"@types/q": "0.x.x",
|
"@pushrocks/smartdata": "^3.1.13",
|
||||||
"dnsly": "^1.0.7",
|
"@pushrocks/smartdelay": "^2.0.2",
|
||||||
"node-forge": "^0.6.47",
|
"@pushrocks/smartdns": "^3.0.8",
|
||||||
"q": "^1.4.1",
|
"@pushrocks/smartexpress": "^3.0.0",
|
||||||
"rawacme": "^0.2.1",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"rsa-keygen": "^1.0.6",
|
"@pushrocks/smartrequest": "^1.1.14",
|
||||||
"smartfile": "^4.1.2",
|
"@pushrocks/smarttime": "^3.0.5",
|
||||||
"smartstring": "^2.0.22",
|
"@pushrocks/smartunique": "^3.0.1",
|
||||||
"typings-global": "^1.0.14"
|
"acme-client": "^2.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.30",
|
"@gitzone/tsbuild": "^2.1.4",
|
||||||
"cflare": "0.0.10",
|
"@gitzone/tsrun": "^1.1.17",
|
||||||
"qenv": "^1.1.1",
|
"@gitzone/tstest": "^1.0.18",
|
||||||
"should": "^11.1.2",
|
"@mojoio/cloudflare": "^2.0.0",
|
||||||
"typings-test": "^1.0.3"
|
"@pushrocks/qenv": "^3.0.2",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
|
"@types/node": "^10.12.18",
|
||||||
|
"tslint": "^5.12.0",
|
||||||
|
"tslint-config-prettier": "^1.17.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
qenv.yml
Normal file
6
qenv.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
required:
|
||||||
|
- CF_EMAIL
|
||||||
|
- CF_KEY
|
||||||
|
- MONGODB_URL
|
||||||
|
- MONGODB_PASSWORD
|
||||||
|
- MONGODB_DATABASE
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
import 'typings-test';
|
|
59
test/test.js
59
test/test.js
@ -1,59 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-test");
|
|
||||||
const should = require("should");
|
|
||||||
// import the module to test
|
|
||||||
const smartacme = require("../dist/index");
|
|
||||||
describe('smartacme', function () {
|
|
||||||
let testSmartAcme;
|
|
||||||
let testAcmeAccount;
|
|
||||||
let testAcmeCert;
|
|
||||||
let testChallenge;
|
|
||||||
it('should create a valid instance', function (done) {
|
|
||||||
this.timeout(10000);
|
|
||||||
testSmartAcme = new smartacme.SmartAcme();
|
|
||||||
testSmartAcme.init().then(() => {
|
|
||||||
should(testSmartAcme).be.instanceOf(smartacme.SmartAcme);
|
|
||||||
done();
|
|
||||||
}).catch(err => { done(err); });
|
|
||||||
});
|
|
||||||
it('should have created keyPair', function () {
|
|
||||||
should(testSmartAcme.acmeUrl).be.of.type('string');
|
|
||||||
});
|
|
||||||
it('should register a new account', function (done) {
|
|
||||||
this.timeout(10000);
|
|
||||||
testSmartAcme.createAccount().then(x => {
|
|
||||||
testAcmeAccount = x;
|
|
||||||
done();
|
|
||||||
}).catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
done(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should create a AcmeCert', function () {
|
|
||||||
testAcmeAccount.createAcmeCert('test1.bleu.de').then(x => {
|
|
||||||
testAcmeCert = x;
|
|
||||||
should(testAcmeAccount).be.instanceOf(smartacme.AcmeCert);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should get a challenge for a AcmeCert', function (done) {
|
|
||||||
this.timeout(10000);
|
|
||||||
testAcmeCert.requestChallenge().then((challengeAccepted) => {
|
|
||||||
console.log(challengeAccepted);
|
|
||||||
testChallenge = challengeAccepted;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should check for a DNS record', function (done) {
|
|
||||||
testAcmeCert.checkDns().then(x => {
|
|
||||||
console.log(x);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should poll for validation of a challenge', function (done) {
|
|
||||||
this.timeout(10000);
|
|
||||||
testAcmeCert.requestValidation().then(x => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFHaEMsNEJBQTRCO0FBQzVCLDJDQUEwQztBQUUxQyxRQUFRLENBQUMsV0FBVyxFQUFFO0lBQ2xCLElBQUksYUFBa0MsQ0FBQTtJQUN0QyxJQUFJLGVBQXNDLENBQUE7SUFDMUMsSUFBSSxZQUFnQyxDQUFBO0lBQ3BDLElBQUksYUFBb0QsQ0FBQTtJQUV4RCxFQUFFLENBQUMsZ0NBQWdDLEVBQUUsVUFBVSxJQUFJO1FBQy9DLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUE7UUFDbkIsYUFBYSxHQUFHLElBQUksU0FBUyxDQUFDLFNBQVMsRUFBRSxDQUFBO1FBQ3pDLGFBQWEsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxJQUFJLENBQUM7WUFDdEIsTUFBTSxDQUFDLGFBQWEsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsU0FBUyxDQUFDLFNBQVMsQ0FBQyxDQUFBO1lBQ3hELElBQUksRUFBRSxDQUFBO1FBQ1YsQ0FBQyxDQUFDLENBQUMsS0FBSyxDQUFDLEdBQUc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yxFQUFFLFVBQVUsSUFBSTtRQUN0RCxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLFlBQVksQ0FBQyxnQkFBZ0IsRUFBRSxDQUFDLElBQUksQ0FBQyxDQUFDLGlCQUFpQjtZQUNuRCxPQUFPLENBQUMsR0FBRyxDQUFDLGlCQUFpQixDQUFDLENBQUE7WUFDOUIsYUFBYSxHQUFHLGlCQUFpQixDQUFBO1lBQ2pDLElBQUksRUFBRSxDQUFBO1FBQ1YsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtJQUVGLEVBQUUsQ0FBQywrQkFBK0IsRUFBRSxVQUFTLElBQUk7UUFDN0MsWUFBWSxDQUFDLFFBQVEsRUFBRSxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQzFCLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUE7WUFDZCxJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7SUFFRixFQUFFLENBQUMsMkNBQTJDLEVBQUUsVUFBVSxJQUFJO1FBQzFELElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUE7UUFDbkIsWUFBWSxDQUFDLGlCQUFpQixFQUFFLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDbkMsSUFBSSxFQUFFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
|
91
test/test.ts
91
test/test.ts
@ -1,68 +1,33 @@
|
|||||||
import 'typings-test'
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as should from 'should'
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
import * as cflare from 'cflare'
|
|
||||||
import * as qenv from 'qenv'
|
|
||||||
|
|
||||||
// import the module to test
|
const testQenv = new Qenv('./', './.nogit/');
|
||||||
import * as smartacme from '../dist/index'
|
|
||||||
|
|
||||||
describe('smartacme', function () {
|
import * as smartacme from '../ts/index';
|
||||||
let testSmartAcme: smartacme.SmartAcme
|
|
||||||
let testAcmeAccount: smartacme.AcmeAccount
|
|
||||||
let testAcmeCert: smartacme.AcmeCert
|
|
||||||
let testChallenge: smartacme.ISmartAcmeChallengeAccepted
|
|
||||||
|
|
||||||
it('should create a valid instance', function (done) {
|
let smartAcmeInstance: smartacme.SmartAcme;
|
||||||
this.timeout(10000)
|
|
||||||
testSmartAcme = new smartacme.SmartAcme()
|
|
||||||
testSmartAcme.init().then(() => {
|
|
||||||
should(testSmartAcme).be.instanceOf(smartacme.SmartAcme)
|
|
||||||
done()
|
|
||||||
}).catch(err => { done(err) })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should have created keyPair', function () {
|
tap.test('should create a valid instance of SmartAcme', async () => {
|
||||||
should(testSmartAcme.acmeUrl).be.of.type('string')
|
smartAcmeInstance = new smartacme.SmartAcme({
|
||||||
})
|
accountEmail: 'domains@lossless.org',
|
||||||
|
accountPrivateKey: null,
|
||||||
|
mongoDescriptor: {
|
||||||
|
mongoDbName: testQenv.getEnvVarOnDemand('MONGODB_DATABASE'),
|
||||||
|
mongoDbPass: testQenv.getEnvVarOnDemand('MONGODB_PASSWORD'),
|
||||||
|
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGODB_URL')
|
||||||
|
},
|
||||||
|
removeChallenge: async (...args) => {
|
||||||
|
console.log(args);
|
||||||
|
},
|
||||||
|
setChallenge: async (...args) => {
|
||||||
|
console.log(args);
|
||||||
|
},
|
||||||
|
validateRemoteRequest: async () => {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await smartAcmeInstance.init();
|
||||||
|
// await smartAcmeInstance.getCertificateForDomain('bleu.de');
|
||||||
|
});
|
||||||
|
|
||||||
it('should register a new account', function (done) {
|
tap.start();
|
||||||
this.timeout(10000)
|
|
||||||
testSmartAcme.createAccount().then(x => {
|
|
||||||
testAcmeAccount = x
|
|
||||||
done()
|
|
||||||
}).catch(err => {
|
|
||||||
console.log(err)
|
|
||||||
done(err)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should create a AcmeCert', function() {
|
|
||||||
testAcmeAccount.createAcmeCert('test1.bleu.de').then(x => {
|
|
||||||
testAcmeCert = x
|
|
||||||
should(testAcmeAccount).be.instanceOf(smartacme.AcmeCert)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should get a challenge for a AcmeCert', function (done) {
|
|
||||||
this.timeout(10000)
|
|
||||||
testAcmeCert.requestChallenge().then((challengeAccepted) => {
|
|
||||||
console.log(challengeAccepted)
|
|
||||||
testChallenge = challengeAccepted
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should check for a DNS record', function(done) {
|
|
||||||
testAcmeCert.checkDns().then(x => {
|
|
||||||
console.log(x)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it.skip('should poll for validation of a challenge', function (done) {
|
|
||||||
this.timeout(10000)
|
|
||||||
testAcmeCert.requestValidation().then(x => {
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
@ -1 +1,3 @@
|
|||||||
export * from './smartacme.classes.smartacme'
|
export * from './smartacme.classes.smartacme';
|
||||||
|
|
||||||
|
export * from './smartacme.classes.certremoteclient';
|
||||||
|
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;
|
||||||
|
}
|
9
ts/interfaces/cert.ts
Normal file
9
ts/interfaces/cert.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export type TCertStatus = 'existing' | 'nonexisting' | 'pending' | 'failed';
|
||||||
|
|
||||||
|
export interface ICert {
|
||||||
|
domainName: string;
|
||||||
|
created: number;
|
||||||
|
privateKey: string;
|
||||||
|
publicKey: string;
|
||||||
|
csr: string;
|
||||||
|
}
|
11
ts/interfaces/certremote.ts
Normal file
11
ts/interfaces/certremote.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { ICert, TCertStatus } from './cert';
|
||||||
|
|
||||||
|
export interface ICertRemoteRequest {
|
||||||
|
secret: string;
|
||||||
|
domainName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ICertRemoteResponse {
|
||||||
|
status: TCertStatus;
|
||||||
|
certificate?: ICert;
|
||||||
|
}
|
3
ts/interfaces/index.ts
Normal file
3
ts/interfaces/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export * from './accountdata';
|
||||||
|
export * from './cert';
|
||||||
|
export * from './certremote';
|
@ -1,94 +0,0 @@
|
|||||||
import * as q from 'q'
|
|
||||||
|
|
||||||
import * as plugins from './smartacme.plugins'
|
|
||||||
import * as helpers from './smartacme.helpers'
|
|
||||||
|
|
||||||
import { SmartAcme, IRsaKeypair } from './smartacme.classes.smartacme'
|
|
||||||
import { AcmeCert } from './smartacme.classes.acmecert'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class AcmeAccount represents an AcmeAccount
|
|
||||||
*/
|
|
||||||
export class AcmeAccount {
|
|
||||||
parentSmartAcme: SmartAcme
|
|
||||||
location: string
|
|
||||||
link: string
|
|
||||||
JWK
|
|
||||||
constructor(smartAcmeParentArg: SmartAcme) {
|
|
||||||
this.parentSmartAcme = smartAcmeParentArg
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* register the account with letsencrypt
|
|
||||||
*/
|
|
||||||
register() {
|
|
||||||
let done = q.defer()
|
|
||||||
this.parentSmartAcme.rawacmeClient.newReg(
|
|
||||||
{
|
|
||||||
contact: ['mailto:domains@lossless.org']
|
|
||||||
},
|
|
||||||
(err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('smartacme: something went wrong:')
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.JWK = res.body.key
|
|
||||||
this.link = res.headers.link
|
|
||||||
console.log(this.link)
|
|
||||||
this.location = res.headers.location
|
|
||||||
done.resolve()
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* agree to letsencrypr terms of service
|
|
||||||
*/
|
|
||||||
agreeTos() {
|
|
||||||
let done = q.defer()
|
|
||||||
let tosPart = this.link.split(',')[1]
|
|
||||||
let tosLinkPortion = tosPart.split(';')[0]
|
|
||||||
let url = tosLinkPortion.split(';')[0].trim().replace(/[<>]/g, '')
|
|
||||||
this.parentSmartAcme.rawacmeClient.post(this.location, { Agreement: url, resource: 'reg' }, (err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
done.resolve()
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
createAcmeCert(
|
|
||||||
domainNameArg: string,
|
|
||||||
countryArg = 'Germany',
|
|
||||||
countryShortArg = 'DE',
|
|
||||||
city = 'Bremen',
|
|
||||||
companyArg = 'Some Company',
|
|
||||||
companyShortArg = 'SC'
|
|
||||||
|
|
||||||
) {
|
|
||||||
let done = q.defer<AcmeCert>()
|
|
||||||
let acmeCert = new AcmeCert(
|
|
||||||
{
|
|
||||||
bit: 2064,
|
|
||||||
key: null, // not needed right now
|
|
||||||
domain: domainNameArg,
|
|
||||||
country: countryArg,
|
|
||||||
country_short: countryShortArg,
|
|
||||||
locality: city,
|
|
||||||
organization: companyArg,
|
|
||||||
organization_short: companyShortArg,
|
|
||||||
password: null,
|
|
||||||
unstructured: null,
|
|
||||||
subject_alt_names: null
|
|
||||||
},
|
|
||||||
this
|
|
||||||
)
|
|
||||||
done.resolve(acmeCert)
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,259 +0,0 @@
|
|||||||
import * as q from 'q'
|
|
||||||
|
|
||||||
import * as plugins from './smartacme.plugins'
|
|
||||||
import * as helpers from './smartacme.helpers'
|
|
||||||
|
|
||||||
import { SmartAcme, IRsaKeypair } from './smartacme.classes.smartacme'
|
|
||||||
import { AcmeAccount } from './smartacme.classes.acmeaccount'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* types of challenges supported by letsencrypt and this module
|
|
||||||
*/
|
|
||||||
export type TChallengeType = 'dns-01' | 'http-01'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* values that a challenge's status can have
|
|
||||||
*/
|
|
||||||
export type TChallengeStatus = 'pending'
|
|
||||||
|
|
||||||
export interface ISmartAcmeChallenge {
|
|
||||||
uri: string
|
|
||||||
status: TChallengeStatus
|
|
||||||
type: TChallengeType
|
|
||||||
token: string
|
|
||||||
keyAuthorization: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ISmartAcmeChallengeAccepted extends ISmartAcmeChallenge {
|
|
||||||
dnsKeyHash: string
|
|
||||||
domainName: string
|
|
||||||
domainNamePrefixed: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IAcmeCsrConstructorOptions {
|
|
||||||
bit: number,
|
|
||||||
key: string,
|
|
||||||
domain: string,
|
|
||||||
country: string,
|
|
||||||
country_short: string,
|
|
||||||
locality: string,
|
|
||||||
organization: string,
|
|
||||||
organization_short: string,
|
|
||||||
password: string,
|
|
||||||
unstructured: string,
|
|
||||||
subject_alt_names: string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dnsly instance (we really just need one)
|
|
||||||
let myDnsly = new plugins.dnsly.Dnsly('google')
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class AcmeCert represents a cert for domain
|
|
||||||
*/
|
|
||||||
export class AcmeCert {
|
|
||||||
domainName: string
|
|
||||||
attributes
|
|
||||||
acceptedChallenge: ISmartAcmeChallengeAccepted
|
|
||||||
fullchain: string
|
|
||||||
parentAcmeAccount: AcmeAccount
|
|
||||||
csr
|
|
||||||
validFrom: Date
|
|
||||||
validTo: Date
|
|
||||||
keypair: IRsaKeypair
|
|
||||||
keyPairFinal: IRsaKeypair
|
|
||||||
constructor(optionsArg: IAcmeCsrConstructorOptions, parentAcmeAccount: AcmeAccount) {
|
|
||||||
this.domainName = optionsArg.domain
|
|
||||||
this.parentAcmeAccount = parentAcmeAccount
|
|
||||||
this.keypair = helpers.createKeypair(optionsArg.bit)
|
|
||||||
let privateKeyForged = plugins.nodeForge.pki.privateKeyFromPem(this.keypair.privateKey)
|
|
||||||
let publicKeyForged = plugins.nodeForge.pki.publicKeyToPem(
|
|
||||||
plugins.nodeForge.pki.setRsaPublicKey(privateKeyForged.n, privateKeyForged.e)
|
|
||||||
)
|
|
||||||
this.keyPairFinal = {
|
|
||||||
privateKey: privateKeyForged,
|
|
||||||
publicKey: publicKeyForged
|
|
||||||
}
|
|
||||||
|
|
||||||
// set dates
|
|
||||||
this.validFrom = new Date()
|
|
||||||
this.validTo = new Date()
|
|
||||||
this.validTo.setDate(this.validFrom.getDate() + 90)
|
|
||||||
|
|
||||||
// set attributes
|
|
||||||
this.attributes = [
|
|
||||||
{ name: 'commonName', value: optionsArg.domain },
|
|
||||||
{ name: 'countryName', value: optionsArg.country },
|
|
||||||
{ shortName: 'ST', value: optionsArg.country_short },
|
|
||||||
{ name: 'localityName', value: optionsArg.locality },
|
|
||||||
{ name: 'organizationName', value: optionsArg.organization },
|
|
||||||
{ shortName: 'OU', value: optionsArg.organization_short },
|
|
||||||
{ name: 'challengePassword', value: optionsArg.password },
|
|
||||||
{ name: 'unstructuredName', value: optionsArg.unstructured }
|
|
||||||
]
|
|
||||||
|
|
||||||
// set up csr
|
|
||||||
this.csr = plugins.nodeForge.pki.createCertificationRequest()
|
|
||||||
this.csr.setSubject(this.attributes)
|
|
||||||
this.csr.setAttributes(this.attributes)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* requests a challenge for a domain
|
|
||||||
* @param domainNameArg - the domain name to request a challenge for
|
|
||||||
* @param challengeType - the challenge type to request
|
|
||||||
*/
|
|
||||||
requestChallenge(challengeTypeArg: TChallengeType = 'dns-01') {
|
|
||||||
let done = q.defer<ISmartAcmeChallengeAccepted>()
|
|
||||||
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.newAuthz(
|
|
||||||
{
|
|
||||||
identifier: {
|
|
||||||
type: 'dns',
|
|
||||||
value: this.domainName
|
|
||||||
}
|
|
||||||
},
|
|
||||||
this.parentAcmeAccount.parentSmartAcme.keyPair,
|
|
||||||
(err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('smartacme: something went wrong:')
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
}
|
|
||||||
let dnsChallenge = res.body.challenges.filter(x => {
|
|
||||||
return x.type === challengeTypeArg
|
|
||||||
})[0]
|
|
||||||
this.acceptChallenge(dnsChallenge)
|
|
||||||
.then((x: ISmartAcmeChallengeAccepted) => {
|
|
||||||
done.resolve(x)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* checks if DNS records are set
|
|
||||||
*/
|
|
||||||
async checkDns() {
|
|
||||||
let myRecord
|
|
||||||
try {
|
|
||||||
myRecord = await myDnsly.getRecord(helpers.prefixName(this.domainName), 'TXT')
|
|
||||||
} catch (err) {
|
|
||||||
await this.checkDns()
|
|
||||||
}
|
|
||||||
return myRecord[0][0]
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* validates a challenge, only call after you have set the challenge at the expected location
|
|
||||||
*/
|
|
||||||
requestValidation() {
|
|
||||||
let done = q.defer()
|
|
||||||
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.poll(this.acceptedChallenge.uri, (err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
}
|
|
||||||
console.log(`Validation response:`)
|
|
||||||
console.log(JSON.stringify(res.body))
|
|
||||||
if (res.body.status === 'pending' || 'invalid') {
|
|
||||||
setTimeout(
|
|
||||||
() => {
|
|
||||||
this.requestValidation().then(x => { done.resolve(x) })
|
|
||||||
},
|
|
||||||
2000
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
done.resolve(res.body)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* requests a certificate
|
|
||||||
*/
|
|
||||||
requestCert() {
|
|
||||||
let done = q.defer()
|
|
||||||
let payload = {
|
|
||||||
csr: plugins.rawacme.base64.encode(
|
|
||||||
plugins.rawacme.toDer(
|
|
||||||
plugins.nodeForge.pki.certificationRequestToPem(
|
|
||||||
this.csr
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
notBefore: this.validFrom.toISOString(),
|
|
||||||
notAfter: this.validTo.toISOString()
|
|
||||||
}
|
|
||||||
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.newCert(
|
|
||||||
payload,
|
|
||||||
helpers.createKeypair(),
|
|
||||||
(err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
}
|
|
||||||
console.log(res.body)
|
|
||||||
done.resolve(res.body)
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getCertificate - takes care of cooldown, validation polling and certificate retrieval
|
|
||||||
*/
|
|
||||||
getCertificate() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* accept a challenge - for private use only
|
|
||||||
*/
|
|
||||||
private acceptChallenge(challengeArg: ISmartAcmeChallenge) {
|
|
||||||
let done = q.defer()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the key is needed to accept the challenge
|
|
||||||
*/
|
|
||||||
let authKey: string = plugins.rawacme.keyAuthz(
|
|
||||||
challengeArg.token,
|
|
||||||
this.parentAcmeAccount.parentSmartAcme.keyPair.publicKey
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* needed in case selected challenge is of type dns-01
|
|
||||||
*/
|
|
||||||
let keyHash: string = plugins.rawacme.dnsKeyAuthzHash(authKey) // needed if dns challenge is chosen
|
|
||||||
|
|
||||||
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.post(
|
|
||||||
challengeArg.uri,
|
|
||||||
{
|
|
||||||
resource: 'challenge',
|
|
||||||
keyAuthorization: authKey
|
|
||||||
},
|
|
||||||
this.parentAcmeAccount.parentSmartAcme.keyPair,
|
|
||||||
(err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* the return challenge
|
|
||||||
*/
|
|
||||||
let returnDNSChallenge: ISmartAcmeChallengeAccepted = {
|
|
||||||
uri: res.body.uri,
|
|
||||||
type: res.body.type,
|
|
||||||
token: res.body.token,
|
|
||||||
keyAuthorization: res.body.keyAuthorization,
|
|
||||||
status: res.body.status,
|
|
||||||
dnsKeyHash: keyHash,
|
|
||||||
domainName: this.domainName,
|
|
||||||
domainNamePrefixed: helpers.prefixName(this.domainName)
|
|
||||||
}
|
|
||||||
this.acceptedChallenge = returnDNSChallenge
|
|
||||||
done.resolve(returnDNSChallenge)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
}
|
|
37
ts/smartacme.classes.cert.ts
Normal file
37
ts/smartacme.classes.cert.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import * as plugins from './smartacme.plugins';
|
||||||
|
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
import { CertManager } from './smartacme.classes.certmanager';
|
||||||
|
|
||||||
|
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
||||||
|
|
||||||
|
@plugins.smartdata.Collection(() => {
|
||||||
|
return CertManager.activeDB;
|
||||||
|
})
|
||||||
|
export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements interfaces.ICert {
|
||||||
|
@unI()
|
||||||
|
public index: string;
|
||||||
|
|
||||||
|
@svDb()
|
||||||
|
public domainName: string;
|
||||||
|
|
||||||
|
@svDb()
|
||||||
|
public created: number;
|
||||||
|
|
||||||
|
@svDb()
|
||||||
|
public privateKey: string;
|
||||||
|
|
||||||
|
@svDb()
|
||||||
|
public publicKey: string;
|
||||||
|
|
||||||
|
@svDb()
|
||||||
|
public csr: string;
|
||||||
|
|
||||||
|
constructor(privateKeyArg: string, publicKeyArg: string, csrArg: string) {
|
||||||
|
super();
|
||||||
|
this.privateKey = privateKeyArg;
|
||||||
|
this.publicKey = publicKeyArg;
|
||||||
|
this.csr = csrArg;
|
||||||
|
}
|
||||||
|
}
|
92
ts/smartacme.classes.certmanager.ts
Normal file
92
ts/smartacme.classes.certmanager.ts
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
import * as plugins from './smartacme.plugins';
|
||||||
|
import { Cert } from './smartacme.classes.cert';
|
||||||
|
import { SmartAcme } from './smartacme.classes.smartacme';
|
||||||
|
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
|
|
||||||
|
export class CertManager {
|
||||||
|
// =========
|
||||||
|
// STATIC
|
||||||
|
// =========
|
||||||
|
public static activeDB: plugins.smartdata.SmartdataDb;
|
||||||
|
|
||||||
|
|
||||||
|
// =========
|
||||||
|
// INSTANCE
|
||||||
|
// =========
|
||||||
|
private mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
|
public smartdataDb: plugins.smartdata.SmartdataDb;
|
||||||
|
|
||||||
|
public pendingMap: plugins.lik.Stringmap;
|
||||||
|
|
||||||
|
constructor(smartAcmeArg: SmartAcme,optionsArg: {
|
||||||
|
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
|
}) {
|
||||||
|
this.mongoDescriptor = optionsArg.mongoDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async init () {
|
||||||
|
// Smartdata DB
|
||||||
|
this.smartdataDb = new plugins.smartdata.SmartdataDb(this.mongoDescriptor);
|
||||||
|
await this.smartdataDb.init();
|
||||||
|
CertManager.activeDB = this.smartdataDb;
|
||||||
|
|
||||||
|
// Pending Map
|
||||||
|
this.pendingMap = new plugins.lik.Stringmap();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieves a certificate
|
||||||
|
* @returns the Cert class or null
|
||||||
|
* @param domainName the domain Name to retrieve the vcertificate for
|
||||||
|
*/
|
||||||
|
public async retrieveCertificate(domainName: string): Promise<Cert> {
|
||||||
|
await this.checkCerts();
|
||||||
|
const existingCertificate: Cert = await Cert.getInstance({
|
||||||
|
name: domainName
|
||||||
|
});
|
||||||
|
|
||||||
|
if(existingCertificate) {
|
||||||
|
return existingCertificate;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stores the certificate with the
|
||||||
|
* @param publicKeyArg
|
||||||
|
* @param privateKeyArg
|
||||||
|
* @param csrArg
|
||||||
|
*/
|
||||||
|
public async storeCertificate(privateKeyArg: string, publicKeyArg: string, csrArg: string) {
|
||||||
|
const cert = new Cert(privateKeyArg, publicKeyArg, csrArg);
|
||||||
|
cert.save();
|
||||||
|
};
|
||||||
|
|
||||||
|
public async deleteCertificate(domainNameArg: string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getCertificateStatus(domainNameArg: string): Promise<interfaces.TCertStatus> {
|
||||||
|
const isPending = this.pendingMap.checkString('domainNameArg');
|
||||||
|
if (isPending) {
|
||||||
|
return 'pending';
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise lets continue
|
||||||
|
const existingCertificate = this.retrieveCertificate(domainNameArg);
|
||||||
|
if (existingCertificate) {
|
||||||
|
return 'existing';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'nonexisting';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks all certs for expiration
|
||||||
|
*/
|
||||||
|
private async checkCerts() {};
|
||||||
|
}
|
47
ts/smartacme.classes.certremoteclient.ts
Normal file
47
ts/smartacme.classes.certremoteclient.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import * as plugins from './smartacme.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
import { ICertRemoteResponse } from './interfaces';
|
||||||
|
|
||||||
|
// tslint:disable-next-line: max-classes-per-file
|
||||||
|
export class CertRemoteClient {
|
||||||
|
private remoteUrl: string;
|
||||||
|
private secret: string;
|
||||||
|
|
||||||
|
constructor(optionsArg: {
|
||||||
|
remoteUrl: string;
|
||||||
|
secret: string;
|
||||||
|
}) {
|
||||||
|
this.remoteUrl = optionsArg.remoteUrl;
|
||||||
|
this.secret = optionsArg.secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param domainNameArg
|
||||||
|
*/
|
||||||
|
async getCertificateForDomain(domainNameArg: string): Promise<interfaces.ICert> {
|
||||||
|
let certificate: interfaces.ICert;
|
||||||
|
const doRequestCycle = async (): Promise<interfaces.ICert> => {
|
||||||
|
const response: ICertRemoteResponse = (await plugins.smartrequest.postJson(this.remoteUrl, {
|
||||||
|
requestBody: <interfaces.ICertRemoteRequest>{
|
||||||
|
domainName: domainNameArg,
|
||||||
|
secret: this.secret
|
||||||
|
}
|
||||||
|
})).body;
|
||||||
|
switch(response.status) {
|
||||||
|
case 'pending':
|
||||||
|
await plugins.smartdelay.delayFor(5000);
|
||||||
|
const finalResponse = await doRequestCycle();
|
||||||
|
return finalResponse;
|
||||||
|
case 'existing':
|
||||||
|
return response.certificate;
|
||||||
|
case 'failed':
|
||||||
|
default:
|
||||||
|
console.log(`could not retrieve certificate for ${domainNameArg}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
certificate = await doRequestCycle();
|
||||||
|
return certificate;
|
||||||
|
}
|
||||||
|
}
|
@ -1,82 +1,167 @@
|
|||||||
// third party modules
|
import * as plugins from './smartacme.plugins';
|
||||||
import * as q from 'q' // promises
|
import { CertManager } from './smartacme.classes.certmanager';
|
||||||
import * as plugins from './smartacme.plugins'
|
|
||||||
import * as helpers from './smartacme.helpers'
|
|
||||||
|
|
||||||
import { AcmeAccount } from './smartacme.classes.acmeaccount'
|
import * as interfaces from './interfaces';
|
||||||
|
import { request } from 'http';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a rsa keypair needed for account creation and subsequent requests
|
*
|
||||||
*/
|
*/
|
||||||
export interface IRsaKeypair {
|
export interface ISmartAcmeOptions {
|
||||||
publicKey: string
|
accountPrivateKey?: string;
|
||||||
privateKey: string
|
accountEmail: string;
|
||||||
|
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
|
||||||
|
setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
||||||
|
removeChallenge: (domainName: string) => Promise<any>;
|
||||||
|
validateRemoteRequest: () => Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { AcmeAccount } from './smartacme.classes.acmeaccount'
|
|
||||||
export { AcmeCert, ISmartAcmeChallenge, ISmartAcmeChallengeAccepted } from './smartacme.classes.acmecert'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class SmartAcme exports methods for maintaining SSL Certificates
|
|
||||||
*/
|
|
||||||
export class SmartAcme {
|
export class SmartAcme {
|
||||||
acmeUrl: string // the acme url to use for this instance
|
private options: ISmartAcmeOptions;
|
||||||
productionBool: boolean // a boolean to quickly know wether we are in production or not
|
|
||||||
keyPair: IRsaKeypair // the keyPair needed for account creation
|
|
||||||
rawacmeClient
|
|
||||||
|
|
||||||
/**
|
// the acme client
|
||||||
* the constructor for class SmartAcme
|
private client: any;
|
||||||
*/
|
private smartdns = new plugins.smartdns.Smartdns();
|
||||||
constructor(productionArg: boolean = false) {
|
|
||||||
this.productionBool = productionArg
|
// the account private key
|
||||||
this.keyPair = helpers.createKeypair()
|
private privateKey: string;
|
||||||
if (this.productionBool) {
|
|
||||||
this.acmeUrl = plugins.rawacme.LETSENCRYPT_URL
|
// challenge fullfillment
|
||||||
} else {
|
private setChallenge: (domainName: string, keyAuthorization: string) => Promise<any>;
|
||||||
this.acmeUrl = plugins.rawacme.LETSENCRYPT_STAGING_URL
|
private removeChallenge: (domainName: string) => Promise<any>;
|
||||||
}
|
private validateRemoteRequest: () => Promise<boolean>;
|
||||||
|
|
||||||
|
// certmanager
|
||||||
|
private certmanager: CertManager;
|
||||||
|
private certremoteHandler: plugins.smartexpress.Handler;
|
||||||
|
|
||||||
|
constructor(optionsArg: ISmartAcmeOptions) {
|
||||||
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init the smartacme instance
|
* inits the instance
|
||||||
*/
|
*/
|
||||||
init() {
|
public async init() {
|
||||||
let done = q.defer()
|
this.privateKey =
|
||||||
plugins.rawacme.createClient(
|
this.options.accountPrivateKey || (await plugins.acme.forge.createPrivateKey());
|
||||||
{
|
this.setChallenge = this.options.setChallenge;
|
||||||
url: this.acmeUrl,
|
this.removeChallenge = this.options.removeChallenge;
|
||||||
publicKey: this.keyPair.publicKey,
|
|
||||||
privateKey: this.keyPair.privateKey
|
// CertMangaer
|
||||||
},
|
this.certmanager = new CertManager(this, {
|
||||||
(err, client) => {
|
mongoDescriptor: this.options.mongoDescriptor
|
||||||
if (err) {
|
});
|
||||||
console.error('smartacme: something went wrong:')
|
await this.certmanager.init();
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
// CertRemoteHandler
|
||||||
return
|
this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => {
|
||||||
|
const requestBody: interfaces.ICertRemoteRequest = req.body;
|
||||||
|
const status: interfaces.TCertStatus = await this.certmanager.getCertificateStatus(requestBody.domainName);
|
||||||
|
const existingCertificate = await this.certmanager.retrieveCertificate(
|
||||||
|
requestBody.domainName
|
||||||
|
);
|
||||||
|
let response: interfaces.ICertRemoteResponse;
|
||||||
|
switch (status) {
|
||||||
|
case 'existing':
|
||||||
|
response = {
|
||||||
|
status,
|
||||||
|
certificate: {
|
||||||
|
created: existingCertificate.created,
|
||||||
|
csr: existingCertificate.csr,
|
||||||
|
domainName: existingCertificate.domainName,
|
||||||
|
privateKey: existingCertificate.privateKey,
|
||||||
|
publicKey: existingCertificate.publicKey
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
response = {
|
||||||
|
status
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
res.status(200);
|
||||||
|
res.send(response);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
// ACME Client
|
||||||
|
this.client = new plugins.acme.Client({
|
||||||
|
directoryUrl: plugins.acme.directory.letsencrypt.staging,
|
||||||
|
accountKey: this.privateKey
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Register account */
|
||||||
|
await this.client.createAccount({
|
||||||
|
termsOfServiceAgreed: true,
|
||||||
|
contact: [`mailto:${this.options.accountEmail}`]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// make client available in class
|
public async getCertificateForDomain(domainArg: string) {
|
||||||
this.rawacmeClient = client
|
const domain = domainArg;
|
||||||
done.resolve()
|
|
||||||
}
|
const retrievedCertificate = await this.certmanager.retrieveCertificate(domain);
|
||||||
)
|
|
||||||
return done.promise
|
if (retrievedCertificate) {
|
||||||
|
return retrievedCertificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Place new order */
|
||||||
* creates an account if not currently present in module
|
const order = await this.client.createOrder({
|
||||||
* @executes ASYNC
|
identifiers: [{ type: 'dns', value: domain }, { type: 'dns', value: `*.${domain}` }]
|
||||||
*/
|
});
|
||||||
createAccount() {
|
|
||||||
let done = q.defer<AcmeAccount>()
|
/* Get authorizations and select challenges */
|
||||||
let acmeAccount = new AcmeAccount(this)
|
const authorizations = await this.client.getAuthorizations(order);
|
||||||
acmeAccount.register().then(() => {
|
|
||||||
return acmeAccount.agreeTos()
|
for (const authz of authorizations) {
|
||||||
}).then(() => {
|
console.log(authz);
|
||||||
done.resolve(acmeAccount)
|
const domainDnsName: string = `_acme-challenge.${authz.identifier.value}`;
|
||||||
})
|
const dnsChallenge: string = authz.challenges.find(challengeArg => {
|
||||||
return done.promise
|
return challengeArg.type === 'dns-01';
|
||||||
|
});
|
||||||
|
// process.exit(1);
|
||||||
|
const keyAuthorization: string = await this.client.getChallengeKeyAuthorization(dnsChallenge);
|
||||||
|
|
||||||
|
try {
|
||||||
|
/* Satisfy challenge */
|
||||||
|
await this.setChallenge(domainDnsName, keyAuthorization);
|
||||||
|
await this.smartdns.checkUntilAvailable(domainDnsName, 'TXT', keyAuthorization, 100, 5000);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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()}`);
|
||||||
|
|
||||||
|
this.certmanager.storeCertificate(key.toString(), cert.toString(), csr.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
import 'typings-global'
|
|
||||||
import * as q from 'q'
|
|
||||||
|
|
||||||
import * as plugins from './smartacme.plugins'
|
|
||||||
|
|
||||||
import { SmartAcme, IRsaKeypair } from './smartacme.classes.smartacme'
|
|
||||||
import { AcmeAccount } from './smartacme.classes.acmeaccount'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates a keypair to use with requests and to generate JWK from
|
|
||||||
*/
|
|
||||||
export let createKeypair = (bit = 2048): IRsaKeypair => {
|
|
||||||
let result = plugins.rsaKeygen.generate(bit)
|
|
||||||
return {
|
|
||||||
publicKey: result.public_key,
|
|
||||||
privateKey: result.private_key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* prefix a domain name to make sure it complies with letsencrypt
|
|
||||||
*/
|
|
||||||
export let prefixName = (domainNameArg: string): string => {
|
|
||||||
return '_acme-challenge.' + domainNameArg
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets an existing registration
|
|
||||||
* @executes ASYNC
|
|
||||||
*/
|
|
||||||
let getReg = (SmartAcmeArg: SmartAcme, location: string) => {
|
|
||||||
let done = q.defer()
|
|
||||||
let body = { resource: 'reg' }
|
|
||||||
SmartAcmeArg.rawacmeClient.post(
|
|
||||||
location,
|
|
||||||
body,
|
|
||||||
SmartAcmeArg.keyPair,
|
|
||||||
(err, res) => {
|
|
||||||
if (err) {
|
|
||||||
console.error('smartacme: something went wrong:')
|
|
||||||
console.log(err)
|
|
||||||
done.reject(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
console.log(JSON.stringify(res.body))
|
|
||||||
done.resolve()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return done.promise
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
import * as path from 'path'
|
|
||||||
import * as smartfile from 'smartfile'
|
|
||||||
|
|
||||||
export let packageDir = path.join(__dirname,'../')
|
|
||||||
export let assetDir = path.join(packageDir,'assets/')
|
|
||||||
smartfile.fs.ensureDirSync(assetDir)
|
|
@ -1,20 +1,17 @@
|
|||||||
import 'typings-global' // typings for node
|
// @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 smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
import * as smartunique from '@pushrocks/smartunique';
|
||||||
|
import * as smarttime from '@pushrocks/smarttime';
|
||||||
|
|
||||||
import * as path from 'path' // native node path module
|
export { lik, smartdata, smartdelay, smartdns, smartexpress, smartpromise, smartrequest, smartunique, smarttime };
|
||||||
let rsaKeygen = require('rsa-keygen') // rsa keygen
|
|
||||||
let rawacme = require('rawacme') // acme helper functions
|
|
||||||
let nodeForge = require('node-forge')
|
|
||||||
|
|
||||||
// push.rocks modules here
|
// thirs party scope
|
||||||
import * as dnsly from 'dnsly'
|
import * as acme from 'acme-client';
|
||||||
import * as smartfile from 'smartfile'
|
|
||||||
import * as smartstring from 'smartstring'
|
|
||||||
|
|
||||||
export {
|
export { acme };
|
||||||
dnsly,
|
|
||||||
rsaKeygen,
|
|
||||||
rawacme,
|
|
||||||
nodeForge,
|
|
||||||
smartfile,
|
|
||||||
smartstring
|
|
||||||
}
|
|
||||||
|
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"target": "es2017",
|
||||||
|
"module": "commonjs"
|
||||||
|
}
|
||||||
|
}
|
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