v1.0.0: 💯 fully functional
This commit is contained in:
parent
73aac4bff4
commit
9f7b97f192
5 changed files with 61 additions and 29 deletions
23
README.md
23
README.md
|
@ -8,7 +8,7 @@ and [Greenlock.js](https://git.coolaj86.com/coolaj86/greenlock.js)
|
||||||
RSA tools. Lightweight. Zero Dependencies. Universal compatibility.
|
RSA tools. Lightweight. Zero Dependencies. Universal compatibility.
|
||||||
|
|
||||||
* [x] PEM-to-JWK
|
* [x] PEM-to-JWK
|
||||||
* [ ] JWK-to-PEM (in progress)
|
* [x] JWK-to-PEM
|
||||||
* [x] SSH "pub" format
|
* [x] SSH "pub" format
|
||||||
|
|
||||||
<!-- This project is fully functional and tested (and the code is pretty clean).
|
<!-- This project is fully functional and tested (and the code is pretty clean).
|
||||||
|
@ -49,7 +49,7 @@ Rasha.import({ pem: pem }).then(function (jwk) {
|
||||||
## JWK-to-PEM
|
## JWK-to-PEM
|
||||||
|
|
||||||
* [x] PKCS#1 (traditional)
|
* [x] PKCS#1 (traditional)
|
||||||
* [ ] PKCS#8, SPKI/PKIX
|
* [x] PKCS#8, SPKI/PKIX
|
||||||
* [x] 2048-bit, 4096-bit (and ostensibily all others)
|
* [x] 2048-bit, 4096-bit (and ostensibily all others)
|
||||||
* [x] SSH (RFC4716), (RFC 4716/SSH2)
|
* [x] SSH (RFC4716), (RFC 4716/SSH2)
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ Rasha.export({ jwk: jwk }).then(function (pem) {
|
||||||
-----BEGIN RSA PRIVATE KEY-----
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
MIIEpAIBAAKCAQEAm2ttVBxPlWw06ZmGBWVDlfjkPAJ4DgnY0TrDwtCohHzLxGhD
|
MIIEpAIBAAKCAQEAm2ttVBxPlWw06ZmGBWVDlfjkPAJ4DgnY0TrDwtCohHzLxGhD
|
||||||
NzUJefLukC+xu0LBKylYojT5vTkxaOhxeSYo31syu4WhxbkTBLICOFcCGMob6pSQ
|
NzUJefLukC+xu0LBKylYojT5vTkxaOhxeSYo31syu4WhxbkTBLICOFcCGMob6pSQ
|
||||||
38P8LdAIlb0pqDHxEJ9adWomjuFf0...e5cCBahfsiNtNR6WV1/iCSuINYs6uPdA
|
38P8LdAIlb0pqDHxEJ9adWomjuFf.....5cCBahfsiNtNR6WV1/iCSuINYs6uPdA
|
||||||
Jlw7hm9m8TAmFWWyfL0s7wiRvAYkQvpxetorTwHJVLabBDJ+WBOAY2enOLHIRQv+
|
Jlw7hm9m8TAmFWWyfL0s7wiRvAYkQvpxetorTwHJVLabBDJ+WBOAY2enOLHIRQv+
|
||||||
atAvHrLXjkUdzF96o0icyF6n7QzGfUPmeWGYg6BEClLS31Whe0eEVQ==
|
atAvHrLXjkUdzF96o0icyF6n7QzGfUPmeWGYg6BEClLS31Whe0eEVQ==
|
||||||
-----END RSA PRIVATE KEY-----
|
-----END RSA PRIVATE KEY-----
|
||||||
|
@ -77,8 +77,6 @@ atAvHrLXjkUdzF96o0icyF6n7QzGfUPmeWGYg6BEClLS31Whe0eEVQ==
|
||||||
|
|
||||||
### Advanced Options
|
### Advanced Options
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
`format: 'pkcs8'`:
|
`format: 'pkcs8'`:
|
||||||
|
|
||||||
The default output format `pkcs1` (RSA-specific format) is used for private keys.
|
The default output format `pkcs1` (RSA-specific format) is used for private keys.
|
||||||
|
@ -95,7 +93,7 @@ Rasha.export({ jwk: jwk, format: 'pkcs8' }).then(function (pem) {
|
||||||
-----BEGIN PRIVATE KEY-----
|
-----BEGIN PRIVATE KEY-----
|
||||||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCba21UHE+VbDTp
|
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCba21UHE+VbDTp
|
||||||
mYYFZUOV+OQ8AngOCdjROsPC0KiEfMvEaEM3NQl58u6QL7G7QsErKViiNPm9OTFo
|
mYYFZUOV+OQ8AngOCdjROsPC0KiEfMvEaEM3NQl58u6QL7G7QsErKViiNPm9OTFo
|
||||||
6HF5JijfWzK7haHFuRMEsgI4VwIYy...fLorV1ovjwKBgAJR1m8dYKemfaW8P9YZ
|
6HF5JijfWzK7haHFuRMEsgI4VwIY.....LorV1ovjwKBgAJR1m8dYKemfaW8P9YZ
|
||||||
Uux7lwIFqF+yI201HpZXX+IJK4g1izq490AmXDuGb2bxMCYVZbJ8vSzvCJG8BiRC
|
Uux7lwIFqF+yI201HpZXX+IJK4g1izq490AmXDuGb2bxMCYVZbJ8vSzvCJG8BiRC
|
||||||
+nF62itPAclUtpsEMn5YE4BjZ6c4schFC/5q0C8esteORR3MX3qjSJzIXqftDMZ9
|
+nF62itPAclUtpsEMn5YE4BjZ6c4schFC/5q0C8esteORR3MX3qjSJzIXqftDMZ9
|
||||||
Q+Z5YZiDoEQKUtLfVaF7R4RV
|
Q+Z5YZiDoEQKUtLfVaF7R4RV
|
||||||
|
@ -119,18 +117,15 @@ Rasha.export({ jwk: jwk, format: 'ssh' }).then(function (pub) {
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
ssh-rsa TODO-TODO-TODO RSA-2048@localhost
|
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCba21UHE.....Q02P1Eamz/nT4I3 rsa@localhost
|
||||||
```
|
```
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
`public: 'true'`:
|
`public: 'true'`:
|
||||||
|
|
||||||
If a private key is used as input, a private key will be output.
|
If a private key is used as input, a private key will be output.
|
||||||
|
|
||||||
If you'd like to output a public key instead you can pass `public: true`.
|
If you'd like to output a public key instead you can pass `public: true`.
|
||||||
|
|
||||||
<!--
|
|
||||||
or `format: 'spki'`.
|
or `format: 'spki'`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
@ -141,15 +136,13 @@ Rasha.export({ jwk: jwk, public: true }).then(function (pem) {
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
-----BEGIN RSA PUBLIC KEY-----
|
-----BEGIN PUBLIC KEY-----
|
||||||
MIIBCgKCAQEAm2ttVBxPlWw06ZmGBWVDlfjkPAJ4DgnY0TrDwtCohHzLxGhDNzUJ
|
MIIBCgKCAQEAm2ttVBxPlWw06ZmGBWVDlfjkPAJ4DgnY0TrDwtCohHzLxGhDNzUJ
|
||||||
efLukC+xu0LBKylYojT5vTkxaOhxe...eTmzCh2ikrwTMja7mUdBJf2bK3By5AB0
|
efLukC+xu0LBKylYojT5vTkxaOhx.....TmzCh2ikrwTMja7mUdBJf2bK3By5AB0
|
||||||
Qi49OykUCfNZeQlEz7UNNj9RGps/50+CNwIDAQAB
|
Qi49OykUCfNZeQlEz7UNNj9RGps/50+CNwIDAQAB
|
||||||
-----END RSA PUBLIC KEY-----
|
-----END PUBLIC KEY-----
|
||||||
```
|
```
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,7 @@ ASN1.tpl = function (asn1) {
|
||||||
console.log(vars.join('\n') + '\n');
|
console.log(vars.join('\n') + '\n');
|
||||||
console.log();
|
console.log();
|
||||||
console.log('function buildSchema(opts) {');
|
console.log('function buildSchema(opts) {');
|
||||||
console.log('\treturn ' + str.slice(3) + ';');
|
console.log('\treturn Enc.hexToBuf(' + str.slice(3) + ');');
|
||||||
console.log('}');
|
console.log('}');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
39
lib/x509.js
39
lib/x509.js
|
@ -114,3 +114,42 @@ x509.packPkcs1 = function (jwk) {
|
||||||
, ASN1.UInt(Enc.base64ToHex(jwk.qi))
|
, ASN1.UInt(Enc.base64ToHex(jwk.qi))
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
x509.packPkcs8 = function (jwk) {
|
||||||
|
if (!jwk.d) {
|
||||||
|
// Public RSA
|
||||||
|
return Enc.hexToBuf(ASN1('30'
|
||||||
|
, ASN1('30'
|
||||||
|
, ASN1('06', '2a864886f70d010101')
|
||||||
|
, ASN1('05')
|
||||||
|
)
|
||||||
|
, ASN1.BitStr(ASN1('30'
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.n))
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.e))
|
||||||
|
))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private RSA
|
||||||
|
return Enc.hexToBuf(ASN1('30'
|
||||||
|
, ASN1.UInt('00')
|
||||||
|
, ASN1('30'
|
||||||
|
, ASN1('06', '2a864886f70d010101')
|
||||||
|
, ASN1('05')
|
||||||
|
)
|
||||||
|
, ASN1('04'
|
||||||
|
, ASN1('30'
|
||||||
|
, ASN1.UInt('00')
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.n))
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.e))
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.d))
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.p))
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.q))
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.dp))
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.dq))
|
||||||
|
, ASN1.UInt(Enc.base64ToHex(jwk.qi))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
};
|
||||||
|
x509.packSpki = x509.packPkcs8;
|
||||||
|
|
10
package.json
10
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "rasha",
|
"name": "rasha",
|
||||||
"version": "0.8.2",
|
"version": "1.0.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",
|
||||||
|
@ -26,14 +26,14 @@
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"zero-dependency",
|
"zero-dependency",
|
||||||
"PEM-to-JWK",
|
"PEM-to-JWK",
|
||||||
|
"JWK-to-PEM",
|
||||||
"RSA",
|
"RSA",
|
||||||
"2048",
|
"2048",
|
||||||
"4096",
|
"4096",
|
||||||
"asn1",
|
"asn1",
|
||||||
"x509"
|
"x509",
|
||||||
],
|
"JWK-to-SSH",
|
||||||
"xkeywords": [
|
"PEM-to-SSH"
|
||||||
"JWK-to-PEM"
|
|
||||||
],
|
],
|
||||||
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
|
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
|
||||||
"license": "MPL-2.0"
|
"license": "MPL-2.0"
|
||||||
|
|
16
test.sh
16
test.sh
|
@ -37,16 +37,16 @@ node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.json pkcs1 > ./fixtures/pub-rsa-20
|
||||||
diff ./fixtures/pub-rsa-2048.pkcs1.pem ./fixtures/pub-rsa-2048.pkcs1.1.pem
|
diff ./fixtures/pub-rsa-2048.pkcs1.pem ./fixtures/pub-rsa-2048.pkcs1.1.pem
|
||||||
|
|
||||||
|
|
||||||
#echo ""
|
echo ""
|
||||||
#echo ""
|
echo ""
|
||||||
#echo "Testing JWK-to-PEM PKCS#8"
|
echo "Testing JWK-to-PEM PKCS#8"
|
||||||
#echo ""
|
echo ""
|
||||||
#
|
#
|
||||||
#node bin/rasha.js ./fixtures/privkey-rsa-2048.jwk.json pkcs8 > ./fixtures/privkey-rsa-2048.pkcs8.1.pem
|
node bin/rasha.js ./fixtures/privkey-rsa-2048.jwk.json pkcs8 > ./fixtures/privkey-rsa-2048.pkcs8.1.pem
|
||||||
#diff ./fixtures/privkey-rsa-2048.pkcs8.pem ./fixtures/privkey-rsa-2048.pkcs8.1.pem
|
diff ./fixtures/privkey-rsa-2048.pkcs8.pem ./fixtures/privkey-rsa-2048.pkcs8.1.pem
|
||||||
#
|
#
|
||||||
#node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.json spki > ./fixtures/pub-rsa-2048.spki.1.pem
|
node bin/rasha.js ./fixtures/pub-rsa-2048.jwk.json spki > ./fixtures/pub-rsa-2048.spki.1.pem
|
||||||
#diff ./fixtures/pub-rsa-2048.pski.pem ./fixtures/pub-rsa-2048.spki.1.pem
|
diff ./fixtures/pub-rsa-2048.spki.pem ./fixtures/pub-rsa-2048.spki.1.pem
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
Loading…
Reference in a new issue