From 14c24e3aeab5249d977ce7a0d540c3f47536aca2 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 6 May 2019 23:12:13 -0600 Subject: [PATCH 1/8] 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) { From 1c0701cd51bf46b4b43caecd3dadb41b97ee5c7e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 7 May 2019 23:46:01 -0600 Subject: [PATCH 2/8] merge working features and add some docs --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++------ bundle.sh | 41 +++++++++++++++++++++++++++++++++++++++++ package.json | 11 ++++++++--- 3 files changed, 92 insertions(+), 9 deletions(-) create mode 100755 bundle.sh diff --git a/README.md b/README.md index 891922c..187800e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,46 @@ -# Bluecrypt™ Keypairs +# Bluecrypt™ [Keypairs](https://git.rootprojects.org/root/bluecrypt-keypairs.js) | A [Root](https://rootprojects.org) Project A port of [keypairs.js](https://git.coolaj86.com/coolaj86/keypairs.js) to the browser. -* Keypairs - * Eckles (ECDSA) - * Rasha (RSA) - * X509 - * ASN1 +# Features (port in-progress) + + * [x] Keypair generation and encoding + * [x] RSA + * [x] ECDSA (P-256, P-384) + * [x] JWK-to-PEM + * [ ] JWK-to-SSH + * [ ] PEM-to-JWK + * [ ] SSH-to-JWK + * [x] ASN1, X509, PEM, DER + * [x] SHA256 JWK Thumbprints + * [x] Sign JWS + * [ ] Create JWTs + * [ ] JWK fetching. See [Keyfetch.js](https://npmjs.com/packages/keyfetch/) + * [ ] OIDC + * [ ] Auth0 + * [ ] CLI (ee [keypairs-cli](https://npmjs.com/packages/keypairs-cli/)) + * [ ] Node.js (ee [keypairs.js](https://npmjs.com/packages/keypairs.js)) + * [ ] [CSR.js](https://git.rootprojects.org/root/bluecrypt-csr.js) + * [ ] [ACME.js](https://git.rootprojects.org/root/bluecrypt-acme.js) (Let's Encyrpt) + +# Online Demos + +* Bluecrypt Keypairs.js Demo + +# QuickStart + +`bluecrypt-keypairs.js` +```html + +``` + +`bluecrypt-keypairs.min.js` +```html + +``` + +You can see `index.html` and `app.js` in the repo for full example usage. + +# Documentation + +See [keypairs.js](https://git.coolaj86.com/coolaj86/keypairs.js) for documentation. diff --git a/bundle.sh b/bundle.sh new file mode 100755 index 0000000..5973e01 --- /dev/null +++ b/bundle.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Development Version +cat > bluecrypt-keypairs.js << EOF +// Copyright 2015-2019 AJ ONeal. All rights reserved +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +; +EOF +cat ./lib/encoding.js \ + ./lib/asn1-packer.js \ + ./lib/x509.js \ + ./lib/ecdsa.js \ + ./lib/rsa.js \ + ./lib/keypairs.js \ + >> bluecrypt-keypairs.js + +# Gzipped +cat > bluecrypt-keypairs.min.js << EOF +// Copyright 2015-2019 AJ ONeal. All rights reserved +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +; +EOF +uglifyjs bluecrypt-keypairs.js >> bluecrypt-keypairs.min.js +gzip bluecrypt-keypairs.min.js + +# Minified Gzipped +cat > bluecrypt-keypairs.min.js << EOF +// Copyright 2015-2019 AJ ONeal. All rights reserved +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +; +EOF +uglifyjs bluecrypt-keypairs.js >> bluecrypt-keypairs.min.js + +rsync -av ./ root@beta.rootprojects.org:~/beta.rootprojects.org/keypairs/ +rsync -av ./ ubuntu@rootprojects.org:/srv/www/rootprojects.org/keypairs/ diff --git a/package.json b/package.json index 3dd19e2..7dd2734 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,18 @@ { - "name": "bluecrypt-keypairs", + "name": "@bluecrypt/keypairs", "version": "0.1.1", "description": "Zero-Dependency Native Browser support for ECDSA P-256 and P-384, and RSA 2048/3072/4096 written in VanillaJS", + "homepage": "https://rootprojects.org/keypairs/", + "files": [ + "lib", + "bluecrypt-keypairs.js", + "bluecrypt-keypairs.min.js" + ] "directories": { "lib": "lib" }, "scripts": { - "test": "node server.js", - "start": "node server.js" + "test": "node test.js" }, "repository": { "type": "git", From 957af198014f96c6b86d0403f1adb8d9e87bb6dc Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 7 May 2019 23:46:31 -0600 Subject: [PATCH 3/8] rename --- lib/{bluecrypt-encoding.js => encoding.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/{bluecrypt-encoding.js => encoding.js} (100%) diff --git a/lib/bluecrypt-encoding.js b/lib/encoding.js similarity index 100% rename from lib/bluecrypt-encoding.js rename to lib/encoding.js From d1104cf1524e354f006ea5083e89786d3297bada Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 7 May 2019 23:47:40 -0600 Subject: [PATCH 4/8] typo fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7dd2734..5430713 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lib", "bluecrypt-keypairs.js", "bluecrypt-keypairs.min.js" - ] + ], "directories": { "lib": "lib" }, From ddc04a54926df82c603fdb351b5c5f2c6b48676b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 10 May 2019 22:37:35 -0600 Subject: [PATCH 5/8] update desc and links --- index.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index d4e99de..7ad38b0 100644 --- a/index.html +++ b/index.html @@ -17,9 +17,17 @@ -

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.

+

@bluecrypt/keypairs: Universal keygen & signing for browsers

+

Keypairs.js is easy-to-use browser crypto in kilobytes, not megabytes.

+ +

It's a modern alternative to larger, legacy libraries like PKI.js and rsasign, + with more universal support for keygen, signing, and verification (including PKI, X509, JOSE, JWS, and JWT) + at a fraction of the cost.

+ +

This is intended to be explored with your JavaScript console open.

+
<script src="https://rootprojects.org/keypairs/bluecrypt-keypairs.js"></script>
+
<script src="https://rootprojects.org/keypairs/bluecrypt-keypairs.min.js"></script>
+ Documentation

Keypair Generation

From 8da6604f32983fec742552c0ab5911e5b0b5b10b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 10 May 2019 22:43:15 -0600 Subject: [PATCH 6/8] update desc and links --- index.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.html b/index.html index 7ad38b0..f245129 100644 --- a/index.html +++ b/index.html @@ -96,6 +96,13 @@
+
+

Bluecrypt™ is a collection of lightweight, zero-dependency, libraries written in VanillaJS. + They are fast, tiny, and secure, using the native features of modern browsers where possible.

+
+ + From 5d920d108a7a06ef2b78b39dce4a4d96ebee63bd Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 10 May 2019 22:43:28 -0600 Subject: [PATCH 7/8] overwrite gzip without confirm --- bundle.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bundle.sh b/bundle.sh index 5973e01..0bc43f1 100755 --- a/bundle.sh +++ b/bundle.sh @@ -25,7 +25,7 @@ cat > bluecrypt-keypairs.min.js << EOF ; EOF uglifyjs bluecrypt-keypairs.js >> bluecrypt-keypairs.min.js -gzip bluecrypt-keypairs.min.js +gzip -f bluecrypt-keypairs.min.js # Minified Gzipped cat > bluecrypt-keypairs.min.js << EOF @@ -37,5 +37,6 @@ cat > bluecrypt-keypairs.min.js << EOF EOF uglifyjs bluecrypt-keypairs.js >> bluecrypt-keypairs.min.js +rsync -av ./ root@beta.therootcompany.com:~/beta.therootcompany.com/keypairs/ rsync -av ./ root@beta.rootprojects.org:~/beta.rootprojects.org/keypairs/ rsync -av ./ ubuntu@rootprojects.org:/srv/www/rootprojects.org/keypairs/ From e7f5376a453ae7709e4e0b185a32e64425c68dec Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 10 May 2019 22:50:00 -0600 Subject: [PATCH 8/8] remove leftover cruft --- app.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app.js b/app.js index bf418ed..10acaa4 100644 --- a/app.js +++ b/app.js @@ -106,8 +106,6 @@ $$('button').map(function ($el) { $el.disabled = false; }); $('.js-toc-jwk').hidden = false; - $('.js-create-account').hidden = false; - $('.js-create-csr').hidden = false; }); });