Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d2dab4e21 | |||
| 04a38f1801 | |||
| 01544d5eef | |||
| fd8576b74e | |||
| 7ee66b8ffc |
35
README.md
35
README.md
@ -1,5 +1,4 @@
|
|||||||
# [rsa-compat.js](https://git.coolaj86.com/coolaj86/rsa-compat.js)
|
# rsa-compat.js
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
@ -8,6 +7,9 @@
|
|||||||
|
|
||||||
JavaScript RSA utils that work on Windows, Mac, and Linux with or without C compiler
|
JavaScript RSA utils that work on Windows, Mac, and Linux with or without C compiler
|
||||||
|
|
||||||
|
This now uses node-native RSA key generation and lightweight, zero-dependency solutions for key conversion.
|
||||||
|
However, it also optionally depends on `ursa` and `forge` for backwards compatibility with older node versions.
|
||||||
|
|
||||||
This was built for the [ACME.js](https://git.coolaj86.com/coolaj86/acme.js) and
|
This was built for the [ACME.js](https://git.coolaj86.com/coolaj86/acme.js) and
|
||||||
[Greenlock.js](https://git.coolaj86.com/coolaj86/greenlock.js) **Let's Encrypt** clients
|
[Greenlock.js](https://git.coolaj86.com/coolaj86/greenlock.js) **Let's Encrypt** clients
|
||||||
and is particularly suitable for building **certbot**-like clients.
|
and is particularly suitable for building **certbot**-like clients.
|
||||||
@ -22,8 +24,6 @@ node.js
|
|||||||
npm install --save rsa-compat
|
npm install --save rsa-compat
|
||||||
```
|
```
|
||||||
|
|
||||||
If you need compatibility with older versions of node, you may need to `npm install --save ursa-optional node-forge`.
|
|
||||||
|
|
||||||
### CLI
|
### CLI
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -80,9 +80,16 @@ Here's what the object might look like:
|
|||||||
, n: '/*base64 modulus n = pq*/'
|
, n: '/*base64 modulus n = pq*/'
|
||||||
, e: '/*base64 exponent (usually 65537)*/'
|
, e: '/*base64 exponent (usually 65537)*/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
, _ursa: '/*undefined or intermediate ursa object*/'
|
||||||
|
, _ursaPublic: '/*undefined or intermediate ursa object*/'
|
||||||
|
, _forge: '/*undefined or intermediate forge object*/'
|
||||||
|
, _forgePublic: '/*undefined or intermediate forge object*/'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
NOTE: this object is JSON safe as _ursa and _forge will be ignored
|
||||||
|
|
||||||
See http://crypto.stackexchange.com/questions/6593/what-data-is-saved-in-rsa-private-key to learn a little more about the meaning of the specific fields in the JWK.
|
See http://crypto.stackexchange.com/questions/6593/what-data-is-saved-in-rsa-private-key to learn a little more about the meaning of the specific fields in the JWK.
|
||||||
|
|
||||||
# API Summary
|
# API Summary
|
||||||
@ -99,7 +106,6 @@ See http://crypto.stackexchange.com/questions/6593/what-data-is-saved-in-rsa-pri
|
|||||||
* (deprecated `RSA.signJws(keypair, payload, nonce)`)
|
* (deprecated `RSA.signJws(keypair, payload, nonce)`)
|
||||||
* `RSA.generateCsrPem(keypair, names)`
|
* `RSA.generateCsrPem(keypair, names)`
|
||||||
* `RSA.generateCsrDerWeb64(keypair, names)`
|
* `RSA.generateCsrDerWeb64(keypair, names)`
|
||||||
* `RSA.thumbprint(keypair)`
|
|
||||||
|
|
||||||
`keypair` can be any object with any of these keys `publicKeyPem, privateKeyPem, publicKeyJwk, privateKeyJwk`
|
`keypair` can be any object with any of these keys `publicKeyPem, privateKeyPem, publicKeyJwk, privateKeyJwk`
|
||||||
|
|
||||||
@ -189,21 +195,6 @@ The result looks like this:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### RSA.thumbprint(keypair)
|
|
||||||
|
|
||||||
Generates a JWK thumbprint.
|
|
||||||
|
|
||||||
`RSA.thumbprint(keypair)`:
|
|
||||||
```javascript
|
|
||||||
var thumb = RSA.thumbprint(keypair);
|
|
||||||
|
|
||||||
console.log(thumb);
|
|
||||||
```
|
|
||||||
|
|
||||||
```
|
|
||||||
// kK4OXp5CT1FEkHi6WkegldmeTJecSTyJN-DxZ91nQ30
|
|
||||||
```
|
|
||||||
|
|
||||||
### RSA.generateCsr*(keypair, names)
|
### RSA.generateCsr*(keypair, names)
|
||||||
|
|
||||||
You can generate the CSR in human-readable or binary / base64 formats:
|
You can generate the CSR in human-readable or binary / base64 formats:
|
||||||
@ -266,13 +257,9 @@ but it does matter.
|
|||||||
|
|
||||||
# ChangeLog:
|
# ChangeLog:
|
||||||
|
|
||||||
* v2.0
|
|
||||||
* remove ursa and node-forge deps
|
|
||||||
* mark for node v10.11+
|
|
||||||
* v1.9
|
* v1.9
|
||||||
* consistently handle key generation across node crypto, ursa, and forge
|
* consistently handle key generation across node crypto, ursa, and forge
|
||||||
* move all other operations to rasha.js and rsa-csr.js
|
* move all other operations to rasha.js and rsa-csr.js
|
||||||
* bugfix non-standard JWKs output (which *mostly* worked)
|
|
||||||
* move dependencies to optional
|
* move dependencies to optional
|
||||||
* v1.4.0
|
* v1.4.0
|
||||||
* remove ursa as dependency (just causes confusion), but note in docs
|
* remove ursa as dependency (just causes confusion), but note in docs
|
||||||
|
|||||||
@ -20,8 +20,7 @@ module.exports = function (bitlen, exp) {
|
|||||||
return require('./generate-privkey-ursa.js')(bitlen, exp);
|
return require('./generate-privkey-ursa.js')(bitlen, exp);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (e.code !== 'MODULE_NOT_FOUND') {
|
if (e.code !== 'MODULE_NOT_FOUND') {
|
||||||
console.error("[rsa-compat] Unexpected error when using 'ursa':");
|
throw e;
|
||||||
console.error(e);
|
|
||||||
}
|
}
|
||||||
if (!oldver) {
|
if (!oldver) {
|
||||||
oldver = true;
|
oldver = true;
|
||||||
@ -48,10 +47,11 @@ module.exports = function (bitlen, exp) {
|
|||||||
try {
|
try {
|
||||||
return require('./generate-privkey-forge.js')(bitlen, exp);
|
return require('./generate-privkey-forge.js')(bitlen, exp);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
if (e.code !== 'MODULE_NOT_FOUND') {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
console.error("[ERROR] rsa-compat: could not generate a private key.");
|
console.error("[ERROR] rsa-compat: could not generate a private key.");
|
||||||
console.error("None of crypto.generateKeyPair, ursa, nor node-forge are present");
|
console.error("None of crypto.generateKeyPair, ursa, nor node-forge are present");
|
||||||
console.error("");
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -171,7 +171,7 @@ Rather than trying to make a generic implementation that works with everything u
|
|||||||
this library is intentionally focused on around the use case of generating certificates for
|
this library is intentionally focused on around the use case of generating certificates for
|
||||||
ACME services (such as Let's Encrypt).
|
ACME services (such as Let's Encrypt).
|
||||||
|
|
||||||
That said, [please tell me](https://git.coolaj86.com/coolaj86/rsa-csr.js/issues/new) if it doesn't
|
That said, [please tell me](https://git.coolaj86.com/coolaj86/rsa-csr.js/issues) if it doesn't
|
||||||
do what you need, it may make sense to add it (or otherwise, perhaps to help you create a fork).
|
do what you need, it may make sense to add it (or otherwise, perhaps to help you create a fork).
|
||||||
|
|
||||||
The primary goal of this project is for this code to do exactly (and all of)
|
The primary goal of this project is for this code to do exactly (and all of)
|
||||||
|
|||||||
@ -15,13 +15,9 @@ try {
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
var csr = rsacsr.sync({ key: key, domains: domains });
|
rsacsr({ key: key, domains: domains }).then(function (csr) {
|
||||||
console.log(csr);
|
|
||||||
/*
|
|
||||||
.then(function (csr) {
|
|
||||||
// Using error so that we can redirect stdout to file
|
// Using error so that we can redirect stdout to file
|
||||||
//console.error("CN=" + domains[0]);
|
//console.error("CN=" + domains[0]);
|
||||||
//console.error("subjectAltName=" + domains.join(','));
|
//console.error("subjectAltName=" + domains.join(','));
|
||||||
console.log(csr);
|
console.log(csr);
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|||||||
@ -136,14 +136,14 @@ CSR.toDer = function encode(opts) {
|
|||||||
RSA.signSync = function signRsaSync(keypem, ab) {
|
RSA.signSync = function signRsaSync(keypem, ab) {
|
||||||
// Signer is a stream
|
// Signer is a stream
|
||||||
var sign = crypto.createSign('SHA256');
|
var sign = crypto.createSign('SHA256');
|
||||||
sign.write(ab);
|
sign.write(new Uint8Array(ab));
|
||||||
sign.end();
|
sign.end();
|
||||||
|
|
||||||
// The signature is ASN1 encoded, as it turns out
|
// The signature is ASN1 encoded, as it turns out
|
||||||
var sig = sign.sign(keypem);
|
var sig = sign.sign(keypem);
|
||||||
|
|
||||||
// Convert to a JavaScript ArrayBuffer just because
|
// Convert to a JavaScript ArrayBuffer just because
|
||||||
return sig.buffer.slice(sig.byteOffset, sig.byteOffset + sig.byteLength);
|
return new Uint8Array(sig.buffer.slice(sig.byteOffset, sig.byteOffset + sig.byteLength));
|
||||||
};
|
};
|
||||||
RSA.sign = function signRsa(keypem, ab) {
|
RSA.sign = function signRsa(keypem, ab) {
|
||||||
return Promise.resolve().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
|
|||||||
@ -1,34 +1,64 @@
|
|||||||
{
|
{
|
||||||
"name": "rsa-csr",
|
"_from": "rsa-csr",
|
||||||
"version": "1.0.7",
|
"_id": "rsa-csr@1.0.5",
|
||||||
"description": "💯 A focused, zero-dependency library to generate a Certificate Signing Request (CSR) and sign it!",
|
"_inBundle": false,
|
||||||
"homepage": "https://git.coolaj86.com/coolaj86/rsa-csr.js",
|
"_integrity": "sha512-rmQY0RmcpLdsXEJgE1S2xBam09YVggDIqBGCJNFkhD6ONkmpSGjZ+28J6gWy+ygKHHgC7Z+OpzDLVQYowOte3A==",
|
||||||
"main": "index.js",
|
"_location": "/rsa-csr",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "tag",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "rsa-csr",
|
||||||
|
"name": "rsa-csr",
|
||||||
|
"escapedName": "rsa-csr",
|
||||||
|
"rawSpec": "",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "latest"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"#USER",
|
||||||
|
"/"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/rsa-csr/-/rsa-csr-1.0.5.tgz",
|
||||||
|
"_shasum": "ac427ae3aa16089f5f26fc93047a7d2d844b0bf4",
|
||||||
|
"_spec": "rsa-csr",
|
||||||
|
"_where": "/Volumes/Data/git.coolaj86.com/coolaj86/rsa-compat.js",
|
||||||
|
"author": {
|
||||||
|
"name": "AJ ONeal",
|
||||||
|
"email": "coolaj86@gmail.com",
|
||||||
|
"url": "https://coolaj86.com/"
|
||||||
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"rsa-csr": "bin/rsa-csr.js"
|
"rsa-csr": "bin/rsa-csr.js"
|
||||||
},
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "💯 A focused, zero-dependency library to generate a Certificate Signing Request (CSR) and sign it!",
|
||||||
|
"directories": {
|
||||||
|
"lib": "lib"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"bin",
|
"bin",
|
||||||
"fixtures",
|
"fixtures",
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"directories": {
|
"homepage": "https://git.coolaj86.com/coolaj86/rsa-csr.js",
|
||||||
"lib": "lib"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"postinstall": "node lib/telemetry.js event:install",
|
|
||||||
"test": "bash test.sh"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://git.coolaj86.com/coolaj86/rsa-csr.js"
|
|
||||||
},
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"zero-dependency",
|
"zero-dependency",
|
||||||
"CSR",
|
"CSR",
|
||||||
"RSA",
|
"RSA",
|
||||||
"x509"
|
"x509"
|
||||||
],
|
],
|
||||||
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
|
"license": "MPL-2.0",
|
||||||
"license": "MPL-2.0"
|
"main": "index.js",
|
||||||
|
"name": "rsa-csr",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.coolaj86.com/coolaj86/rsa-csr.js"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"postinstall": "node lib/telemetry.js event:install",
|
||||||
|
"test": "bash test.sh"
|
||||||
|
},
|
||||||
|
"version": "1.0.5"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rsa-compat",
|
"name": "rsa-compat",
|
||||||
"version": "2.0.8",
|
"version": "1.9.4",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.12"
|
"node": ">=10.12"
|
||||||
},
|
},
|
||||||
@ -21,7 +21,6 @@
|
|||||||
"ursa",
|
"ursa",
|
||||||
"forge",
|
"forge",
|
||||||
"certificate",
|
"certificate",
|
||||||
"csr",
|
|
||||||
"tls",
|
"tls",
|
||||||
"ssl",
|
"ssl",
|
||||||
"windows",
|
"windows",
|
||||||
@ -36,11 +35,13 @@
|
|||||||
"url": "https://git.coolaj86.com/coolaj86/rsa-compat.js/issues"
|
"url": "https://git.coolaj86.com/coolaj86/rsa-compat.js/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://git.coolaj86.com/coolaj86/rsa-compat.js#readme",
|
"homepage": "https://git.coolaj86.com/coolaj86/rsa-compat.js#readme",
|
||||||
"trulyOptionalDependencies": {
|
"optionalDependencies": {
|
||||||
"buffer-v6-polyfill": "^1.0.3",
|
|
||||||
"node-forge": "^0.7.6",
|
"node-forge": "^0.7.6",
|
||||||
"ursa-optional": "^0.9.10"
|
"ursa-optional": "^0.9.10"
|
||||||
},
|
},
|
||||||
|
"trulyOptionalDependencies": {
|
||||||
|
"buffer-v6-polyfill": "^1.0.3"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"keypairs": "^1.2.14"
|
"keypairs": "^1.2.14"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user