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