Compare commits

..

29 Commits

Author SHA1 Message Date
a9efae65d6 1.0.10 2017-04-28 18:59:45 +02:00
0f09bdaf9f update to latest standards 2017-04-28 18:59:43 +02:00
84177cd575 update 2017-04-28 18:56:55 +02:00
7d16ada760 1.0.9 2017-01-27 01:09:48 +01:00
b4de8cc2be basic functionality 2017-01-27 01:09:38 +01:00
68e570c32a 1.0.8 2017-01-25 02:45:52 +01:00
20ea599f9d now getting a valid response 2017-01-25 02:45:48 +01:00
5fa530456b update validation 2017-01-22 21:50:04 +01:00
2cd1794e7e improve README 2017-01-15 23:19:48 +01:00
1f38e12bd3 1.0.7 2017-01-15 23:11:54 +01:00
1c777f6f05 improve README 2017-01-15 23:11:51 +01:00
aad113a8ea add async checkDNS 2017-01-15 22:59:58 +01:00
fff63839d1 1.0.6 2017-01-15 22:30:43 +01:00
c8d2cfd4ce update to new standards 2017-01-15 22:30:33 +01:00
dfd7edd330 now has working requestValidation method 2017-01-15 13:33:55 +01:00
4dadcf227c fix som things 2017-01-15 12:21:29 +01:00
fce25c60ed start better segregation of concerns 2017-01-14 18:36:33 +01:00
98cc70dbfb start with certificate signing process 2017-01-14 14:14:50 +01:00
89d628bd37 1.0.5 2017-01-02 00:18:57 +01:00
0056c8508c now getting certificates 2017-01-02 00:18:51 +01:00
96e0c4f905 can now agree to TOS 2017-01-01 21:20:12 +01:00
2f844dd78d remove test keys 2017-01-01 18:15:48 +01:00
ab82ac0c83 1.0.4 2017-01-01 18:09:48 +01:00
5b925e3d1b add npmextra.json 2017-01-01 18:09:45 +01:00
3c862158f3 1.0.3 2017-01-01 18:07:17 +01:00
e226bb7c4a add better readme 2017-01-01 18:07:09 +01:00
66407cb214 switch to rawacme for more basic letsencrypt access 2017-01-01 18:05:26 +01:00
f5e7bab12d 1.0.2 2016-11-17 13:36:49 +01:00
69b4e85218 fix promise 2016-11-17 13:36:43 +01:00
30 changed files with 2270 additions and 318 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ node_modules/
coverage/ coverage/
public/ public/
pages/ pages/
.nogit/

4
.npmignore Normal file
View File

@ -0,0 +1,4 @@
node_modules/
coverage/
public/
pages/

View File

