#38 passes create test

This commit is contained in:
AJ ONeal 2016-08-08 19:14:53 -04:00
parent 29a4443d49
commit eebfe38d62
3 changed files with 28 additions and 45 deletions

View File

@ -28,8 +28,10 @@ LE._undefined = {
acme: u acme: u
, store: u , store: u
, challenger: u , challenger: u
, register: u , register: u
, check: u , check: u
, renewWithin: u , renewWithin: u
, memorizeFor: u , memorizeFor: u
, acmeChallengePrefix: u , acmeChallengePrefix: u
@ -61,6 +63,9 @@ LE.create = function (le) {
le.rsaKeySize = le.rsaKeySize || LE.rsaKeySize; le.rsaKeySize = le.rsaKeySize || LE.rsaKeySize;
le.challengeType = le.challengeType || LE.challengeType; le.challengeType = le.challengeType || LE.challengeType;
le._ipc = ipc; le._ipc = ipc;
le.agreeToTerms = le.agreeToTerms || function (args, agreeCb) {
agreeCb(new Error("'agreeToTerms' was not supplied to LE and 'agreeTos' was not supplied to LE.register"));
};
if (!le.renewWithin) { le.renewWithin = 3 * 24 * 60 * 60 * 1000; } if (!le.renewWithin) { le.renewWithin = 3 * 24 * 60 * 60 * 1000; }
if (!le.memorizeFor) { le.memorizeFor = 1 * 24 * 60 * 60 * 1000; } if (!le.memorizeFor) { le.memorizeFor = 1 * 24 * 60 * 60 * 1000; }

View File

@ -2,9 +2,8 @@
module.exports.create = function (le) { module.exports.create = function (le) {
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var utils = require('./utils'); // merge, tplCopy; var utils = require('./utils');
var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA); var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA);
var crypto = require('crypto');
var core = { var core = {
// //
@ -39,9 +38,11 @@ module.exports.create = function (le) {
registerAsync: function (args) { registerAsync: function (args) {
var err; var err;
var copy = utils.merge(args, le); var copy = utils.merge(args, le);
var disagreeTos;
args = utils.tplCopy(copy); args = utils.tplCopy(copy);
if (!args.email || !args.agreeTos || (parseInt(args.rsaKeySize, 10) < 2048)) { disagreeTos = (!args.agreeTos && 'undefined' !== typeof args.agreeTos);
if (!args.email || disagreeTos || (parseInt(args.rsaKeySize, 10) < 2048)) {
err = new Error( err = new Error(
"In order to register an account both 'email' and 'agreeTos' must be present" "In order to register an account both 'email' and 'agreeTos' must be present"
+ " and 'rsaKeySize' must be 2048 or greater." + " and 'rsaKeySize' must be 2048 or greater."
@ -58,6 +59,7 @@ module.exports.create = function (le) {
}, function (/*err*/) { }, function (/*err*/) {
return RSA.generateKeypairAsync(args.rsaKeySize, 65537, keypairOpts).then(function (keypair) { return RSA.generateKeypairAsync(args.rsaKeySize, 65537, keypairOpts).then(function (keypair) {
keypair.privateKeyPem = RSA.exportPrivatePem(keypair); keypair.privateKeyPem = RSA.exportPrivatePem(keypair);
keypair.publicKeyPem = RSA.exportPublicPem(keypair);
keypair.privateKeyJwk = RSA.exportPrivateJwk(keypair); keypair.privateKeyJwk = RSA.exportPrivateJwk(keypair);
return le.store.accounts.setKeypairAsync(args, keypair); return le.store.accounts.setKeypairAsync(args, keypair);
}); });
@ -69,8 +71,6 @@ module.exports.create = function (le) {
return core.getAcmeUrlsAsync(args).then(function (urls) { return core.getAcmeUrlsAsync(args).then(function (urls) {
args._acmeUrls = urls; args._acmeUrls = urls;
throw new Error("WAIT! Don't go yet!!!");
return le.acme.registerNewAccountAsync({ return le.acme.registerNewAccountAsync({
email: args.email email: args.email
, newRegUrl: args._acmeUrls.newReg , newRegUrl: args._acmeUrls.newReg
@ -88,28 +88,18 @@ module.exports.create = function (le) {
, accountKeypair: keypair , accountKeypair: keypair
, debug: le.debug || args.debug , debug: le.debug || args.debug
}).then(function (body) { }).then(function (receipt) {
// TODO XXX use sha256 (the python client uses md5) var reg = {
// TODO ssh fingerprint (noted on rsa-compat issues page, I believe) keypair: keypair
keypair.publicKeyMd5 = crypto.createHash('md5').update(RSA.exportPublicPem(keypair)).digest('hex'); , receipt: receipt
keypair.publicKeySha256 = crypto.createHash('sha256').update(RSA.exportPublicPem(keypair)).digest('hex'); , email: args.email
};
var accountId = keypair.publicKeyMd5; // TODO move templating of arguments to right here?
var regr = { body: body }; return le.store.accounts.setAsync(args, reg).then(function (account) {
var account = {}; // should now have account.id and account.accountId
args.account = account;
args.accountId = accountId; args.accountId = account.id;
account.keypair = keypair;
account.regr = regr;
account.accountId = accountId;
account.id = accountId;
account.email = args.email;
args.account = account;
// TODO move templating to right here?
return le.store.accounts.setAsync(args, account).then(function () {
return account; return account;
}); });
}); });
@ -186,6 +176,7 @@ module.exports.create = function (le) {
}, function (/*err*/) { }, function (/*err*/) {
return RSA.generateKeypairAsync(args.rsaKeySize, 65537, keypairOpts).then(function (keypair) { return RSA.generateKeypairAsync(args.rsaKeySize, 65537, keypairOpts).then(function (keypair) {
keypair.privateKeyPem = RSA.exportPrivatePem(keypair); keypair.privateKeyPem = RSA.exportPrivatePem(keypair);
keypair.publicKeyPem = RSA.exportPublicPem(keypair);
keypair.privateKeyJwk = RSA.exportPrivateJwk(keypair); keypair.privateKeyJwk = RSA.exportPrivateJwk(keypair);
return le.store.certificates.setKeypairAsync(args, keypair); return le.store.certificates.setKeypairAsync(args, keypair);
}); });

View File

@ -11,7 +11,8 @@ var le = LE.create({
, debug: true , debug: true
}); });
var testId = Math.round(Date.now() / 1000).toString(); //var testId = Math.round(Date.now() / 1000).toString();
var testId = 'test1000';
var fakeEmail = 'coolaj86+le.' + testId + '@example.com'; var fakeEmail = 'coolaj86+le.' + testId + '@example.com';
var testEmail = 'coolaj86+le.' + testId + '@gmail.com'; var testEmail = 'coolaj86+le.' + testId + '@gmail.com';
var testAccount; var testAccount;
@ -74,6 +75,10 @@ var tests = [
, rsaKeySize: 2048 , rsaKeySize: 2048
}).then(function (account) { }).then(function (account) {
testAccount = account; testAccount = account;
console.log(testEmail);
console.log(testAccount);
if (!account) { if (!account) {
throw new Error("Registration should always return a new account."); throw new Error("Registration should always return a new account.");
} }
@ -85,24 +90,6 @@ var tests = [
} }
}); });
} }
, function () {
return le.core.accounts.checkAsync({
email: testAccount.email
}).then(function (account) {
if (!account) {
throw new Error("Test account should exist when searched by email.");
}
});
}
, function () {
return le.core.accounts.checkAsync({
accountId: testAccount.id
}).then(function (account) {
if (!account) {
throw new Error("Test account should exist when searched by account id.");
}
});
}
]; ];
function run() { function run() {