diff --git a/app.js b/app.js
index 28c9e63..fc3d9da 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,11 @@
return Array.prototype.slice.call(document.querySelectorAll(sel));
}
+ function checkTos(tos) {
+ console.log("TODO checkbox for agree to terms");
+ return tos;
+ }
+
function run() {
console.log('hello');
@@ -101,6 +108,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;
});
});
@@ -115,74 +125,17 @@
console.log('acme result', result);
var privJwk = JSON.parse($('.js-jwk').innerText).private;
var email = $('.js-email').value;
- function checkTos(tos) {
- console.log("TODO checkbox for agree to terms");
- return tos;
- }
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').value||'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.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]
- });
- });
+ accountStuff.account = account;
+ accountStuff.privateJwk = privJwk;
+ accountStuff.email = email;
+ accountStuff.acme = acme;
+ $('.js-create-order').hidden = false;
}).catch(function (err) {
console.error("A bad thing happened:");
console.error(err);
@@ -191,8 +144,87 @@
});
});
+ $('form.js-csr').addEventListener('submit', function (ev) {
+ ev.preventDefault();
+ ev.stopPropagation();
+ var domains = ($('.js-domains').value||'example.com').split(/[, ]+/g);
+ var privJwk = JSON.parse($('.js-jwk').innerText).private;
+ return CSR({ jwk: privJwk, domains: domains }).then(function (web64) {
+ // Verify with https://www.sslshopper.com/csr-decoder.html
+ console.log('urlBase64 CSR:');
+ console.log(web64);
+ });
+ });
+
+ $('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;
+
+ return Keypairs.generate({
+ kty: 'RSA'
+ , modulusLength: 2048
+ }).then(function (pair) {
+ console.log('domain keypair:', pair);
+ var domains = ($('.js-domains').value||'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.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]
+ });
+ });
+ });
+
$('.js-generate').hidden = false;
- $('.js-create-account').hidden = false;
}
window.addEventListener('load', run);
diff --git a/index.html b/index.html
index f984d04..4379cdb 100644
--- a/index.html
+++ b/index.html
@@ -58,15 +58,26 @@
+
+
+
+