From 037b8489f60d83a9ac44896183263fd830d44807 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:45:48 -0400 Subject: [PATCH 1/6] 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 -
+ From 035535465406809ee4c121908708c64517cb28c5 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:47:59 -0400 Subject: [PATCH 2/6] 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 @@
- +
- +
From 1809d9104b5c92d9c3dcd29be0c08134fff797b9 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:52:46 -0400 Subject: [PATCH 3/6] 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 */ From 1d6ce35289533b5c6f969b4d9066a867fd69c60e Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:53:24 -0400 Subject: [PATCH 4/6] 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(".") From 0e802df186465a18dbb709497c221b3951a44e61 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 11:53:44 -0400 Subject: [PATCH 5/6] 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; From 13be5d8eb619b27f30e77e306c06a25ab849d596 Mon Sep 17 00:00:00 2001 From: lastlink Date: Tue, 7 May 2019 12:02:37 -0400 Subject: [PATCH 6/6] 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; + }