Compare commits
No commits in common. "6ae7076185c52f7a78530671a7f22a8bdee1fdc1" and "6617d2c352930e0868d59d80f5fb5b31af77d693" have entirely different histories.
6ae7076185
...
6617d2c352
@ -14,7 +14,6 @@ RSA tools. Lightweight. Zero Dependencies. Universal compatibility.
|
|||||||
* [x] Fast and Easy RSA Key Generation
|
* [x] Fast and Easy RSA Key Generation
|
||||||
* [x] PEM-to-JWK
|
* [x] PEM-to-JWK
|
||||||
* [x] JWK-to-PEM
|
* [x] JWK-to-PEM
|
||||||
* [x] JWK thumbprint
|
|
||||||
* [x] SSH "pub" format
|
* [x] SSH "pub" format
|
||||||
* [ ] ECDSA
|
* [ ] ECDSA
|
||||||
* **Need EC or ECDSA tools?** Check out [Eckles.js](https://git.coolaj86.com/coolaj86/eckles.js)
|
* **Need EC or ECDSA tools?** Check out [Eckles.js](https://git.coolaj86.com/coolaj86/eckles.js)
|
||||||
@ -175,14 +174,6 @@ Qi49OykUCfNZeQlEz7UNNj9RGps/50+CNwIDAQAB
|
|||||||
-----END PUBLIC KEY-----
|
-----END PUBLIC KEY-----
|
||||||
```
|
```
|
||||||
|
|
||||||
## JWK Thumbprint
|
|
||||||
|
|
||||||
```js
|
|
||||||
Rasha.thumbprint({ jwk: jwk }).then(function (thumbprint) {
|
|
||||||
console.log(thumbprint);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
45
bin/rasha.js
45
bin/rasha.js
@ -8,12 +8,6 @@ var ASN1 = require('../lib/asn1.js');
|
|||||||
|
|
||||||
var infile = process.argv[2];
|
var infile = process.argv[2];
|
||||||
var format = process.argv[3];
|
var format = process.argv[3];
|
||||||
var msg = process.argv[4];
|
|
||||||
var sign;
|
|
||||||
if ('sign' === format) {
|
|
||||||
sign = true;
|
|
||||||
format = 'pkcs8';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!infile) {
|
if (!infile) {
|
||||||
infile = 'jwk';
|
infile = 'jwk';
|
||||||
@ -46,24 +40,13 @@ try {
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
var thumbprint = ('thumbprint' === format);
|
|
||||||
if (thumbprint) {
|
|
||||||
format = 'public';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('string' === typeof key) {
|
if ('string' === typeof key) {
|
||||||
if (thumbprint) {
|
|
||||||
Rasha.thumbprint({ pem: key }).then(console.info);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ('tpl' === format) {
|
if ('tpl' === format) {
|
||||||
var block = PEM.parseBlock(key);
|
var block = PEM.parseBlock(key);
|
||||||
var asn1 = ASN1.parse(block.der);
|
var asn1 = ASN1.parse(block.der);
|
||||||
ASN1.tpl(asn1);
|
ASN1.tpl(asn1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sign) { signMessage(key, msg); return; }
|
|
||||||
|
|
||||||
var pub = (-1 !== [ 'public', 'spki', 'pkix' ].indexOf(format));
|
var pub = (-1 !== [ 'public', 'spki', 'pkix' ].indexOf(format));
|
||||||
Rasha.import({ pem: key, public: (pub || format) }).then(function (jwk) {
|
Rasha.import({ pem: key, public: (pub || format) }).then(function (jwk) {
|
||||||
console.info(JSON.stringify(jwk, null, 2));
|
console.info(JSON.stringify(jwk, null, 2));
|
||||||
@ -72,38 +55,10 @@ if ('string' === typeof key) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (thumbprint) {
|
|
||||||
Rasha.thumbprint({ jwk: key }).then(console.info);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Rasha.export({ jwk: key, format: format }).then(function (pem) {
|
Rasha.export({ jwk: key, format: format }).then(function (pem) {
|
||||||
if (sign) { signMessage(pem, msg); return; }
|
|
||||||
console.info(pem);
|
console.info(pem);
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function signMessage(pem, name) {
|
|
||||||
var msg;
|
|
||||||
try {
|
|
||||||
msg = fs.readFileSync(name);
|
|
||||||
} catch(e) {
|
|
||||||
console.warn("[info] input string did not exist as a file, signing the string itself");
|
|
||||||
msg = Buffer.from(name, 'binary');
|
|
||||||
}
|
|
||||||
var crypto = require('crypto');
|
|
||||||
var sign = crypto.createSign('SHA256');
|
|
||||||
sign.write(msg)
|
|
||||||
sign.end()
|
|
||||||
var buf = sign.sign(pem);
|
|
||||||
console.log(buf.toString('base64'));
|
|
||||||
/*
|
|
||||||
Rasha.sign({ pem: pem, message: msg, alg: 'SHA256' }).then(function (sig) {
|
|
||||||
}).catch(function () {
|
|
||||||
console.error(err);
|
|
||||||
process.exit(3);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
24
lib/rasha.js
24
lib/rasha.js
@ -5,7 +5,6 @@ var SSH = require('./ssh.js');
|
|||||||
var PEM = require('./pem.js');
|
var PEM = require('./pem.js');
|
||||||
var x509 = require('./x509.js');
|
var x509 = require('./x509.js');
|
||||||
var ASN1 = require('./asn1.js');
|
var ASN1 = require('./asn1.js');
|
||||||
var Enc = require('./encoding.js');
|
|
||||||
|
|
||||||
/*global Promise*/
|
/*global Promise*/
|
||||||
RSA.generate = function (opts) {
|
RSA.generate = function (opts) {
|
||||||
@ -203,26 +202,3 @@ RSA.nueter = function (jwk) {
|
|||||||
});
|
});
|
||||||
return jwk;
|
return jwk;
|
||||||
};
|
};
|
||||||
|
|
||||||
RSA.__thumbprint = function (jwk) {
|
|
||||||
var buf = require('crypto').createHash('sha256')
|
|
||||||
// alphabetically sorted keys [ 'e', 'kty', 'n' ]
|
|
||||||
.update('{"e":"' + jwk.e + '","kty":"RSA","n":"' + jwk.n + '"}')
|
|
||||||
.digest()
|
|
||||||
;
|
|
||||||
return Enc.bufToUrlBase64(buf);
|
|
||||||
};
|
|
||||||
|
|
||||||
RSA.thumbprint = function (opts) {
|
|
||||||
return Promise.resolve().then(function () {
|
|
||||||
var jwk;
|
|
||||||
if ('RSA' === opts.kty) {
|
|
||||||
jwk = opts;
|
|
||||||
} else if (opts.jwk) {
|
|
||||||
jwk = opts.jwk;
|
|
||||||
} else {
|
|
||||||
jwk = RSA.importSync(opts);
|
|
||||||
}
|
|
||||||
return RSA.__thumbprint(jwk);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rasha",
|
"name": "rasha",
|
||||||
"version": "1.2.1",
|
"version": "1.1.0",
|
||||||
"description": "💯 PEM-to-JWK and JWK-to-PEM for RSA keys in a lightweight, zero-dependency library focused on perfect universal compatibility.",
|
"description": "💯 PEM-to-JWK and JWK-to-PEM for RSA keys in a lightweight, zero-dependency library focused on perfect universal compatibility.",
|
||||||
"homepage": "https://git.coolaj86.com/coolaj86/rasha.js",
|
"homepage": "https://git.coolaj86.com/coolaj86/rasha.js",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
8
test.sh
8
test.sh
@ -149,7 +149,7 @@ rndkey 768
|
|||||||
rndkey 1024
|
rndkey 1024
|
||||||
rndkey 2048 # first secure key size
|
rndkey 2048 # first secure key size
|
||||||
|
|
||||||
if [ "${RASHA_TEST_LARGE_KEYS}" == "true" ]; then
|
if [ "${RASHA_TEST_LARGE_KEYS}" == "true" ]; then
|
||||||
rndkey 3072
|
rndkey 3072
|
||||||
rndkey 4096 # largest reasonable key size
|
rndkey 4096 # largest reasonable key size
|
||||||
else
|
else
|
||||||
@ -164,12 +164,6 @@ echo "Pass"
|
|||||||
|
|
||||||
rm fixtures/*.1.*
|
rm fixtures/*.1.*
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Testing Thumbprints"
|
|
||||||
node bin/rasha.js ./fixtures/privkey-rsa-2048.pkcs1.pem thumbprint
|
|
||||||
node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.json thumbprint
|
|
||||||
echo "PASS"
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
echo "PASSED:"
|
echo "PASSED:"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user