From 14c24e3aeab5249d977ce7a0d540c3f47536aca2 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 6 May 2019 23:12:13 -0600 Subject: [PATCH] minor bugfixes --- app.js | 5 ----- lib/asn1-parser.js | 2 +- lib/bluecrypt-encoding.js | 7 +++++-- lib/keypairs.js | 15 ++++++--------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/app.js b/app.js index 9780beb..bf418ed 100644 --- a/app.js +++ b/app.js @@ -17,11 +17,6 @@ return Array.prototype.slice.call(document.querySelectorAll(sel)); } - function checkTos(tos) { - console.log("TODO checkbox for agree to terms"); - return tos; - } - function run() { console.log('hello'); diff --git a/lib/asn1-parser.js b/lib/asn1-parser.js index 82f7cd0..9314aa3 100644 --- a/lib/asn1-parser.js +++ b/lib/asn1-parser.js @@ -125,7 +125,7 @@ PEM.parseBlock = PEM.parseBlock || function (str) { var der = str.split(/\n/).filter(function (line) { return !/-----/.test(line); }).join(''); - return { der: Enc.base64ToBuf(der) }; + return { bytes: Enc.base64ToBuf(der) }; }; Enc.base64ToBuf = function (b64) { diff --git a/lib/bluecrypt-encoding.js b/lib/bluecrypt-encoding.js index c2473a6..a9609e5 100644 --- a/lib/bluecrypt-encoding.js +++ b/lib/bluecrypt-encoding.js @@ -66,8 +66,11 @@ Enc.numToHex = function (d) { }; Enc.bufToUrlBase64 = function (u8) { - return Enc.bufToBase64(u8) - .replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); + return Enc.base64ToUrlBase64(Enc.bufToBase64(u8)); +}; + +Enc.base64ToUrlBase64 = function (str) { + return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); }; Enc.bufToBase64 = function (u8) { diff --git a/lib/keypairs.js b/lib/keypairs.js index 2e423f9..932bc65 100644 --- a/lib/keypairs.js +++ b/lib/keypairs.js @@ -186,10 +186,6 @@ Keypairs.signJws = function (opts) { , signature: Enc.bufToUrlBase64(buf) }; - console.log('Signed Base64 Msg:'); - console.log(JSON.stringify(signedMsg, null, 2)); - - console.log('msg:', msg); return signedMsg; }); } @@ -219,10 +215,12 @@ Keypairs._sign = function (opts, payload) { ).then(function (signature) { signature = new Uint8Array(signature); // ArrayBuffer -> u8 // This will come back into play for CSRs, but not for JOSE - if ('EC' === opts.jwk.kty && /x509/i.test(opts.format)) { - signature = Keypairs._ecdsaJoseSigToAsn1Sig(signature); + if ('EC' === opts.jwk.kty && /x509|asn1/i.test(opts.format)) { + return Keypairs._ecdsaJoseSigToAsn1Sig(signature); + } else { + // jose/jws/jwt + return signature; } - return signature; }); }); }; @@ -261,7 +259,6 @@ Keypairs._import = function (opts) { opts.jwk.ext = true; opts.jwk.key_ops = ops; - console.log('jwk', opts.jwk); return window.crypto.subtle.importKey( "jwk" , opts.jwk @@ -298,7 +295,7 @@ Keypairs._ecdsaJoseSigToAsn1Sig = function (bufsig) { if (len >= 0x80) { head.push(0x81); } head.push(len); - return Uint8Array.from(head.concat([0x02, r.length], r, [0x02, s.byteLength], s)); + return Uint8Array.from(head.concat([0x02, r.length], r, [0x02, s.length], s)); }; function setTime(time) { -- 2.38.5