A Root Project.
A focused, zero-dependency library that can do exactly one thing really, really well:
- Generate a Certificate Signing Requests (CSR), and sign it!
| < 300 lines of code | 1.7k gzipped | 4.7k minified | 8.5k with comments |
- Universal CSR support (RSA signing) that Just Works™
- Common Name (CN) Subject
- Subject Alternative Names (SANs / altnames)
- 2048, 3072, and 4096 bit JWK RSA
- RSASSA PKCS1 v1.5
- Zero Dependencies
- (no ASN1.js, PKI.js, forge, jrsasign - not even elliptic.js!)
- Well-Commented, Well-Documented
- Vanilla Node.js
- no school like the old school
- easy to read and understand
- See Rasha.js
- EC CSR
- See ECSDA-CSR.js
Given an array of domains it uses the first for the Common Name (CN), also known as Subject, and all of them as the Subject Alternative Names (SANs or altnames).
'use strict';var rsacsr = ;var key ="kty": "RSA""n": "m2tt...-CNw""e": "AQAB""d": "Cpfo...HMQQ""p": "ynG-...sTCE""q": "xIkA...1Q1c""dp": "tzDG...B1QE""dq": "kh5d...aL48""qi": "AlHW...HhFU";var domains = 'example.com' 'www.example.com' ;return;
The output will look something like this (but much longer):
-----BEGIN CERTIFICATE REQUEST----- MIIClTCCAX0CAQAwFjEUMBIGA1UEAwwLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3 DQEBAQUAA4IBDwAwggEKAoIBAQCba21UHE+VbDTpmYYFZUOV+OQ8AngOCdjROsPC 0KiEfMvEaEM3NQl58u6QL7G7QsEr.....3pIpUUkx5WbwJY6xDrCyFKG8ktpnee6 WjpTOBnpgHUI1/5ydnf0v29L9N+ALIJGKQxhub3iqB6EhCl93iiQtf4e7M/lzX7l c1xqsSwVZ3RQVY9bRP9NdGuW4hVvscy5ypqRtXPXQpxMnYwfi9qW5Uo= -----END CERTIFICATE REQUEST-----
If you need to convert a PEM to JWK first, do so:
var Rasha = ;Rasha
You're probably better off using OpenSSL for most commandline tasks,
rasha CLIs are useful for testing and debugging.
npm install -g rsa-csrnpm install -g rasharasha ./privkey.pem > ./privkey.jwk.jsonrsa-csr ./privkey.jwk.json example.com,www.example.com > csr.pem
keyshould be a JWK
- Need PEM support? Use Rasha.js.
- (supports PEM, DER, PKCS#1 and PKCS#8)
domainsmust be a list of strings representing domain names
- correctly handles utf-8
- you may also use punycoded, if needed
- you shouldn't use this unless you need to
- you may need to if you need utf-8 for domains, but punycode for the subject
You can double check that the CSR you get out is actually valid:
# Generate a key, if neededopenssl genrsa -out ./privkey-rsa.pkcs1.pem $keysize# Convert to JWKrasha ./privkey-rsa.pkcs1.pem > ./privkey-rsa.jwk.json# Create a CSR with your domainsnpx rsa-csr ./privkey-rsa.jwk.json example.com,www.example.com > csr.pem# Verifyopenssl req -text -noout -verify -in csr.pem
New to Crypto?
Just a heads up in case you have no idea what you're doing:
First of all, don't panic.
- RSA stands for... well, that doesn't matter, actually.
- DSA stands for Digital Signing Algorithm.
- RSA a separate standard from EC/ECDSA, but both are asymmetric
- Private keys are actually keypairs (they contain the public key)
In many cases the terms get used (and misused) interchangably, which can be confusing. You'll survive, I promise.
- PEM is just a Base64-encoded DER (think JSON as hex or base64)
- DER is an binary object notation for ASN.1 (think actual stringified JSON or XML)
- ASN.1 is object notation standard (think JSON, the standard)
- X.509 is a suite of schemas (think XLST or json-schema.org)
- PKCS#8, PKIK, SPKI are all X.509 schemas (think defining
Now forget about all that and just know this:
This library solves your problem if you need RSA something-or-other and CSR something-or-other in order to deal with SSL certificates in an internal organization.
If that's not what you're doing, you may want HTTPS and SSL through Greenlock.js, or you may be looking for something else entirely.
Goals vs Non-Goals
Rather than trying to make a generic implementation that works with everything under the sun, this library is intentionally focused on around the use case of generating certificates for ACME services (such as Let's Encrypt).
That said, please tell me if it doesn't 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) what it needs to do - No more, no less.
- Support RSA JWKs
- Support PEM and DER via Rasha.js
- PKCS#1 (traditional)
- Vanilla node.js (ECMAScript 5.1)
- No babel
- No dependencies
However, there are a few areas where I'd be willing to stretch:
- Type definition files for altscript languages
It is not a goal of this project to support any RSA profiles except those that are universally supported by browsers and are sufficiently secure (overkill is overkill).
A little copying is better than a little dependency. - Go Proverbs by Rob Pike
This code is considered small and focused enough that, rather than making it a dependency in other small projects, I personally just copy over the code.
Hence, all of these projects are MPL-2.0 licensed.