@ -1,19 +1,29 @@
# smartacme # smartacme
acme implementation in TypeScript
## Availabililty ## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartacme) [![npm](https://umbrellazone.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartacme)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartacme) [![git](https://umbrellazone.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/umbrellazone/smartacme)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartacme) [![git](https://umbrellazone.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/umbrellazone/smartacme)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartacme/) [![docs](https://umbrellazone.gitlab.io/assets/repo-button-docs.svg)](https://umbrellazone.gitlab.io/smartacme/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/smartacme/badges/master/build.svg)](https://gitlab.com/pushrocks/smartacme/commits/master) [![build status](https://GitLab.com/umbrellazone/smartacme/badges/master/build.svg)](https://GitLab.com/umbrellazone/smartacme/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartacme/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartacme/commits/master) [![coverage report](https://GitLab.com/umbrellazone/smartacme/badges/master/coverage.svg)](https://GitLab.com/umbrellazone/smartacme/commits/master)
[![Dependency Status](https://david-dm.org/pushrocks/smartacme.svg)](https://david-dm.org/pushrocks/smartacme) [![npm downloads per month](https://img.shields.io/npm/dm/smartacme.svg)](https://www.npmjs.com/package/smartacme)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartacme/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartacme/master/dependencies/npm) [![Dependency Status](https://david-dm.org/umbrellazone/smartacme.svg)](https://david-dm.org/umbrellazone/smartacme)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartacme/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartacme) [![bitHound Dependencies](https://www.bithound.io/github/umbrellazone/smartacme/badges/dependencies.svg)](https://www.bithound.io/github/umbrellazone/smartacme/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/umbrellazone/smartacme/badges/code.svg)](https://www.bithound.io/github/umbrellazone/smartacme)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) [![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) [![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks) ## Usage
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://umbrellazone.gitlab.io/assets/repo-footer.svg)](https://umbrella.zone)

View File

@ -1,27 +0,0 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAyocFq3vvbiRNCsEcXtsqimIi6UM1OmxiYVQ0NoLvBtpaWk+E
TvNIjmUgh5QQaQfRyRGoWvhskp+E8p6go4GsbRtzx0TvL8uINTcC3SHHo6Qvl599
4QUUPUrioHdh+lX1oj+zIPVUOaL4dl0US1Ebs5vrZVbCfNXSm86vBaPIj6IkWEkj
4S5xGsYlVaQU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x7cA1yt39Mz+f8nUQP9yiP
C54sjh2JpKZ4CnDTXqN9uPO+L79ueBsPrE/9wAQ6q3ilfXFvBkrWJ8pdd0iuHN6F
PPBwb50tGc+BGhcUUlBzGekxxxllTx/ZgrnlnRQu3XENwmp8zRQwEaUjFq+SdFyZ
qJwap5ECgYEA7UGxxRXAjfStTLnsrnr9svvr3QhwnZBg5JAjeR6FKC0cGFzdBrJ5
rV/Zy4mGbTBBVh5oU3MplB3AUHejuFv+8eCik2mJug8k3G8KQAk9mB8oV97k0cp+
bdlu9vlutIoCG9RXxCHdgRVLiLK+OkLv6p7hQOIY7fsIRaAuI+vPKSk=
-----END RSA PRIVATE KEY-----

View File

@ -1,9 +0,0 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyocFq3vvbiRNCsEcXtsq
imIi6UM1OmxiYVQ0NoLvBtpaWk+ETvNIjmUgh5QQaQfRyRGoWvhskp+E8p6go4Gs
bRtzx0TvL8uINTcC3SHHo6Qvl5994QUUPUrioHdh+lX1oj+zIPVUOaL4dl0US1Eb
s5vrZVbCfNXSm86vBaPIj6IkWEkj4S5xGsYlVaQUI8Tvv2fbPziIivbkxS1v/EEM
nfk6i5PWgCsnMupYxz58WaVp9xyu+v/DMPB09mqo4DzchtUNF/b5eOWh3pDJoewY
yRVMDDPJoQiTKkJn3kt64EaQuZK2nUXcihlmaKIx5ayxirsgfvIvxidHnkQcluvc
iQIDAQAB
-----END PUBLIC KEY-----

3
dist/index.js vendored
View File

@ -2,5 +2,6 @@
function __export(m) { function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
} }
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./smartacme.classes.smartacme")); __export(require("./smartacme.classes.smartacme"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsbURBQTZDIn0= //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE2QyJ9

21
dist/smartacme.classes.acmeaccount.d.ts vendored Normal file
View File

@ -0,0 +1,21 @@
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(): Promise<{}>;
/**
* agree to letsencrypr terms of service
*/
agreeTos(): Promise<{}>;
createAcmeCert(domainNameArg: string, countryArg?: string, countryShortArg?: string, city?: string, companyArg?: string, companyShortArg?: string): Promise<AcmeCert>;
}

72
dist/smartacme.classes.acmeaccount.js vendored Normal file
View File

@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const q = require("smartq");
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuYWNtZWFjY291bnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUuY2xhc3Nlcy5hY21lYWNjb3VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDRCQUEyQjtBQU0zQiw2RUFBdUQ7QUFFdkQ7O0dBRUc7QUFDSDtJQUtFLFlBQVksa0JBQTZCO1FBQ3ZDLElBQUksQ0FBQyxlQUFlLEdBQUcsa0JBQWtCLENBQUE7SUFDM0MsQ0FBQztJQUVEOztPQUVHO0lBQ0gsUUFBUTtRQUNOLElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUNwQixJQUFJLENBQUMsZUFBZSxDQUFDLGFBQWEsQ0FBQyxNQUFNLENBQ3ZDO1lBQ0UsT0FBTyxFQUFFLENBQUUsNkJBQTZCLENBQUU7U0FDM0MsRUFDRCxDQUFDLEdBQUcsRUFBRSxHQUF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UUFBUSxFQUFFLElBQUk7WUFDZCxZQUFZLEVBQUUsVUFBVTtZQUN4QixrQkFBa0IsRUFBRSxlQUFlO1lBQ25DLFFBQVEsRUFBRSxJQUFJO1lBQ2QsWUFBWSxFQUFFLElBQUk7WUFDbEIsaUJBQWlCLEVBQUUsSUFBSTtTQUN4QixFQUNELElBQUksQ0FDTCxDQUFBO1FBQ0QsSUFBSSxDQUFDLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQTtRQUN0QixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUNyQixDQUFDO0NBQ0Y7QUFsRkQsa0NBa0ZDIn0=

