2019-05-06 09:45:11 +00:00
|
|
|
/*global Promise*/
|
2019-04-18 06:20:51 +00:00
|
|
|
(function () {
|
2019-04-27 04:09:57 +00:00
|
|
|
'use strict';
|
2019-04-18 06:20:51 +00:00
|
|
|
|
2019-04-27 04:09:57 +00:00
|
|
|
var Keypairs = window.Keypairs;
|
2019-04-27 06:34:49 +00:00
|
|
|
var Rasha = window.Rasha;
|
|
|
|
var Eckles = window.Eckles;
|
|
|
|
var x509 = window.x509;
|
2019-05-06 09:45:11 +00:00
|
|
|
var CSR = window.CSR;
|
|
|
|
var ACME = window.ACME;
|
|
|
|
var accountStuff = {};
|
2019-04-18 06:20:51 +00:00
|
|
|
|
2019-04-27 04:09:57 +00:00
|
|
|
function $(sel) {
|
|
|
|
return document.querySelector(sel);
|
|
|
|
}
|
|
|
|
function $$(sel) {
|
|
|
|
return Array.prototype.slice.call(document.querySelectorAll(sel));
|
|
|
|
}
|
2019-04-18 06:20:51 +00:00
|
|
|
|
2019-05-06 09:45:11 +00:00
|
|
|
function checkTos(tos) {
|
|
|
|
console.log("TODO checkbox for agree to terms");
|
|
|
|
return tos;
|
|
|
|
}
|
|
|
|
|
2019-04-27 04:09:57 +00:00
|
|
|
function run() {
|
|
|
|
console.log('hello');
|
2019-04-18 06:20:51 +00:00
|
|
|
|
2019-04-27 04:09:57 +00:00
|
|
|
// Show different options for ECDSA vs RSA
|
|
|
|
$$('input[name="kty"]').forEach(function ($el) {
|
|
|
|
$el.addEventListener('change', function (ev) {
|
|
|
|
console.log(this);
|
|
|
|
console.log(ev);
|
|
|
|
if ("RSA" === ev.target.value) {
|
|
|
|
$('.js-rsa-opts').hidden = false;
|
|
|
|
$('.js-ec-opts').hidden = true;
|
|
|
|
} else {
|
|
|
|
$('.js-rsa-opts').hidden = true;
|
|
|
|
$('.js-ec-opts').hidden = false;
|
|
|
|
}
|
|
|
|
});
|
2019-04-18 06:20:51 +00:00
|
|
|
});
|
|
|
|
|
2019-04-27 04:09:57 +00:00
|
|
|
// Generate a key on submit
|
|
|
|
$('form.js-keygen').addEventListener('submit', function (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
$('.js-loading').hidden = false;
|
|
|
|
$('.js-jwk').hidden = true;
|
2019-04-27 05:24:37 +00:00
|
|
|
$('.js-toc-der-public').hidden = true;
|
|
|
|
$('.js-toc-der-private').hidden = true;
|
2019-05-07 03:05:45 +00:00
|
|
|
$('.js-toc-jwk').hidden = true;
|
|
|
|
|
2019-04-27 06:34:49 +00:00
|
|
|
$$('.js-toc-pem').forEach(function ($el) {
|
|
|
|
$el.hidden = true;
|
|
|
|
});
|
2019-04-27 04:09:57 +00:00
|
|
|
$$('input').map(function ($el) { $el.disabled = true; });
|
|
|
|
$$('button').map(function ($el) { $el.disabled = true; });
|
|
|
|
var opts = {
|
|
|
|
kty: $('input[name="kty"]:checked').value
|
2019-04-29 06:56:40 +00:00
|
|
|
, namedCurve: $('input[name="ec-crv"]:checked').value
|
|
|
|
, modulusLength: $('input[name="rsa-len"]:checked').value
|
2019-04-27 04:09:57 +00:00
|
|
|
};
|
2019-05-06 09:45:11 +00:00
|
|
|
var then = Date.now();
|
2019-04-27 04:09:57 +00:00
|
|
|
console.log('opts', opts);
|
|
|
|
Keypairs.generate(opts).then(function (results) {
|
2019-05-06 09:45:11 +00:00
|
|
|
console.log("Key generation time:", (Date.now() - then) + "ms");
|
2019-04-27 06:34:49 +00:00
|
|
|
var pubDer;
|
|
|
|
var privDer;
|
|
|
|
if (/EC/i.test(opts.kty)) {
|
|
|
|
privDer = x509.packPkcs8(results.private);
|
|
|
|
pubDer = x509.packSpki(results.public);
|
|
|
|
Eckles.export({ jwk: results.private, format: 'sec1' }).then(function (pem) {
|
|
|
|
$('.js-input-pem-sec1-private').innerText = pem;
|
|
|
|
$('.js-toc-pem-sec1-private').hidden = false;
|
|
|
|
});
|
|
|
|
Eckles.export({ jwk: results.private, format: 'pkcs8' }).then(function (pem) {
|
|
|
|
$('.js-input-pem-pkcs8-private').innerText = pem;
|
|
|
|
$('.js-toc-pem-pkcs8-private').hidden = false;
|
|
|
|
});
|
|
|
|
Eckles.export({ jwk: results.public, public: true }).then(function (pem) {
|
|
|
|
$('.js-input-pem-spki-public').innerText = pem;
|
|
|
|
$('.js-toc-pem-spki-public').hidden = false;
|
|
|
|
});
|
2019-04-27 04:31:16 +00:00
|
|
|
} else {
|
2019-04-27 06:34:49 +00:00
|
|
|
privDer = x509.packPkcs8(results.private);
|
|
|
|
pubDer = x509.packSpki(results.public);
|
|
|
|
Rasha.export({ jwk: results.private, format: 'pkcs1' }).then(function (pem) {
|
|
|
|
$('.js-input-pem-pkcs1-private').innerText = pem;
|
|
|
|
$('.js-toc-pem-pkcs1-private').hidden = false;
|
|
|
|
});
|
|
|
|
Rasha.export({ jwk: results.private, format: 'pkcs8' }).then(function (pem) {
|
|
|
|
$('.js-input-pem-pkcs8-private').innerText = pem;
|
|
|
|
$('.js-toc-pem-pkcs8-private').hidden = false;
|
|
|
|
});
|
|
|
|
Rasha.export({ jwk: results.public, format: 'pkcs1' }).then(function (pem) {
|
|
|
|
$('.js-input-pem-pkcs1-public').innerText = pem;
|
|
|
|
$('.js-toc-pem-pkcs1-public').hidden = false;
|
|
|
|
});
|
|
|
|
Rasha.export({ jwk: results.public, format: 'spki' }).then(function (pem) {
|
|
|
|
$('.js-input-pem-spki-public').innerText = pem;
|
|
|
|
$('.js-toc-pem-spki-public').hidden = false;
|
|
|
|
});
|
2019-04-27 04:09:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 06:34:49 +00:00
|
|
|
$('.js-der-public').innerText = pubDer;
|
2019-04-27 05:24:37 +00:00
|
|
|
$('.js-toc-der-public').hidden = false;
|
2019-04-27 06:34:49 +00:00
|
|
|
$('.js-der-private').innerText = privDer;
|
2019-04-27 05:24:37 +00:00
|
|
|
$('.js-toc-der-private').hidden = false;
|
2019-04-27 04:09:57 +00:00
|
|
|
$('.js-jwk').innerText = JSON.stringify(results, null, 2);
|
|
|
|
$('.js-loading').hidden = true;
|
|
|
|
$('.js-jwk').hidden = false;
|
|
|
|
$$('input').map(function ($el) { $el.disabled = false; });
|
|
|
|
$$('button').map(function ($el) { $el.disabled = false; });
|
|
|
|
$('.js-toc-jwk').hidden = false;
|
2019-05-06 09:45:11 +00:00
|
|
|
|
|
|
|
$('.js-create-account').hidden = false;
|
|
|
|
$('.js-create-csr').hidden = false;
|
2019-04-27 04:09:57 +00:00
|
|
|
});
|
2019-04-18 06:20:51 +00:00
|
|
|
});
|
|
|
|
|
2019-04-27 04:09:57 +00:00
|
|
|
$('.js-generate').hidden = false;
|
|
|
|
}
|
2019-04-18 06:20:51 +00:00
|
|
|
|
2019-04-27 04:09:57 +00:00
|
|
|
window.addEventListener('load', run);
|
2019-04-18 06:20:51 +00:00
|
|
|
}());
|