do der and pem for ecdsa only

This commit is contained in:
lastlink 2019-04-27 00:09:57 -04:00
parent 4b44a576c1
commit f0166afeeb
1 changed files with 67 additions and 63 deletions

130
app.js
View File

@ -1,75 +1,79 @@
(function () { (function () {
'use strict'; 'use strict';
var Keypairs = window.Keypairs; var Keypairs = window.Keypairs;
function $(sel) { function $(sel) {
return document.querySelector(sel); return document.querySelector(sel);
} }
function $$(sel) { function $$(sel) {
return Array.prototype.slice.call(document.querySelectorAll(sel)); return Array.prototype.slice.call(document.querySelectorAll(sel));
} }
function run() { function run() {
console.log('hello'); console.log('hello');
// Show different options for ECDSA vs RSA // Show different options for ECDSA vs RSA
$$('input[name="kty"]').forEach(function ($el) { $$('input[name="kty"]').forEach(function ($el) {
$el.addEventListener('change', function (ev) { $el.addEventListener('change', function (ev) {
console.log(this); console.log(this);
console.log(ev); console.log(ev);
if ("RSA" === ev.target.value) { if ("RSA" === ev.target.value) {
$('.js-rsa-opts').hidden = false; $('.js-rsa-opts').hidden = false;
$('.js-ec-opts').hidden = true; $('.js-ec-opts').hidden = true;
} else { } else {
$('.js-rsa-opts').hidden = true; $('.js-rsa-opts').hidden = true;
$('.js-ec-opts').hidden = false; $('.js-ec-opts').hidden = false;
} }
});
}); });
});
// Generate a key on submit // Generate a key on submit
$('form.js-keygen').addEventListener('submit', function (ev) { $('form.js-keygen').addEventListener('submit', function (ev) {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
$('.js-loading').hidden = false; $('.js-loading').hidden = false;
$('.js-jwk').hidden = true; $('.js-jwk').hidden = true;
$$('input').map(function ($el) { $el.disabled = true; }); $('.js-toc-der').hidden = true;
$$('button').map(function ($el) { $el.disabled = true; }); $('.js-toc-pem').hidden = true;
var opts = { $$('input').map(function ($el) { $el.disabled = true; });
kty: $('input[name="kty"]:checked').value $$('button').map(function ($el) { $el.disabled = true; });
, namedCurve: $('input[name="ec-crv"]:checked').value var opts = {
, modulusLength: $('input[name="rsa-len"]:checked').value kty: $('input[name="kty"]:checked').value
}; , namedCurve: $('input[name="ec-crv"]:checked').value
console.log('opts', opts); , modulusLength: $('input[name="rsa-len"]:checked').value
Keypairs.generate(opts).then(function (results) { };
var der = x509.packPkcs8(results.private); console.log('opts', opts);
var pem = Eckles.export({jwk:results.private}) Keypairs.generate(opts).then(function (results) {
if (opts.kty == 'EC') {
$('.js-jwk').innerText = JSON.stringify(results, null, 2); var der = x509.packPkcs8(results.private);
$('.js-der').innerText = JSON.stringify(der, null, 2); var pem = Eckles.export({ jwk: results.private })
$('.js-input-pem').innerText = pem; $('.js-der').innerText = JSON.stringify(der, null, 2);
// $('.js-input-pem').innerText = pem;
$('.js-loading').hidden = true; $('.js-toc-der').hidden = false;
$('.js-jwk').hidden = false; $('.js-toc-pem').hidden = false;
$$('input').map(function ($el) { $el.disabled = false; }); }
$$('button').map(function ($el) { $el.disabled = false; });
$('.js-toc-jwk').hidden = false; $('.js-jwk').innerText = JSON.stringify(results, null, 2);
$('.js-toc-der').hidden = false; //
$('.js-toc-pem').hidden = false; $('.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;
});
}); });
});
$('form.js-acme-account').addEventListener('submit', function (ev) { $('form.js-acme-account').addEventListener('submit', function (ev) {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
$('.js-loading').hidden = false; $('.js-loading').hidden = false;
ACME.accounts.create ACME.accounts.create
}); });
$('.js-generate').hidden = false; $('.js-generate').hidden = false;
$('.js-create-account').hidden = false; $('.js-create-account').hidden = false;
} }
window.addEventListener('load', run); window.addEventListener('load', run);
}()); }());