Compare commits

..

10 Commits

Author SHA1 Message Date
Mr. Funk cc1afb8d4a merge fix 2019-05-11 16:56:38 -04:00
Mr. Funk d2c256d0bc fix merge 2019-05-11 16:55:53 -04:00
AJ ONeal e7f5376a45 remove leftover cruft 2019-05-10 22:50:00 -06:00
AJ ONeal 5d920d108a overwrite gzip without confirm 2019-05-10 22:43:28 -06:00
AJ ONeal 8da6604f32 update desc and links 2019-05-10 22:43:15 -06:00
AJ ONeal ddc04a5492 update desc and links 2019-05-10 22:37:35 -06:00
AJ ONeal d1104cf152 typo fix 2019-05-07 23:47:40 -06:00
AJ ONeal 957af19801 rename 2019-05-07 23:46:31 -06:00
AJ ONeal 1c0701cd51 merge working features and add some docs 2019-05-07 23:46:06 -06:00
AJ ONeal 14c24e3aea minor bugfixes 2019-05-06 23:12:13 -06:00
8 changed files with 142 additions and 53 deletions

View File

@ -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. A port of [keypairs.js](https://git.coolaj86.com/coolaj86/keypairs.js) to the browser.
* Keypairs # Features (port in-progress)
* Eckles (ECDSA)
* Rasha (RSA) * [x] Keypair generation and encoding
* X509 * [x] RSA
* ASN1 * [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 <https://rootprojects.org/keypairs/>
# QuickStart
`bluecrypt-keypairs.js`
```html
<script src="https://rootprojects.org/keypairs/bluecrypt-keypairs.js"></script>
```
`bluecrypt-keypairs.min.js`
```html
<script src="https://rootprojects.org/keypairs/bluecrypt-keypairs.min.js"></script>
```
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.

7
app.js
View File

@ -17,11 +17,6 @@
return Array.prototype.slice.call(document.querySelectorAll(sel)); return Array.prototype.slice.call(document.querySelectorAll(sel));
} }
function checkTos(tos) {
console.log("TODO checkbox for agree to terms");
return tos;
}
function run() { function run() {
console.log('hello'); console.log('hello');
@ -113,8 +108,6 @@
$$('button').map(function ($el) { $el.disabled = false; }); $$('button').map(function ($el) { $el.disabled = false; });
$('.js-toc-jwk').hidden = false; $('.js-toc-jwk').hidden = false;
$('.js-create-account').hidden = false;
$('.js-create-csr').hidden = false;
}); });
}); });

42
bundle.sh Executable file
View File

@ -0,0 +1,42 @@
#!/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 -f 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.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/

View File

@ -7,23 +7,28 @@
width: 42em; width: 42em;
height: 10em; height: 10em;
} }
/* need to word wrap the binary no space der */ /* need to word wrap the binary no space der */
.js-der-public, .js-der-private, .js-jwt{ .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 */
white-space: -o-pre-wrap; /* Opera 7 */ white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* IE */ word-wrap: break-word; /* IE */
} }
.errors { </style>
color: red; </head>
} <body>
</style> <h1>@bluecrypt/keypairs: Universal&nbsp;keygen&nbsp;&amp;&nbsp;signing&nbsp;for&nbsp;browsers</h1>
</head> <p>Keypairs.js is <strong>easy-to-use browser crypto in kilobytes, not megabytes.</strong></p>
<body>
<h1>BlueCrypt for the Browser</h1> <p>It's a modern alternative to larger, legacy libraries like PKI.js and rsasign,
<p>BlueCrypt is universal crypto for the browser. It's lightweight, fast, and based on native webcrypto. with more universal support for keygen, signing, and verification (including PKI, X509, JOSE, JWS, and JWT)
This means it's easy-to-use crypto in kilobytes, not megabytes.</p> at a fraction of the cost.</p>
<p>This is intended to be explored with your JavaScript console open.</p>
<pre><code>&lt;script src="<a href="https://rootprojects.org/keypairs/bluecrypt-keypairs.js">https://rootprojects.org/keypairs/bluecrypt-keypairs.js</a>"&gt;&lt;/script&gt;</code></pre>
<pre><code>&lt;script src="<a href="https://rootprojects.org/keypairs/bluecrypt-keypairs.min.js">https://rootprojects.org/keypairs/bluecrypt-keypairs.min.js</a>"&gt;&lt;/script&gt;</code></pre>
<a href="https://git.rootprojects.org/root/bluecrypt-keypairs.js">Documentation</a>
<h2>Keypair Generation</h2> <h2>Keypair Generation</h2>
<form class="js-keygen"> <form class="js-keygen">
@ -116,12 +121,19 @@
<pre><code class="js-jwt"></code></pre> <pre><code class="js-jwt"></code></pre>
</details> </details>
<script src="./lib/bluecrypt-encoding.js"></script> <br>
<script src="./lib/asn1-packer.js"></script> <p>Bluecrypt&trade; is a collection of lightweight, zero-dependency, libraries written in VanillaJS.
<script src="./lib/x509.js"></script> They are fast, tiny, and secure, using the native features of modern browsers where possible.</p>
<script src="./lib/ecdsa.js"></script> <br>
<script src="./lib/rsa.js"></script> <footer>View (git) source
<script src="./lib/keypairs.js"></script> <a href="https://git.rootprojects.org/root/bluecrypt-keypairs.js">@bluecrypt/keypairs</a></footer>
<script src="./app.js"></script>
</body> <script src="./lib/bluecrypt-encoding.js"></script>
<script src="./lib/asn1-packer.js"></script>
<script src="./lib/x509.js"></script>
<script src="./lib/ecdsa.js"></script>
<script src="./lib/rsa.js"></script>
<script src="./lib/keypairs.js"></script>
<script src="./app.js"></script>
</body>
</html> </html>

