WIP Building out all features necessary for Let's Encrypt #6

Closed
coolaj86 wants to merge 17 commits from more-acme into master
1 changed files with 86 additions and 70 deletions
Showing only changes of commit 009e0dc1fb - Show all commits

156
app.js
View File

@ -138,6 +138,7 @@
accountStuff.privateJwk = privJwk; accountStuff.privateJwk = privJwk;
accountStuff.email = email; accountStuff.email = email;
accountStuff.acme = acme; accountStuff.acme = acme;
$('.js-create-order').hidden = false;
}).catch(function (err) { }).catch(function (err) {
console.error("A bad thing happened:"); console.error("A bad thing happened:");
console.error(err); console.error(err);
@ -149,26 +150,7 @@
$('form.js-csr').addEventListener('submit', function (ev) { $('form.js-csr').addEventListener('submit', function (ev) {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
var domains = ($('.js-domains').value||'example.com').split(/[, ]+/g); generateCsr();
//var privJwk = JSON.parse($('.js-jwk').innerText).private;
return Keypairs.generate({
kty: $('input[name="kty"]:checked').value
, namedCurve: $('input[name="ec-crv"]:checked').value
, modulusLength: $('input[name="rsa-len"]:checked').value
}).then(function (pair) {
console.log('domain keypair:', pair);
accountStuff.domainPrivateJwk = pair.private;
return CSR({ jwk: pair.private, domains: domains }).then(function (pem) {
// Verify with https://www.sslshopper.com/csr-decoder.html
accountStuff.csr = pem;
console.log('CSR:');
console.log(pem);
console.log('CSR info:');
console.log(CSR._info(pem));
$('.js-create-order').hidden = false;
});
});
}); });
$('form.js-acme-order').addEventListener('submit', function (ev) { $('form.js-acme-order').addEventListener('submit', function (ev) {
@ -181,64 +163,98 @@
var domains = ($('.js-domains').value||'example.com').split(/[, ]+/g); var domains = ($('.js-domains').value||'example.com').split(/[, ]+/g);
return acme.certificates.create({ return getDomainPrivkey().then(function () {
accountKeypair: { privateKeyJwk: privJwk } return acme.certificates.create({
, account: account accountKeypair: { privateKeyJwk: privJwk }
//, domainKeypair: { privateKeyJwk: accountStuff.domainPrivateJwk } , account: account
, csr: accountStuff.csr //, domainKeypair: { privateKeyJwk: accountStuff.domainPrivateJwk }
, email: email , csr: accountStuff.csr
, domains: domains , email: email
, agreeToTerms: checkTos , domains: domains
, challenges: { , agreeToTerms: checkTos
'dns-01': { , challenges: {
set: function (opts) { 'dns-01': {
console.info('dns-01 set challenge:'); set: function (opts) {
console.info('TXT', opts.dnsHost); console.info('dns-01 set challenge:');
console.info(opts.dnsAuthorization); console.info('TXT', opts.dnsHost);
return new Promise(function (resolve) { console.info(opts.dnsAuthorization);
while (!window.confirm("Did you set the challenge?")) {} return new Promise(function (resolve) {
resolve(); while (!window.confirm("Did you set the challenge?")) {}
}); resolve();
});
}
, remove: function (opts) {
console.log('dns-01 remove challenge:');
console.info('TXT', opts.dnsHost);
console.info(opts.dnsAuthorization);
return new Promise(function (resolve) {
while (!window.confirm("Did you delete the challenge?")) {}
resolve();
});
}
} }
, remove: function (opts) { , 'http-01': {
console.log('dns-01 remove challenge:'); set: function (opts) {
console.info('TXT', opts.dnsHost); console.info('http-01 set challenge:');
console.info(opts.dnsAuthorization); console.info(opts.challengeUrl);
return new Promise(function (resolve) { console.info(opts.keyAuthorization);
while (!window.confirm("Did you delete the challenge?")) {} return new Promise(function (resolve) {
resolve(); while (!window.confirm("Did you set the challenge?")) {}
}); resolve();
});
}
, remove: function (opts) {
console.log('http-01 remove challenge:');
console.info(opts.challengeUrl);
console.info(opts.keyAuthorization);
return new Promise(function (resolve) {
while (!window.confirm("Did you delete the challenge?")) {}
resolve();
});
}
} }
} }
, 'http-01': { , challengeTypes: [$('input[name="acme-challenge-type"]:checked').value]
set: function (opts) { }).catch(function (err) {
console.info('http-01 set challenge:'); window.alert("failed! " + err.message || JSON.stringify(err));
console.info(opts.challengeUrl); });
console.info(opts.keyAuthorization);
return new Promise(function (resolve) {
while (!window.confirm("Did you set the challenge?")) {}
resolve();
});
}
, remove: function (opts) {
console.log('http-01 remove challenge:');
console.info(opts.challengeUrl);
console.info(opts.keyAuthorization);
return new Promise(function (resolve) {
while (!window.confirm("Did you delete the challenge?")) {}
resolve();
});
}
}
}
, challengeTypes: [$('input[name="acme-challenge-type"]:checked').value]
}).catch(function (err) {
window.alert("failed! " + err.message || JSON.stringify(err));
}); });
}); });
$('.js-generate').hidden = false; $('.js-generate').hidden = false;
} }
function getDomainPrivkey() {
if (accountStuff.domainPrivateJwk) { return Promise.resolve(accountStuff.domainPrivateJwk); }
return Keypairs.generate({
kty: $('input[name="kty"]:checked').value
, namedCurve: $('input[name="ec-crv"]:checked').value
, modulusLength: $('input[name="rsa-len"]:checked').value
}).then(function (pair) {
console.log('domain keypair:', pair);
accountStuff.domainPrivateJwk = pair.private;
return pair.private;
});
}
function generateCsr() {
var domains = ($('.js-domains').value||'example.com').split(/[, ]+/g);
//var privJwk = JSON.parse($('.js-jwk').innerText).private;
return getDomainPrivkey().then(function (privJwk) {
accountStuff.domainPrivateJwk = privJwk;
return CSR({ jwk: privJwk, domains: domains }).then(function (pem) {
// Verify with https://www.sslshopper.com/csr-decoder.html
accountStuff.csr = pem;
console.log('CSR:');
console.log(pem);
console.log('CSR info:');
console.log(CSR._info(pem));
return pem;
});
});
}
window.addEventListener('load', run); window.addEventListener('load', run);
}()); }());