switch to rawacme for more basic letsencrypt access

This commit is contained in:
Philipp Kunz 2017-01-01 18:05:26 +01:00
parent f5e7bab12d
commit 66407cb214
10 changed files with 133 additions and 189 deletions

8
dist/smartacme.classes.helper.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
import 'typings-global';
export interface IRsaKeypair {
publicKey: string;
privateKey: string;
}
export declare class SmartacmeHelper {
createKeypair(bit?: number): IRsaKeypair;
}

14
dist/smartacme.classes.helper.js vendored Normal file
View File

@ -0,0 +1,14 @@
"use strict";
require("typings-global");
let rsaKeygen = require('rsa-keygen');
class SmartacmeHelper {
createKeypair(bit = 2048) {
let result = rsaKeygen.generate(bit);
return {
publicKey: result.public_key,
privateKey: result.private_key
};
}
}
exports.SmartacmeHelper = SmartacmeHelper;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuaGVscGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZXMuaGVscGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFDdkIsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFBO0FBT3JDO0lBQ0ksYUFBYSxDQUFDLEdBQUcsR0FBRyxJQUFJO1FBQ3BCLElBQUksTUFBTSxHQUFHLFNBQVMsQ0FBQyxRQUFRLENBQUMsR0FBRyxDQUFDLENBQUE7UUFDbkMsTUFBTSxDQUFDO1lBQ0osU0FBUyxFQUFHLE1BQU0sQ0FBQyxVQUFVO1lBQzdCLFVBQVUsRUFBRSxNQUFNLENBQUMsV0FBVztTQUNoQyxDQUFBO0lBQ04sQ0FBQztDQUNKO0FBUkQsMENBUUMifQ==

View File

@ -1,29 +1,23 @@
/// <reference types="q" /> /// <reference types="q" />
import 'typings-global'; import 'typings-global';
import * as q from 'q'; import * as q from 'q';
import { SmartacmeHelper, IRsaKeypair } from './smartacme.classes.helper';
/** /**
* 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; helper: SmartacmeHelper;
acmeUrls: any; acmeUrl: string;
productionBool: boolean; productionBool: boolean;
keyPair: any; keyPair: IRsaKeypair;
JWK: any;
/**
* the constructor for class SmartAcme
*/
constructor(productionArg?: boolean); constructor(productionArg?: boolean);
/**
* prepares the SmartAcme class
*/
prepareAcme(): q.Promise<{}>;
/** /**
* creates an account if not currently present in module * creates an account if not currently present in module
* @executes ASYNC
*/ */
createAccount(): q.Promise<{}>; createAccount(): q.Promise<{}>;
/**
* creates a keyPair
*/
createKeyPair(): q.Promise<{}>;
/**
* gets the Acme Urls
*/
getAcmeUrls(): q.Promise<{}>;
} }

View File