View File

@ -125,7 +125,7 @@ PEM.parseBlock = PEM.parseBlock || function (str) {
var der = str.split(/\n/).filter(function (line) { var der = str.split(/\n/).filter(function (line) {
return !/-----/.test(line); return !/-----/.test(line);
}).join(''); }).join('');
return { der: Enc.base64ToBuf(der) }; return { bytes: Enc.base64ToBuf(der) };
}; };
Enc.base64ToBuf = function (b64) { Enc.base64ToBuf = function (b64) {

View File

@ -66,8 +66,11 @@ Enc.numToHex = function (d) {
}; };
Enc.bufToUrlBase64 = function (u8) { Enc.bufToUrlBase64 = function (u8) {
return Enc.bufToBase64(u8) return Enc.base64ToUrlBase64(Enc.bufToBase64(u8));
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); };
Enc.base64ToUrlBase64 = function (str) {
return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
}; };
Enc.bufToBase64 = function (u8) { Enc.bufToBase64 = function (u8) {

View File

@ -186,10 +186,6 @@ Keypairs.signJws = function (opts) {
, signature: Enc.bufToUrlBase64(buf) , signature: Enc.bufToUrlBase64(buf)
}; };
console.log('Signed Base64 Msg:');
console.log(JSON.stringify(signedMsg, null, 2));
console.log('msg:', msg);
return signedMsg; return signedMsg;
}); });
} }
@ -219,10 +215,12 @@ Keypairs._sign = function (opts, payload) {
).then(function (signature) { ).then(function (signature) {
signature = new Uint8Array(signature); // ArrayBuffer -> u8 signature = new Uint8Array(signature); // ArrayBuffer -> u8
// This will come back into play for CSRs, but not for JOSE // This will come back into play for CSRs, but not for JOSE
if ('EC' === opts.jwk.kty && /x509/i.test(opts.format)) { if ('EC' === opts.jwk.kty && /x509|asn1/i.test(opts.format)) {
signature = Keypairs._ecdsaJoseSigToAsn1Sig(signature); 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.ext = true;
opts.jwk.key_ops = ops; opts.jwk.key_ops = ops;
console.log('jwk', opts.jwk);
return window.crypto.subtle.importKey( return window.crypto.subtle.importKey(
"jwk" "jwk"
, opts.jwk , opts.jwk
@ -298,7 +295,7 @@ Keypairs._ecdsaJoseSigToAsn1Sig = function (bufsig) {
if (len >= 0x80) { head.push(0x81); } if (len >= 0x80) { head.push(0x81); }
head.push(len); 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) { function setTime(time) {

View File

@ -1,13 +1,18 @@
{ {
"name": "bluecrypt-keypairs", "name": "@bluecrypt/keypairs",
"version": "0.1.1", "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", "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": { "directories": {
"lib": "lib" "lib": "lib"
}, },
"scripts": { "scripts": {
"test": "node server.js", "test": "node test.js"
"start": "node server.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",