diff --git a/app.js b/app.js index 3531ee2..bbac95c 100644 --- a/app.js +++ b/app.js @@ -6,7 +6,9 @@ var Rasha = window.Rasha; var Eckles = window.Eckles; var x509 = window.x509; + var CSR = window.CSR; var ACME = window.ACME; + var accountStuff = {}; function $(sel) { return document.querySelector(sel); @@ -15,6 +17,14 @@ return Array.prototype.slice.call(document.querySelectorAll(sel)); } + function checkTos(tos) { + if ($('input[name="tos"]:checked')) { + return tos; + } else { + return ''; + } + } + function run() { console.log('hello'); @@ -51,8 +61,10 @@ , namedCurve: $('input[name="ec-crv"]:checked').value , modulusLength: $('input[name="rsa-len"]:checked').value }; + var then = Date.now(); console.log('opts', opts); Keypairs.generate(opts).then(function (results) { + console.log("Key generation time:", (Date.now() - then) + "ms"); var pubDer; var privDer; if (/EC/i.test(opts.kty)) { @@ -101,6 +113,9 @@ $$('input').map(function ($el) { $el.disabled = false; }); $$('button').map(function ($el) { $el.disabled = false; }); $('.js-toc-jwk').hidden = false; + + $('.js-create-account').hidden = false; + $('.js-create-csr').hidden = false; }); }); @@ -110,56 +125,25 @@ $('.js-loading').hidden = false; var acme = ACME.create({ Keypairs: Keypairs + , CSR: CSR }); acme.init('https://acme-staging-v02.api.letsencrypt.org/directory').then(function (result) { console.log('acme result', result); var privJwk = JSON.parse($('.js-jwk').innerText).private; - var email = $('.js-email').innerText; - function checkTos(tos) { - console.log("TODO checkbox for agree to terms"); - return tos; - } + var email = $('.js-email').value; return acme.accounts.create({ email: email , agreeToTerms: checkTos , accountKeypair: { privateKeyJwk: privJwk } }).then(function (account) { console.log("account created result:", account); - return Keypairs.generate({ - kty: 'RSA' - , modulusLength: 2048 - }).then(function (pair) { - console.log('domain keypair:', pair); - var domains = ($('.js-domains').innerText||'example.com').split(/[, ]+/g); - return acme.certificates.create({ - accountKeypair: { privateKeyJwk: privJwk } - , account: account - , domainKeypair: { privateKeyJwk: pair.private } - , email: email - , domains: domains - , agreeToTerms: checkTos - , challenges: { - 'dns-01': { - set: function (opts) { - console.log('dns-01 set challenge:'); - console.log(JSON.stringify(opts, null, 2)); - return new Promise(function (resolve) { - while (!window.confirm("Did you set the challenge?")) {} - resolve(); - }); - } - , remove: function (opts) { - console.log('dns-01 remove challenge:'); - console.log(JSON.stringify(opts, null, 2)); - return new Promise(function (resolve) { - while (!window.confirm("Did you delete the challenge?")) {} - resolve(); - }); - } - } - } - }); - }); + accountStuff.account = account; + accountStuff.privateJwk = privJwk; + accountStuff.email = email; + accountStuff.acme = acme; + $('.js-create-order').hidden = false; + $('.js-toc-acme-account-response').hidden = false; + $('.js-acme-account-response').innerText = JSON.stringify(account, null, 2); }).catch(function (err) { console.error("A bad thing happened:"); console.error(err); @@ -168,8 +152,123 @@ }); }); + $('form.js-csr').addEventListener('submit', function (ev) { + ev.preventDefault(); + ev.stopPropagation(); + generateCsr(); + }); + + $('form.js-acme-order').addEventListener('submit', function (ev) { + ev.preventDefault(); + ev.stopPropagation(); + var account = accountStuff.account; + var privJwk = accountStuff.privateJwk; + var email = accountStuff.email; + var acme = accountStuff.acme; + + + var domains = ($('.js-domains').value||'example.com').split(/[, ]+/g); + return getDomainPrivkey().then(function (domainPrivJwk) { + console.log('Has CSR already?'); + console.log(accountStuff.csr); + return acme.certificates.create({ + accountKeypair: { privateKeyJwk: privJwk } + , account: account + , domainKeypair: { privateKeyJwk: domainPrivJwk } + , csr: accountStuff.csr + , email: email + , domains: domains + , skipDryRun: $('input[name="skip-dryrun"]:checked') && true + , agreeToTerms: checkTos + , challenges: { + 'dns-01': { + set: function (opts) { + console.info('dns-01 set challenge:'); + console.info('TXT', opts.dnsHost); + console.info(opts.dnsAuthorization); + return new Promise(function (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(); + }); + } + } + , 'http-01': { + set: function (opts) { + console.info('http-01 set challenge:'); + 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] + }).then(function (results) { + console.log('Got Certificates:'); + console.log(results); + $('.js-toc-acme-order-response').hidden = false; + $('.js-acme-order-response').innerText = JSON.stringify(results, null, 2); + }).catch(function (err) { + console.error("challenge failed:"); + console.error(err); + window.alert("failed! " + err.message || JSON.stringify(err)); + }); + }); + }); + $('.js-generate').hidden = false; - $('.js-create-account').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('Created CSR:'); + console.log(pem); + + console.log('CSR info:'); + console.log(CSR._info(pem)); + + return pem; + }); + }); } window.addEventListener('load', run); diff --git a/index.html b/index.html index b4d91c8..27f0aa5 100644 --- a/index.html +++ b/index.html @@ -34,27 +34,21 @@
EC Options:
- - - - - + + +RSA Options:
- - - - - - + + +
-
+