From 7efe42da103db7037ef165cec50860bd5f114b5f Mon Sep 17 00:00:00 2001 From: "Mr. Funk" Date: Mon, 6 May 2019 23:00:01 -0400 Subject: [PATCH 01/11] consistent spacing for reformating --- .editorconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bec4847 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +tab_width = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true \ No newline at end of file -- 2.38.5 From 7ba413dae6a9042158ee1a237719241be52345a1 Mon Sep 17 00:00:00 2001 From: "Mr. Funk" Date: Mon, 6 May 2019 23:05:45 -0400 Subject: [PATCH 02/11] hide jwk keypair on loading --- app.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.js b/app.js index 9780beb..ca6bcae 100644 --- a/app.js +++ b/app.js @@ -48,6 +48,8 @@ $('.js-jwk').hidden = true; $('.js-toc-der-public').hidden = true; $('.js-toc-der-private').hidden = true; + $('.js-toc-jwk').hidden = true; + $$('.js-toc-pem').forEach(function ($el) { $el.hidden = true; }); -- 2.38.5 From 4f5cf492e3dae889b9d85fd4816ccdae9307f93c Mon Sep 17 00:00:00 2001 From: "Mr. Funk" Date: Tue, 7 May 2019 09:29:53 -0400 Subject: [PATCH 03/11] init template --- index.html | 142 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 59 deletions(-) diff --git a/index.html b/index.html index d4e99de..b1d9667 100644 --- a/index.html +++ b/index.html @@ -1,11 +1,12 @@ - - BlueCrypt - - - -

BlueCrypt for the Browser

-

BlueCrypt is universal crypto for the browser. It's lightweight, fast, and based on native webcrypto. + + + +

BlueCrypt for the Browser

+

BlueCrypt is universal crypto for the browser. It's lightweight, fast, and based on native webcrypto. This means it's easy-to-use crypto in kilobytes, not megabytes.

-

Keypair Generation

-
-

Key Type:

-
+

Keypair Generation

+ +

Key Type:

+
@@ -50,50 +51,73 @@
- - + + - + - - - - - - - - + + + + + + + + - - - - - - - - +

Signing

