working der and pem generation #2

Merged
coolaj86 merged 7 commits from lastlink/bluecrypt-keypairs.js:master into master 2019-04-27 05:33:09 +00:00
2 changed files with 41 additions and 20 deletions
Showing only changes of commit fbe30dbfbc - Show all commits

39
app.js
View File

@ -34,8 +34,10 @@
ev.stopPropagation(); ev.stopPropagation();
$('.js-loading').hidden = false; $('.js-loading').hidden = false;
$('.js-jwk').hidden = true; $('.js-jwk').hidden = true;
$('.js-toc-der').hidden = true; $('.js-toc-der-public').hidden = true;
$('.js-toc-pem').hidden = true; $('.js-toc-pem-public').hidden = true;
$('.js-toc-der-private').hidden = true;
$('.js-toc-pem-private').hidden = true;
$$('input').map(function ($el) { $el.disabled = true; }); $$('input').map(function ($el) { $el.disabled = true; });
$$('button').map(function ($el) { $el.disabled = true; }); $$('button').map(function ($el) { $el.disabled = true; });
var opts = { var opts = {
@ -45,22 +47,33 @@
}; };
console.log('opts', opts); console.log('opts', opts);
Keypairs.generate(opts).then(function (results) { Keypairs.generate(opts).then(function (results) {
var der; var der_public, der_private;
if (opts.kty == 'EC') { if (opts.kty == 'EC') {
der = x509.packPkcs8(results.private); der_public = x509.packSpki(results.public);
var pem = Eckles.export({ jwk: results.private }) der_private = x509.packPkcs8(results.private);
$('.js-input-pem').innerText = pem; var pem_private = Eckles.export({ jwk: results.private })
$('.js-toc-pem').hidden = false; var pem_public = Eckles.export({ jwk: results.public, public: true })
$('.js-input-pem-public').innerText = pem_public;
$('.js-toc-pem-public').hidden = false;
$('.js-input-pem-private').innerText = pem_private;
$('.js-toc-pem-private').hidden = false;
} else { } else {
der = x509.packPkcs8(results.private); der_private = x509.packPkcs8(results.private);
var pem = Rasha.pack({ jwk: results.private }).then(function (pem) { der_public = x509.packPkcs8(results.public);
$('.js-input-pem').innerText = pem; Rasha.pack({ jwk: results.private }).then(function (pem) {
$('.js-toc-pem').hidden = false; $('.js-input-pem-private').innerText = pem;
$('.js-toc-pem-private').hidden = false;
})
Rasha.pack({ jwk: results.public }).then(function (pem) {
$('.js-input-pem-public').innerText = pem;
$('.js-toc-pem-public').hidden = false;
}) })
} }
$('.js-der').innerText = der; $('.js-der-public').innerText = der_public;
$('.js-toc-der').hidden = false; $('.js-toc-der-public').hidden = false;
$('.js-der-private').innerText = der_private;
$('.js-toc-der-private').hidden = false;
$('.js-jwk').innerText = JSON.stringify(results, null, 2); $('.js-jwk').innerText = JSON.stringify(results, null, 2);
$('.js-loading').hidden = true; $('.js-loading').hidden = true;
$('.js-jwk').hidden = false; $('.js-jwk').hidden = false;

View File

@ -7,7 +7,7 @@
height: 10em; height: 10em;
} }
/* need to word wrap the binary no space der */ /* need to word wrap the binary no space der */
.js-der{ .js-der-public, .js-der-private{
white-space: pre-wrap; /* CSS3 */ white-space: pre-wrap; /* CSS3 */
white-space: -moz-pre-wrap; /* Firefox */ white-space: -moz-pre-wrap; /* Firefox */
white-space: -pre-wrap; /* Opera <7 */ white-space: -pre-wrap; /* Opera <7 */
@ -72,13 +72,21 @@
<summary>JWK Keypair</summary> <summary>JWK Keypair</summary>
<pre><code class="js-jwk">&nbsp;</code></pre> <pre><code class="js-jwk">&nbsp;</code></pre>
</details> </details>
<details class="js-toc-der" hidden> <details class="js-toc-der-private" hidden>
<summary>DER Binary</summary> <summary>DER Private Binary</summary>
<pre><code class="js-der">&nbsp;</code></pre> <pre><code class="js-der-private">&nbsp;</code></pre>
</details> </details>
<details class="js-toc-pem" hidden> <details class="js-toc-der-public" hidden>
<summary>PEM (base64-encoded DER)</summary> <summary>DER Public Binary</summary>
<textarea class="js-input-pem" readonly></textarea> <pre><code class="js-der-public">&nbsp;</code></pre>
</details>
<details class="js-toc-pem-private" hidden>
<summary>PEM Private (base64-encoded DER)</summary>
<pre><code class="js-input-pem-private" ></code></pre>
</details>
<details class="js-toc-pem-public" hidden>
<summary>PEM Public (base64-encoded DER)</summary>
<pre><code class="js-input-pem-public" ></code></pre>
</details> </details>
<details class="js-toc-acme-account-request" hidden> <details class="js-toc-acme-account-request" hidden>
<summary>ACME Account Request</summary> <summary>ACME Account Request</summary>