78
dist/smartacme.classes.acmecert.d.ts vendored Normal file
View File

@ -0,0 +1,78 @@
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 ISmartAcmeChallengeChosen 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;
fullchain: string;
parentAcmeAccount: AcmeAccount;
csr: any;
validFrom: Date;
validTo: Date;
keypair: IRsaKeypair;
keyPairFinal: IRsaKeypair;
chosenChallenge: ISmartAcmeChallengeChosen;
dnsKeyHash: string;
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): Promise<ISmartAcmeChallengeChosen>;
/**
* checks if DNS records are set, will go through a max of 30 cycles
*/
checkDns(cycleArg?: number): Promise<void>;
/**
* validates a challenge, only call after you have set the challenge at the expected location
*/
requestValidation(): Promise<void>;
/**
* requests a certificate
*/
requestCert(): Promise<{}>;
/**
* getCertificate - takes care of cooldown, validation polling and certificate retrieval
*/
getCertificate(): void;
/**
* accept a challenge - for private use only
*/
acceptChallenge(): Promise<{}>;
}

183
dist/smartacme.classes.acmecert.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,29 +1,32 @@
/// <reference types="q" /> import { AcmeAccount } from './smartacme.classes.acmeaccount';
import 'typings-global'; /**
import * as q from 'q'; * 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, ISmartAcmeChallengeChosen } from './smartacme.classes.acmecert';
/** /**
* class SmartAcme exports methods for maintaining SSL Certificates * class SmartAcme exports methods for maintaining SSL Certificates
*/ */
export declare class SmartAcme { export declare class SmartAcme {
preparedBool: boolean; acmeUrl: string;
acmeUrls: any;
productionBool: boolean; productionBool: boolean;
keyPair: any; keyPair: IRsaKeypair;
rawacmeClient: any;
/**
* the constructor for class SmartAcme
*/
constructor(productionArg?: boolean); constructor(productionArg?: boolean);
/** /**
* prepares the SmartAcme class * init the smartacme instance
*/ */
prepareAcme(): q.Promise<{}>; init(): Promise<{}>;
/** /**
* creates an account if not currently present in module * creates an account if not currently present in module
* @executes ASYNC
*/ */
createAccount(): q.Promise<{}>; createAcmeAccount(): Promise<AcmeAccount>;
/**
* creates a keyPair
*/
createKeyPair(): q.Promise<{}>;
/**
* gets the Acme Urls
*/
getAcmeUrls(): q.Promise<{}>;
} }

View File