@ -1,101 +1,60 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
const q = require("q"); const q = require("q");
let ACME = require('le-acme-core').ACME.create(); let rsaKeygen = require('rsa-keygen');
let RSA = require('rsa-compat').RSA; let rawacme = require('rawacme');
let bitlen = 1024; const smartacme_classes_helper_1 = require("./smartacme.classes.helper");
let exp = 65537;
let options = {
public: true,
pem: true,
internal: true
};
/** /**
* 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.helper = new smartacme_classes_helper_1.SmartacmeHelper();
this.getAcmeUrls() this.keyPair = this.helper.createKeypair();
.then(() => { if (this.productionBool) {
return this.createKeyPair(); this.acmeUrl = rawacme.LETSENCRYPT_STAGING_URL;
})
.then((x) => {
console.log('prepared smartacme instance');
done.resolve();
});
} }
else { else {
done.resolve(); this.acmeUrl = rawacme.LETSENCRYPT_URL;
} }
return done.promise;
} }
/** /**
* creates an account if not currently present in module * creates an account if not currently present in module
* @executes ASYNC
*/ */
createAccount() { createAccount() {
let done = q.defer(); let done = q.defer();
this.prepareAcme() rawacme.createClient({
.then(() => { url: this.acmeUrl,
let options = { publicKey: this.keyPair.publicKey,
newRegUrl: this.acmeUrls.newReg, privateKey: this.keyPair.privateKey
email: 'domains@lossless.org', }, (err, client) => {
accountKeypair: {
privateKeyPem: this.keyPair
},
agreeToTerms: function (tosUrl, done) {
done(null, tosUrl);
}
};
ACME.registerNewAccount(options, (err, regr) => {
if (err) { if (err) {
console.error('smartacme: something went wrong:');
console.log(err); console.log(err);
done.reject(err); done.reject(err);
return;
} }
done.resolve(regr); client.newReg({
}); contact: ['mailto:domains@lossless.org']
}).catch(err => { console.log(err); }); }, (err, res) => {
return done.promise;
}
/**
* creates a keyPair
*/
createKeyPair() {
let done = q.defer();
RSA.generateKeypair(bitlen, exp, options, (err, keypair) => {
if (err) { if (err) {
console.error('smartacme: something went wrong:');
console.log(err); console.log(err);
done.reject(err); done.reject(err);
return;
} }
console.log(keypair); this.JWK = res.body.key;
this.keyPair = keypair; console.log(this.JWK);
done.resolve(); 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ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FBRyxHQUFHLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQTtnQkFDdkIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUE7Z0JBQ3JCLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtZQUNsQixDQUFDLENBQUMsQ0FBQTtRQUVWLENBQUMsQ0FDSixDQUFBO1FBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztDQUNKO0FBN0RELDhCQTZEQyJ9

View File

@ -24,9 +24,9 @@
"homepage": "https://gitlab.com/pushrocks/smartacme#README", "homepage": "https://gitlab.com/pushrocks/smartacme#README",
"dependencies": { "dependencies": {
"@types/q": "0.x.x", "@types/q": "0.x.x",
"le-acme-core": "^2.0.7",
"q": "^1.4.1", "q": "^1.4.1",
"rsa-compat": "^1.2.7", "rawacme": "^0.2.1",
"rsa-keygen": "^1.0.6",
"smartfile": "^4.1.0", "smartfile": "^4.1.0",
"smartstring": "^2.0.20", "smartstring": "^2.0.20",
"typings-global": "^1.0.14" "typings-global": "^1.0.14"

View File

@ -10,17 +10,12 @@ describe('smartacme', function () {
testAcme = new smartacme.SmartAcme(); testAcme = new smartacme.SmartAcme();
should(testAcme).be.instanceOf(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 have created keyPair', function () {
should(testAcme.acmeUrl).be.of.type('string');
}); });
it('should register a new account', function (done) { it('should register a new account', function (done) {
this.timeout(40000);
testAcme.createAccount().then(x => { testAcme.createAccount().then(x => {
console.log(x);
done(); done();
}).catch(err => { }).catch(err => {
console.log(err); console.log(err);
@ -28,4 +23,4 @@ describe('smartacme', function () {
}); });
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ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0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsK0JBQStCLEVBQUUsVUFBVSxJQUFJO1FBQzlDLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUE7UUFDbkIsUUFBUSxDQUFDLGFBQWEsRUFBRSxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQzNCLElBQUksRUFBRSxDQUFBO1FBQ1YsQ0FBQyxDQUFDLENBQUMsS0FBSyxDQUFDLEdBQUc7WUFDUixPQUFPLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxDQUFBO1lBQ2hCLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQTtRQUNiLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -11,20 +11,12 @@ describe('smartacme', function () {
testAcme = new smartacme.SmartAcme() testAcme = new smartacme.SmartAcme()
should(testAcme).be.instanceOf(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 have created keyPair', function () {
should(testAcme.acmeUrl).be.of.type('string')
}) })
it('should register a new account', function (done) { it('should register a new account', function (done) {
this.timeout(40000)
testAcme.createAccount().then(x => { testAcme.createAccount().then(x => {
console.log(x)
done() done()
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)

View File

@ -0,0 +1,17 @@
import 'typings-global'
let rsaKeygen = require('rsa-keygen')
export interface IRsaKeypair {
publicKey: string
privateKey: string
}
export class SmartacmeHelper {
createKeypair(bit = 2048): IRsaKeypair {
let result = rsaKeygen.generate(bit)
return {
publicKey: result.public_key,
privateKey: result.private_key
}
}
}

View File

@ -1,111 +1,76 @@
import 'typings-global' import 'typings-global'
import * as q from 'q' import * as q from 'q'
import * as path from 'path' import * as path from 'path'
let rsaKeygen = require('rsa-keygen')
import * as smartfile from 'smartfile' import * as smartfile from 'smartfile'
import * as smartstring from 'smartstring' import * as smartstring from 'smartstring'
let rawacme = require('rawacme')
import * as paths from './smartacme.paths' import * as paths from './smartacme.paths'
let ACME = require('le-acme-core').ACME.create() import { SmartacmeHelper, IRsaKeypair } from './smartacme.classes.helper'
let RSA = require('rsa-compat').RSA
let bitlen = 1024
let exp = 65537
let options = {
public: true,
pem: true,
internal: true
}
/** /**
* 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 helper: SmartacmeHelper // bundles helper methods that would clutter the main SmartAcme class
acmeUrls: any acmeUrl: string // the acme url to use
productionBool: boolean productionBool: boolean // a boolean to quickly know wether we are in production or not
keyPair: any keyPair: IRsaKeypair // the keyPair needed for account creation
constructor(productionArg: boolean = false) { JWK
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.helper = new SmartacmeHelper()
this.getAcmeUrls() this.keyPair = this.helper.createKeypair()
.then(() => { if (this.productionBool) {
return this.createKeyPair() this.acmeUrl = rawacme.LETSENCRYPT_STAGING_URL
})
.then((x) => {
console.log('prepared smartacme instance')
done.resolve()
})
} else { } else {
done.resolve() this.acmeUrl = rawacme.LETSENCRYPT_URL
} }
return done.promise
} }
/** /**
* creates an account if not currently present in module * creates an account if not currently present in module
* @executes ASYNC
*/ */
createAccount() { createAccount() {
let done = q.defer() let done = q.defer()
this.prepareAcme() rawacme.createClient(
.then(() => { {
let options = { url: this.acmeUrl,
newRegUrl: this.acmeUrls.newReg, publicKey: this.keyPair.publicKey,
email: 'domains@lossless.org', // valid email (server checks MX records) privateKey: this.keyPair.privateKey
accountKeypair: { // privateKeyPem or privateKeyJwt
privateKeyPem: this.keyPair
}, },
agreeToTerms: function (tosUrl, done) { (err, client) => {
done(null, tosUrl)
}
}
ACME.registerNewAccount(options, (err, regr) => {
if (err) { if (err) {
console.error('smartacme: something went wrong:')
console.log(err) console.log(err)
done.reject(err) done.reject(err)
} return
done.resolve(regr)
})
}).catch(err => { console.log(err) })
return done.promise
} }
/** client.newReg(
* creates a keyPair {
*/ contact: ['mailto:domains@lossless.org']
createKeyPair() { },
let done = q.defer() (err, res) => {
RSA.generateKeypair(bitlen, exp, options, (err, keypair) => {
if (err) { if (err) {
console.error('smartacme: something went wrong:')
console.log(err) console.log(err)
done.reject(err) done.reject(err)
return
} }
console.log(keypair) this.JWK = res.body.key
this.keyPair = keypair console.log(this.JWK)
done.resolve() 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
} }
} }

0
ts/test.coffee Normal file
View File