+
+
+
+ +
+ +
+ +
+ + + + + + + + + + + -- 2.38.5 From 1654ab7880713f181a6071ad151d268c3da09185 Mon Sep 17 00:00:00 2001 From: "Mr. Funk" Date: Tue, 7 May 2019 09:37:05 -0400 Subject: [PATCH 04/11] remove outer div --- index.html | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index b1d9667..1d51fd3 100644 --- a/index.html +++ b/index.html @@ -99,18 +99,15 @@
- - + +
+ JWS +
+
+
+ JWS +
+
-- 2.38.5 From 49ab9982423976bdf2089bd56d1cfce4b49b11ce Mon Sep 17 00:00:00 2001 From: "Mr. Funk" Date: Tue, 7 May 2019 09:38:16 -0400 Subject: [PATCH 05/11] boilerplate function --- app.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index ca6bcae..390a218 100644 --- a/app.js +++ b/app.js @@ -57,8 +57,8 @@ $$('button').map(function ($el) { $el.disabled = true; }); var opts = { kty: $('input[name="kty"]:checked').value - , namedCurve: $('input[name="ec-crv"]:checked').value - , modulusLength: $('input[name="rsa-len"]:checked').value + , namedCurve: $('input[name="ec-crv"]:checked').value + , modulusLength: $('input[name="rsa-len"]:checked').value }; var then = Date.now(); console.log('opts', opts); @@ -118,7 +118,27 @@ }); }); + $('form.js-keysign').addEventListener('submit', function (ev) { + ev.preventDefault(); + ev.stopPropagation(); + $('.js-pem-loading').hidden = false; + $('.js-toc-jws').hidden = true; + $('.js-toc-jwt').hidden = true; + $$('input').map(function ($el) { $el.disabled = true; }); + $$('button').map(function ($el) { $el.disabled = true; }); + + // function here + // keys.generate() + // jws = jwk.sign(payload) + // jwt = jws.protected + '.' + jws.payload + '.' + jws.signature + // promise call back + $('.js-pem-loading').hidden = true; + $$('input').map(function ($el) { $el.disabled = false; }); + $$('button').map(function ($el) { $el.disabled = false; }); + }); + $('.js-generate').hidden = false; + $('.js-sign').hidden = false; } window.addEventListener('load', run); -- 2.38.5 From 037b8489f60d83a9ac44896183263fd830d44807 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:45:48 -0400 Subject: [PATCH 06/11] initial working jwk jws --- app.js | 46 ++++++++++++++++++++++++++++++++++++++++------ index.html | 16 ++++++++++------ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/app.js b/app.js index 390a218..0367578 100644 --- a/app.js +++ b/app.js @@ -127,18 +127,52 @@ $$('input').map(function ($el) { $el.disabled = true; }); $$('button').map(function ($el) { $el.disabled = true; }); - // function here - // keys.generate() + var opts = { + jwk: JSON.parse($('textarea[name="JWK"]').value), + claims: { + exp: "1h", + iss: document.getElementById(`-acmeDomains`).value + } + }; + + Keypairs.signJwt(opts).then(function (msg) { + console.log("msg response") + console.log(msg) + + $('.js-jwt').innerText = msg; + $('.js-toc-jwt').hidden = false; + var msgArr = msg.split(".") + var protected64 = msgArr[0] + var payload64 = msgArr[1] + Keypairs._sign(opts, msg).then(function (buf) { + var signedMsg = { + protected: protected64 + , payload: payload64 + , signature: Enc.bufToUrlBase64(buf) + }; + $('.js-jws').innerText = JSON.stringify(signedMsg); + $('.js-toc-jws').hidden = false; + $('.js-pem-loading').hidden = true; + $$('input').map(function ($el) { $el.disabled = false; }); + $$('button').map(function ($el) { $el.disabled = false; }); + }); + }) + // jws = jwk.sign(payload) // jwt = jws.protected + '.' + jws.payload + '.' + jws.signature - // promise call back - $('.js-pem-loading').hidden = true; - $$('input').map(function ($el) { $el.disabled = false; }); - $$('button').map(function ($el) { $el.disabled = false; }); + }); $('.js-generate').hidden = false; $('.js-sign').hidden = false; + $('textarea[name="JWK"]').value = JSON.stringify({ + "crv": "P-256", + "d": "LImWxqqTHbP3LHQfqscDSUzf_uNePGqf9U6ETEcO5Ho", + "kty": "EC", + "x": "vdjQ3T6VBX82LIKDzepYgRsz3HgRwp83yPuonu6vqos", + "y": "IUkEXtAMnppnV1A19sE2bJhUo4WPbq6EYgWxma4oGyg", + "kid": "MnfJYyS9W5gUjrJLdn8ePMzik8ZJz2qc-VZmKOs_oCw" + }) } window.addEventListener('load', run); diff --git a/index.html b/index.html index 1d51fd3..27d96b9 100644 --- a/index.html +++ b/index.html @@ -93,20 +93,24 @@
- + + +
+
+
-
+ -
- JWS -
+ -- 2.38.5 From 035535465406809ee4c121908708c64517cb28c5 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:47:59 -0400 Subject: [PATCH 07/11] fix initial jwk --- app.js | 4 ++-- index.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 0367578..24f2ebc 100644 --- a/app.js +++ b/app.js @@ -128,7 +128,7 @@ $$('button').map(function ($el) { $el.disabled = true; }); var opts = { - jwk: JSON.parse($('textarea[name="JWK"]').value), + jwk: JSON.parse($('textarea[name="jwk"]').value), claims: { exp: "1h", iss: document.getElementById(`-acmeDomains`).value @@ -165,7 +165,7 @@ $('.js-generate').hidden = false; $('.js-sign').hidden = false; - $('textarea[name="JWK"]').value = JSON.stringify({ + $('textarea[name="jwk"]').value = JSON.stringify({ "crv": "P-256", "d": "LImWxqqTHbP3LHQfqscDSUzf_uNePGqf9U6ETEcO5Ho", "kty": "EC", diff --git a/index.html b/index.html index 27d96b9..8afe337 100644 --- a/index.html +++ b/index.html @@ -97,9 +97,9 @@
- +
- +
-- 2.38.5 From 1809d9104b5c92d9c3dcd29be0c08134fff797b9 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:52:46 -0400 Subject: [PATCH 08/11] some cleanup --- app.js | 23 +++++++++++------------ index.html | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app.js b/app.js index 24f2ebc..7bf7564 100644 --- a/app.js +++ b/app.js @@ -144,18 +144,17 @@ var msgArr = msg.split(".") var protected64 = msgArr[0] var payload64 = msgArr[1] - Keypairs._sign(opts, msg).then(function (buf) { - var signedMsg = { - protected: protected64 - , payload: payload64 - , signature: Enc.bufToUrlBase64(buf) - }; - $('.js-jws').innerText = JSON.stringify(signedMsg); - $('.js-toc-jws').hidden = false; - $('.js-pem-loading').hidden = true; - $$('input').map(function ($el) { $el.disabled = false; }); - $$('button').map(function ($el) { $el.disabled = false; }); - }); + var signature = msgArr[2] + var signedMsg = { + protected: protected64 + , payload: payload64 + , signature + }; + $('.js-jws').innerText = JSON.stringify(signedMsg, null, 2); + $('.js-toc-jws').hidden = false; + $('.js-pem-loading').hidden = true; + $$('input').map(function ($el) { $el.disabled = false; }); + $$('button').map(function ($el) { $el.disabled = false; }); }) // jws = jwk.sign(payload) diff --git a/index.html b/index.html index 8afe337..00298de 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ height: 10em; } /* need to word wrap the binary no space der */ - .js-der-public, .js-der-private{ + .js-der-public, .js-der-private, .js-jwt{ white-space: pre-wrap; /* CSS3 */ white-space: -moz-pre-wrap; /* Firefox */ white-space: -pre-wrap; /* Opera <7 */ -- 2.38.5 From 1d6ce35289533b5c6f969b4d9066a867fd69c60e Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:53:24 -0400 Subject: [PATCH 09/11] remove log --- app.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/app.js b/app.js index 7bf7564..a894ce8 100644 --- a/app.js +++ b/app.js @@ -136,9 +136,6 @@ }; Keypairs.signJwt(opts).then(function (msg) { - console.log("msg response") - console.log(msg) - $('.js-jwt').innerText = msg; $('.js-toc-jwt').hidden = false; var msgArr = msg.split(".") -- 2.38.5 From 0e802df186465a18dbb709497c221b3951a44e61 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:53:44 -0400 Subject: [PATCH 10/11] more code cleanup --- app.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app.js b/app.js index a894ce8..2ff2699 100644 --- a/app.js +++ b/app.js @@ -153,10 +153,7 @@ $$('input').map(function ($el) { $el.disabled = false; }); $$('button').map(function ($el) { $el.disabled = false; }); }) - - // jws = jwk.sign(payload) - // jwt = jws.protected + '.' + jws.payload + '.' + jws.signature - + }); $('.js-generate').hidden = false; -- 2.38.5 From 13be5d8eb619b27f30e77e306c06a25ab849d596 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 12:02:37 -0400 Subject: [PATCH 11/11] error print --- app.js | 59 ++++++++++++++++++++++++++++++++++-------------------- index.html | 19 ++++++++++-------- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/app.js b/app.js index 2ff2699..e16f5ec 100644 --- a/app.js +++ b/app.js @@ -127,33 +127,48 @@ $$('input').map(function ($el) { $el.disabled = true; }); $$('button').map(function ($el) { $el.disabled = true; }); - var opts = { - jwk: JSON.parse($('textarea[name="jwk"]').value), - claims: { - exp: "1h", - iss: document.getElementById(`-acmeDomains`).value - } - }; + try { - Keypairs.signJwt(opts).then(function (msg) { - $('.js-jwt').innerText = msg; - $('.js-toc-jwt').hidden = false; - var msgArr = msg.split(".") - var protected64 = msgArr[0] - var payload64 = msgArr[1] - var signature = msgArr[2] - var signedMsg = { - protected: protected64 - , payload: payload64 - , signature + + var opts = { + jwk: JSON.parse($('textarea[name="jwk"]').value), + claims: { + exp: "1h", + iss: document.getElementById(`-acmeDomains`).value + } }; - $('.js-jws').innerText = JSON.stringify(signedMsg, null, 2); - $('.js-toc-jws').hidden = false; + + Keypairs.signJwt(opts).then(function (msg) { + document.getElementById(`sign-error`).innerText = null; + $('.js-jwt').innerText = msg; + $('.js-toc-jwt').hidden = false; + var msgArr = msg.split(".") + var protected64 = msgArr[0] + var payload64 = msgArr[1] + var signature = msgArr[2] + var signedMsg = { + protected: protected64 + , payload: payload64 + , signature + }; + $('.js-jws').innerText = JSON.stringify(signedMsg, null, 2); + $('.js-toc-jws').hidden = false; + $('.js-pem-loading').hidden = true; + $$('input').map(function ($el) { $el.disabled = false; }); + $$('button').map(function ($el) { $el.disabled = false; }); + }).catch(function (error) { + document.getElementById(`sign-error`).innerText = error.message + $('.js-pem-loading').hidden = true; + $$('input').map(function ($el) { $el.disabled = false; }); + $$('button').map(function ($el) { $el.disabled = false; }); + }) + } catch (error) { + document.getElementById(`sign-error`).innerText = error.message $('.js-pem-loading').hidden = true; $$('input').map(function ($el) { $el.disabled = false; }); $$('button').map(function ($el) { $el.disabled = false; }); - }) - + } + }); $('.js-generate').hidden = false; diff --git a/index.html b/index.html index 00298de..e140335 100644 --- a/index.html +++ b/index.html @@ -7,14 +7,17 @@ width: 42em; height: 10em; } - /* need to word wrap the binary no space der */ - .js-der-public, .js-der-private, .js-jwt{ - white-space: pre-wrap; /* CSS3 */ - white-space: -moz-pre-wrap; /* Firefox */ - white-space: -pre-wrap; /* Opera <7 */ - white-space: -o-pre-wrap; /* Opera 7 */ - word-wrap: break-word; /* IE */ - } + /* need to word wrap the binary no space der */ + .js-der-public, .js-der-private, .js-jwt{ + white-space: pre-wrap; /* CSS3 */ + white-space: -moz-pre-wrap; /* Firefox */ + white-space: -pre-wrap; /* Opera <7 */ + white-space: -o-pre-wrap; /* Opera 7 */ + word-wrap: break-word; /* IE */ + } + .errors { + color: red; + } -- 2.38.5