@ -1,101 +1,67 @@
"use strict"; "use strict";
require("typings-global"); Object.defineProperty(exports, "__esModule", { value: true });
const q = require("q"); // third party modules
let ACME = require('le-acme-core').ACME.create(); const q = require("smartq"); // promises
let RSA = require('rsa-compat').RSA; const plugins = require("./smartacme.plugins");
let bitlen = 1024; const helpers = require("./smartacme.helpers");
let exp = 65537; const smartacme_classes_acmeaccount_1 = require("./smartacme.classes.acmeaccount");
let options = { var smartacme_classes_acmeaccount_2 = require("./smartacme.classes.acmeaccount");
public: true, exports.AcmeAccount = smartacme_classes_acmeaccount_2.AcmeAccount;
pem: true, var smartacme_classes_acmecert_1 = require("./smartacme.classes.acmecert");
internal: true exports.AcmeCert = smartacme_classes_acmecert_1.AcmeCert;
};
/** /**
* class SmartAcme exports methods for maintaining SSL Certificates * class SmartAcme exports methods for maintaining SSL Certificates
*/ */
class SmartAcme { class SmartAcme {
constructor(productionArg = false) {
this.preparedBool = false;
this.productionBool = productionArg;
}
/** /**
* prepares the SmartAcme class * the constructor for class SmartAcme
*/ */
prepareAcme() { constructor(productionArg = false) {
let done = q.defer(); this.productionBool = productionArg;
if (this.preparedBool === false) { this.keyPair = helpers.createKeypair();
this.getAcmeUrls() if (this.productionBool) {
.then(() => { this.acmeUrl = plugins.rawacme.LETSENCRYPT_URL;
return this.createKeyPair();
})
.then((x) => {
console.log('prepared smartacme instance');
done.resolve();
});
} }
else { else {
done.resolve(); 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; return done.promise;
} }
/** /**
* creates an account if not currently present in module * creates an account if not currently present in module
* @executes ASYNC
*/ */
createAccount() { createAcmeAccount() {
let done = q.defer(); let done = q.defer();
this.prepareAcme() let acmeAccount = new smartacme_classes_acmeaccount_1.AcmeAccount(this);
.then(() => { acmeAccount.register().then(() => {
let options = { return acmeAccount.agreeTos();
newRegUrl: this.acmeUrls.newReg, }).then(() => {
email: 'domains@lossless.org', done.resolve(acmeAccount);
accountKeypair: {
privateKeyPem: this.keyPair
},
agreeToTerms: function (tosUrl, done) {
done(null, tosUrl);
}
};
ACME.registerNewAccount(options, (err, regr) => {
if (err) {
console.log(err);
done.reject(err);
}
done.resolve(regr);
});
}).catch(err => { console.log(err); });
return done.promise;
}
/**
* creates a keyPair
*/
createKeyPair() {
let done = q.defer();
RSA.generateKeypair(bitlen, exp, options, (err, keypair) => {
if (err) {
console.log(err);
done.reject(err);
}
console.log(keypair);
this.keyPair = keypair;
});
done.resolve();
return done.promise;
}
/**
* gets the Acme Urls
*/
getAcmeUrls() {
let done = q.defer();
ACME.getAcmeUrls(ACME.stagingServerUrl, (err, urls) => {
if (err) {
throw err;
}
this.acmeUrls = urls;
console.log(this.acmeUrls);
done.resolve();
}); });
return done.promise; return done.promise;
} }
} }
exports.SmartAcme = SmartAcme; exports.SmartAcme = SmartAcme;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFDdkIsdUJBQXNCO0FBTXRCLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0FBQyxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUE7QUFDaEQsSUFBSSxHQUFHLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFDLEdBQUcsQ0FBQTtBQUVuQyxJQUFJLE1BQU0sR0FBRyxJQUFJLENBQUE7QUFDakIsSUFBSSxHQUFHLEdBQUcsS0FBSyxDQUFBO0FBQ2YsSUFBS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';
/**
* 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;

41
dist/smartacme.helpers.js vendored Normal file
View File

@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
const q = require("smartq");
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qiw0QkFBMkI7QUFFM0IsK0NBQThDO0FBSzlDOztHQUVHO0FBQ1EsUUFBQSxhQUFhLEdBQUcsQ0FBQyxHQUFHLEdBQUcsSUFBSTtJQUNwQyxJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLFFBQVEsQ0FBQyxHQUFHLENBQUMsQ0FBQTtJQUM1QyxNQUFNLENBQUM7UUFDTCxTQUFTLEVBQUUsTUFBTSxDQUFDLFVBQVU7UUFD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

@ -1,7 +1,8 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path"); const path = require("path");
const smartfile = require("smartfile"); const smartfile = require("smartfile");
exports.packageDir = path.join(__dirname, '../'); exports.packageDir = path.join(__dirname, '../');
exports.assetDir = path.join(exports.packageDir, 'assets/'); exports.assetDir = path.join(exports.packageDir, 'assets/');
smartfile.fs.ensureDirSync(exports.assetDir); smartfile.fs.ensureDirSync(exports.assetDir);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw2QkFBNEI7QUFDNUIsdUNBQXNDO0FBRTNCLFFBQUEsVUFBVSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFBO0FBQ3ZDLFFBQUEsUUFBUSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsa0JBQVUsRUFBQyxTQUFTLENBQUMsQ0FBQTtBQUNyRCxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyxnQkFBUSxDQUFDLENBQUEifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsNkJBQTRCO0FBQzVCLHVDQUFzQztBQUUzQixRQUFBLFVBQVUsR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxLQUFLLENBQUMsQ0FBQTtBQUN2QyxRQUFBLFFBQVEsR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLGtCQUFVLEVBQUMsU0FBUyxDQUFDLENBQUE7QUFDckQsU0FBUyxDQUFDLEVBQUUsQ0FBQyxhQUFhLENBQUMsZ0JBQVEsQ0FBQyxDQUFBIn0=

9
dist/smartacme.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import 'typings-global';
declare let rsaKeygen: any;
declare let rawacme: any;
declare let nodeForge: any;
import * as dnsly from 'dnsly';
import * as smartdelay from 'smartdelay';
import * as smartfile from 'smartfile';
import * as smartstring from 'smartstring';
export { dnsly, rsaKeygen, rawacme, nodeForge, smartdelay, smartfile, smartstring };

19
dist/smartacme.plugins.js vendored Normal file
View File

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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 smartdelay = require("smartdelay");
exports.smartdelay = smartdelay;
const smartfile = require("smartfile");
exports.smartfile = smartfile;
const smartstring = require("smartstring");
exports.smartstring = smartstring;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QixDQUFDLG1CQUFtQjtBQUczQyxJQUFJLFNBQVMsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUEsQ0FBQyxhQUFhO0FBWWpELDhCQUFTO0FBWFgsSUFBSSxPQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFBLENBQUMsd0JBQXdCO0FBWXZELDBCQUFPO0FBWFQsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFBO0FBWW5DLDhCQUFTO0FBVlgsMEJBQTBCO0FBQzFCLCtCQUE4QjtBQU01QixzQkFBSztBQUxQLHlDQUF3QztBQVN0QyxnQ0FBVTtBQVJaLHVDQUFzQztBQVNwQyw4QkFBUztBQVJYLDJDQUEwQztBQVN4QyxrQ0FBVyJ9

59
docs/index.md Normal file
View File

@ -0,0 +1,59 @@
# smartacme
acme implementation in TypeScript
## Availabililty
[![npm](https://umbrellazone.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartacme)
[![git](https://umbrellazone.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/umbrellazone/smartacme)
[![git](https://umbrellazone.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/umbrellazone/smartacme)
[![docs](https://umbrellazone.gitlab.io/assets/repo-button-docs.svg)](https://umbrellazone.gitlab.io/smartacme/)
## Status for master
[![build status](https://GitLab.com/umbrellazone/smartacme/badges/master/build.svg)](https://GitLab.com/umbrellazone/smartacme/commits/master)
[![coverage report](https://GitLab.com/umbrellazone/smartacme/badges/master/coverage.svg)](https://GitLab.com/umbrellazone/smartacme/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartacme.svg)](https://www.npmjs.com/package/smartacme)
[![Dependency Status](https://david-dm.org/umbrellazone/smartacme.svg)](https://david-dm.org/umbrellazone/smartacme)
[![bitHound Dependencies](https://www.bithound.io/github/umbrellazone/smartacme/badges/dependencies.svg)](https://www.bithound.io/github/umbrellazone/smartacme/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/umbrellazone/smartacme/badges/code.svg)](https://www.bithound.io/github/umbrellazone/smartacme)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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 | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://umbrellazone.gitlab.io/assets/repo-footer.svg)](https://umbrella.zone

7
npmextra.json Normal file
View File

@ -0,0 +1,7 @@
{
"npmci": {
"globalNpmTools": [
"npmts"
]
}
}

View File

@ -1,6 +1,6 @@
{ {
"name": "smartacme", "name": "smartacme",
"version": "1.0.1", "version": "1.0.10",
"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",
@ -9,7 +9,7 @@
}, },
"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,21 +19,24 @@
"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/q": "0.x.x", "@types/node-forge": "^0.6.8",
"le-acme-core": "^2.0.7", "dnsly": "^2.0.4",
"q": "^1.4.1", "node-forge": "^0.7.1",
"rsa-compat": "^1.2.7", "rawacme": "^0.2.1",
"smartfile": "^4.1.0", "rsa-keygen": "^1.0.6",
"smartstring": "^2.0.20", "smartdelay": "^1.0.1",
"typings-global": "^1.0.14" "smartfile": "^4.1.10",
"smartq": "^1.1.1",
"smartstring": "^2.0.24",
"typings-global": "^1.0.16"
}, },
"devDependencies": { "devDependencies": {
"@types/should": "^8.1.30", "cflare": "0.0.19",
"should": "^11.1.1", "qenv": "^1.1.3",
"typings-test": "^1.0.3" "tapbundle": "^1.0.10"
} }
} }

3
qenv.yml Normal file
View File

@ -0,0 +1,3 @@
vars:
- CF_EMAIL
- CF_KEY

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import 'typings-test';

View File

@ -1,31 +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 testAcme;
it('should create a valid instance', function () {
this.timeout(10000);
testAcme = new smartacme.SmartAcme();
should(testAcme).be.instanceOf(smartacme.SmartAcme);
});
it('should get the ACME urls', function (done) {
testAcme.getAcmeUrls().then(() => { done(); });
});
it('should prepare the Instance', function (done) {
testAcme.prepareAcme().then(done);
});
it('should have created keyPair', function () {
});
it('should register a new account', function (done) {
testAcme.createAccount().then(x => {
console.log(x);
done();
}).catch(err => {
console.log(err);
done(err);
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQ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FDLEtBQUssQ0FBQyxHQUFHO1lBQ1IsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQTtZQUNoQixJQUFJLENBQUMsR0FBRyxDQUFDLENBQUE7UUFDYixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

View File

@ -1,34 +1,90 @@
import 'typings-test' import { expect, tap } from 'tapbundle'
import * as should from 'should' import * as cflare from 'cflare'
import * as qenv from 'qenv'
let testQenv = new qenv.Qenv(process.cwd(), process.cwd() + '/.nogit')
// import the module to test // import the module to test
import * as smartacme from '../dist/index' import * as smartacme from '../dist/index'
describe('smartacme', function () { let myCflareAccount = new cflare.CflareAccount()
let testAcme: smartacme.SmartAcme myCflareAccount.auth({
it('should create a valid instance', function () { email: process.env.CF_EMAIL,
this.timeout(10000) key: process.env.CF_KEY
testAcme = new smartacme.SmartAcme()
should(testAcme).be.instanceOf(smartacme.SmartAcme)
})
it('should get the ACME urls', function (done) {
testAcme.getAcmeUrls().then(() => { done() })
})
it('should prepare the Instance', function (done) {
testAcme.prepareAcme().then(done)
})
it('should have created keyPair', function () {
})
it('should register a new account', function (done) {
testAcme.createAccount().then(x => {
console.log(x)
done()
}).catch(err => {
console.log(err)
done(err)
})
})
}) })
let testSmartAcme: smartacme.SmartAcme
let testAcmeAccount: smartacme.AcmeAccount
let testAcmeCert: smartacme.AcmeCert
let testChallenge: smartacme.ISmartAcmeChallengeChosen
tap.test('smartacme -> should create a valid instance', async (tools) => {
tools.timeout(10000)
testSmartAcme = new smartacme.SmartAcme(false)
await testSmartAcme.init().then(async () => {
expect(testSmartAcme).to.be.instanceOf(smartacme.SmartAcme)
})
})
tap.test('smartacme -> should have created keyPair', async () => {
expect(testSmartAcme.acmeUrl).to.be.a('string')
})
tap.test('smartacme -> should register a new account', async (tools) => {
tools.timeout(10000)
await testSmartAcme.createAcmeAccount().then(async x => {
testAcmeAccount = x
})
})
tap.test('smartacme -> should create a AcmeCert', async () => {
await testAcmeAccount.createAcmeCert('test2.bleu.de').then(async x => {
testAcmeCert = x
expect(testAcmeAccount).to.be.instanceOf(smartacme.AcmeCert)
})
})
tap.test('smartacme -> should get a challenge for a AcmeCert', async (tools) => {
tools.timeout(10000)
await testAcmeCert.requestChallenge().then(async (challengeChosen) => {
console.log(challengeChosen)
testChallenge = challengeChosen
})
})
tap.test('smartacme -> should set the challenge', async (tools) => {
tools.timeout(20000)
await myCflareAccount.createRecord(
testChallenge.domainNamePrefixed,
'TXT', testChallenge.dnsKeyHash
)
})
tap.test('smartacme -> should check for a DNS record', async (tools) => {
tools.timeout(20000)
await testAcmeCert.checkDns().then(x => {
console.log(x)
})
})
tap.test('smartacme -> should accept the challenge', async (tools) => {
tools.timeout(10000)
await testAcmeCert.acceptChallenge()
})
tap.test('smartacme -> should poll for validation of a challenge', async (tools) => {
tools.timeout(10000)
await testAcmeCert.requestValidation().then(async x => {
console.log(x)
})
})
tap.test('smartacme -> should remove the challenge', async (tools) => {
tools.timeout(20000)
await myCflareAccount.removeRecord(
testChallenge.domainNamePrefixed,
'TXT'
)
})
tap.start()

View File

@ -0,0 +1,94 @@
import * as q from 'smartq'
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
}
}

View File

@ -0,0 +1,255 @@
import * as q from 'smartq'
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 ISmartAcmeChallengeChosen 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
fullchain: string
parentAcmeAccount: AcmeAccount
csr
validFrom: Date
validTo: Date
keypair: IRsaKeypair
keyPairFinal: IRsaKeypair
chosenChallenge: ISmartAcmeChallengeChosen
dnsKeyHash: string
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<ISmartAcmeChallengeChosen>()
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 preChosenChallenge = res.body.challenges.filter(x => {
return x.type === challengeTypeArg
})[ 0 ]
/**
* the key is needed to accept the challenge
*/
let authKey: string = plugins.rawacme.keyAuthz(
preChosenChallenge.token,
this.parentAcmeAccount.parentSmartAcme.keyPair.publicKey
)
/**
* needed in case selected challenge is of type dns-01
*/
this.dnsKeyHash = plugins.rawacme.dnsKeyAuthzHash(authKey) // needed if dns challenge is chosen
/**
* the return challenge
*/
this.chosenChallenge = {
uri: preChosenChallenge.uri,
type: preChosenChallenge.type,
token: preChosenChallenge.token,
keyAuthorization: authKey,
status: preChosenChallenge.status,
dnsKeyHash: this.dnsKeyHash,
domainName: this.domainName,
domainNamePrefixed: helpers.prefixName(this.domainName)
}
done.resolve(this.chosenChallenge)
}
)
return done.promise
}
/**
* checks if DNS records are set, will go through a max of 30 cycles
*/
async checkDns(cycleArg = 1) {
let result = await myDnsly.checkUntilAvailable(helpers.prefixName(this.domainName), 'TXT', this.dnsKeyHash)
if (result) {
console.log('DNS is set!')
return
} else {
throw new Error('DNS not set!')
}
}
/**
* validates a challenge, only call after you have set the challenge at the expected location
*/
async requestValidation() {
let makeRequest = () => {
let done = q.defer()
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.poll(this.chosenChallenge.uri, async (err, res) => {
if (err) {
console.log(err)
return
}
console.log(`Validation response:`)
console.log(JSON.stringify(res.body))
if (res.body.status === 'pending' || res.body.status === 'invalid') {
await plugins.smartdelay.delayFor(3000)
makeRequest().then((x: any) => { done.resolve(x) })
} else {
console.log('perfect!')
done.resolve(res.body)
}
})
return done.promise
}
await makeRequest()
}
/**
* 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
*/
acceptChallenge() {
let done = q.defer()
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.post(
this.chosenChallenge.uri,
{
resource: 'challenge',
keyAuthorization: this.chosenChallenge.keyAuthorization
},
this.parentAcmeAccount.parentSmartAcme.keyPair,
(err, res) => {
if (err) {
console.log(err)
done.reject(err)
}
done.resolve(res.body)
}
)
return done.promise
}
}

View File

@ -1,111 +1,82 @@
import 'typings-global' // third party modules
import * as q from 'q' import * as q from 'smartq' // promises
import * as path from 'path' import * as plugins from './smartacme.plugins'
import * as smartfile from 'smartfile' import * as helpers from './smartacme.helpers'
import * as smartstring from 'smartstring'
import * as paths from './smartacme.paths'
let ACME = require('le-acme-core').ACME.create() import { AcmeAccount } from './smartacme.classes.acmeaccount'
let RSA = require('rsa-compat').RSA
let bitlen = 1024 /**
let exp = 65537 * a rsa keypair needed for account creation and subsequent requests
let options = { */
public: true, export interface IRsaKeypair {
pem: true, publicKey: string
internal: true privateKey: string
} }
export { AcmeAccount } from './smartacme.classes.acmeaccount'
export { AcmeCert, ISmartAcmeChallenge, ISmartAcmeChallengeChosen } from './smartacme.classes.acmecert'
/** /**
* class SmartAcme exports methods for maintaining SSL Certificates * class SmartAcme exports methods for maintaining SSL Certificates
*/ */
export class SmartAcme { export class SmartAcme {
preparedBool: boolean = false acmeUrl: string // the acme url to use for this instance
acmeUrls: any productionBool: boolean // a boolean to quickly know wether we are in production or not
productionBool: boolean keyPair: IRsaKeypair // the keyPair needed for account creation
keyPair: any rawacmeClient
constructor(productionArg: boolean = false) {
this.productionBool = productionArg
}
/** /**
* prepares the SmartAcme class * the constructor for class SmartAcme
*/ */
prepareAcme() { constructor(productionArg: boolean = false) {
let done = q.defer() this.productionBool = productionArg
if (this.preparedBool === false) { this.keyPair = helpers.createKeypair()
this.getAcmeUrls() if (this.productionBool) {
.then(() => { this.acmeUrl = plugins.rawacme.LETSENCRYPT_URL
return this.createKeyPair() } else {
}) this.acmeUrl = plugins.rawacme.LETSENCRYPT_STAGING_URL
.then((x) => { }
console.log('prepared smartacme instance') }
done.resolve()
}) /**
} else { * init the smartacme instance
done.resolve() */
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
} }
return done.promise
}
/** // make client available in class
* creates an account if not currently present in module this.rawacmeClient = client
*/
createAccount() {
let done = q.defer()
this.prepareAcme()
.then(() => {
let options = {
newRegUrl: this.acmeUrls.newReg,
email: 'domains@lossless.org', // valid email (server checks MX records)
accountKeypair: { // privateKeyPem or privateKeyJwt
privateKeyPem: this.keyPair
},
agreeToTerms: function (tosUrl, done) {
done(null, tosUrl)
}
}
ACME.registerNewAccount(options, (err, regr) => {
if(err) {
console.log(err)
done.reject(err)
}
done.resolve(regr)
})
}).catch(err => { console.log(err) })
return done.promise
}
/**
* creates a keyPair
*/
createKeyPair() {
let done = q.defer()
RSA.generateKeypair(bitlen, exp, options, (err, keypair) => {
if (err) {
console.log(err)
done.reject(err)
}
console.log(keypair)
this.keyPair = keypair
})
done.resolve() done.resolve()
return done.promise }
} )
return done.promise
}
/** /**
* gets the Acme Urls * creates an account if not currently present in module
*/ * @executes ASYNC
getAcmeUrls() { */
let done = q.defer() createAcmeAccount() {
ACME.getAcmeUrls(ACME.stagingServerUrl, (err, urls) => { let done = q.defer<AcmeAccount>()
if (err) { let acmeAccount = new AcmeAccount(this)
throw err acmeAccount.register().then(() => {
} return acmeAccount.agreeTos()
this.acmeUrls = urls }).then(() => {
console.log(this.acmeUrls) done.resolve(acmeAccount)
done.resolve() })
}) return done.promise
return done.promise }
}
} }

50
ts/smartacme.helpers.ts Normal file
View File

@ -0,0 +1,50 @@
import 'typings-global'
import * as q from 'smartq'
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
}

22
ts/smartacme.plugins.ts Normal file
View File

@ -0,0 +1,22 @@
import 'typings-global' // typings for node
import * as path from 'path' // native node path module
let rsaKeygen = require('rsa-keygen') // rsa keygen
let rawacme = require('rawacme') // acme helper functions
let nodeForge = require('node-forge')
// push.rocks modules here
import * as dnsly from 'dnsly'
import * as smartdelay from 'smartdelay'
import * as smartfile from 'smartfile'
import * as smartstring from 'smartstring'
export {
dnsly,
rsaKeygen,
rawacme,
nodeForge,
smartdelay,
smartfile,
smartstring
}

1081
yarn.lock Normal file

File diff suppressed because it is too large Load Diff