Compare commits
	
		
			8 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 8211d9b6d8 | |||
| 361b0bf994 | |||
| c392b72120 | |||
| f2a9fc083a | |||
| f68f5f8d0f | |||
| bd8056ff87 | |||
| e138491328 | |||
| 579f31ebbe | 
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								README.md
									
									
									
									
									
								
							| @ -1,17 +1,15 @@ | ||||
| [RSA-CSR.js](https://git.coolaj86.com/coolaj86/rsa-csr.js) | ||||
| ========== | ||||
| 
 | ||||
| Sponsored by [Root](https://therootcompany.com), | ||||
| built for [ACME.js](https://git.coolaj86.com/coolaj86/acme.js) | ||||
| A [Root](https://therootcompany.com) Project. | ||||
| 
 | ||||
| Built for [ACME.js](https://git.coolaj86.com/coolaj86/acme.js) | ||||
| and [Greenlock.js](https://git.coolaj86.com/coolaj86/greenlock-express.js) | ||||
| 
 | ||||
| A focused, **zero-dependency** library that can do exactly one thing really, really well: | ||||
| 
 | ||||
|   * Generate a Certificate Signing Requests (CSR), and sign it! | ||||
| 
 | ||||
| Need JWK-to-PEM? Try [Rasha.js](https://git.coolaj86.com/coolaj86/rasha.js) | ||||
| 
 | ||||
| Need to generate an EC CSR? Try [ECSDA-CSR.js](https://git.coolaj86.com/coolaj86/ecdsa-csr.js) | ||||
| | < 300 lines of code | 1.7k gzipped | 4.7k minified | 8.5k with comments | | ||||
| 
 | ||||
| Features | ||||
| ======== | ||||
| @ -31,6 +29,10 @@ Features | ||||
| * [x] Vanilla Node.js | ||||
|   * no school like the old school | ||||
|   * easy to read and understand | ||||
| * [ ] JWK-to-PEM | ||||
|     * See [Rasha.js](https://git.coolaj86.com/coolaj86/rasha.js) | ||||
| * [ ] EC CSR | ||||
|     * See [ECSDA-CSR.js](https://git.coolaj86.com/coolaj86/ecdsa-csr.js) | ||||
| 
 | ||||
| Usage | ||||
| ----- | ||||
| @ -55,7 +57,7 @@ var key = { | ||||
| }; | ||||
| var domains = [ 'example.com', 'www.example.com' ]; | ||||
| 
 | ||||
| return rsacsr({ key: key, domains: domains }).then(function (csr) { | ||||
| return rsacsr({ jwk: key, domains: domains }).then(function (csr) { | ||||
|   console.log('CSR PEM:'); | ||||
|   console.log(csr); | ||||
| }); | ||||
| @ -63,7 +65,7 @@ return rsacsr({ key: key, domains: domains }).then(function (csr) { | ||||
| 
 | ||||
| The output will look something like this (but much longer): | ||||
| 
 | ||||
| ```js | ||||
| ``` | ||||
| -----BEGIN CERTIFICATE REQUEST----- | ||||
| MIIClTCCAX0CAQAwFjEUMBIGA1UEAwwLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3 | ||||
| DQEBAQUAA4IBDwAwggEKAoIBAQCba21UHE+VbDTpmYYFZUOV+OQ8AngOCdjROsPC | ||||
| @ -80,7 +82,7 @@ If you need to convert a PEM to JWK first, do so: | ||||
| ```js | ||||
| var Rasha = require('rasha'); | ||||
| 
 | ||||
| Rasha.import({ pem: '-----BEGIN RSA PRIVATE KEY-----\nMIIEpAI..." }).then(function (jwk) { | ||||
| Rasha.import({ pem: "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAI..." }).then(function (jwk) { | ||||
|   console.log(jwk); | ||||
| }) | ||||
| ``` | ||||
| @ -170,7 +172,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 | ||||
| ACME services (such as Let's Encrypt). | ||||
| 
 | ||||
| That said, [please tell me](https://git.coolaj86.com/coolaj86/rsa-csr.js/issues) if it doesn't | ||||
| That said, [please tell me](https://git.coolaj86.com/coolaj86/rsa-csr.js/issues/new) 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) | ||||
|  | ||||
| @ -15,7 +15,7 @@ try { | ||||
|   // ignore
 | ||||
| } | ||||
| 
 | ||||
| rsacsr({ key: key, domains: domains }).then(function (csr) { | ||||
| rsacsr({ jwk: key, domains: domains }).then(function (csr) { | ||||
|   // Using error so that we can redirect stdout to file
 | ||||
|   //console.error("CN=" + domains[0]);
 | ||||
|   //console.error("subjectAltName=" + domains.join(','));
 | ||||
|  | ||||
| @ -110,13 +110,13 @@ RSA.sign = function signRsa(keypem, ab) { | ||||
|   return Promise.resolve().then(function () { | ||||
|     // Signer is a stream
 | ||||
|     var sign = crypto.createSign('SHA256'); | ||||
|     sign.write(new Uint8Array(ab)); | ||||
|     sign.write(ab); | ||||
|     sign.end(); | ||||
| 
 | ||||
|     // The signature is ASN1 encoded, as it turns out
 | ||||
|     var sig = sign.sign(keypem); | ||||
| 
 | ||||
|     // Convert to a JavaScript ArrayBuffer just because
 | ||||
|     return new Uint8Array(sig.buffer.slice(sig.byteOffset, sig.byteOffset + sig.byteLength)); | ||||
|     return sig.buffer.slice(sig.byteOffset, sig.byteOffset + sig.byteLength); | ||||
|   }); | ||||
| }; | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| 'use strict'; | ||||
| 
 | ||||
| var Enc = require('./encoding.js') | ||||
| var Enc = require('./encoding.js'); | ||||
| var PEM = module.exports; | ||||
| 
 | ||||
| PEM.packBlock = function (opts) { | ||||
|  | ||||
							
								
								
									
										111
									
								
								lib/telemetry.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								lib/telemetry.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,111 @@ | ||||
| 'use strict'; | ||||
| 
 | ||||
| // We believe in a proactive approach to sustainable open source.
 | ||||
| // As part of that we make it easy for you to opt-in to following our progress
 | ||||
| // and we also stay up-to-date on telemetry such as operating system and node
 | ||||
| // version so that we can focus our efforts where they'll have the greatest impact.
 | ||||
| //
 | ||||
| // Want to learn more about our Terms, Privacy Policy, and Mission?
 | ||||
| // Check out https://therootcompany.com/legal/
 | ||||
| 
 | ||||
| var os = require('os'); | ||||
| var crypto = require('crypto'); | ||||
| var https = require('https'); | ||||
| var pkg = require('../package.json'); | ||||
| 
 | ||||
| // to help focus our efforts in the right places
 | ||||
| var data = { | ||||
|   package: pkg.name | ||||
| , version: pkg.version | ||||
| , node: process.version | ||||
| , arch: process.arch || os.arch() | ||||
| , platform: process.platform || os.platform() | ||||
| , release: os.release() | ||||
| }; | ||||
| 
 | ||||
| function addCommunityMember(opts) { | ||||
|   setTimeout(function () { | ||||
|     var req = https.request({ | ||||
|       hostname: 'api.therootcompany.com' | ||||
|     , port: 443 | ||||
|     , path: '/api/therootcompany.com/public/community' | ||||
|     , method: 'POST' | ||||
|     , headers: { 'Content-Type': 'application/json' } | ||||
|     }, function (resp) { | ||||
|       // let the data flow, so we can ignore it
 | ||||
|       resp.on('data', function () {}); | ||||
|       //resp.on('data', function (chunk) { console.log(chunk.toString()); });
 | ||||
|       resp.on('error', function () { /*ignore*/ }); | ||||
|       //resp.on('error', function (err) { console.error(err); });
 | ||||
|     }); | ||||
|     var obj = JSON.parse(JSON.stringify(data)); | ||||
|     obj.action = 'updates'; | ||||
|     try { | ||||
|       obj.ppid = ppid(obj.action); | ||||
|     } catch(e) { | ||||
|       // ignore
 | ||||
|       //console.error(e);
 | ||||
|     } | ||||
|     obj.name = opts.name || undefined; | ||||
|     obj.address = opts.email; | ||||
|     obj.community = 'node.js@therootcompany.com'; | ||||
| 
 | ||||
|     req.write(JSON.stringify(obj, 2, null)); | ||||
|     req.end(); | ||||
|     req.on('error', function () { /*ignore*/ }); | ||||
|     //req.on('error', function (err) { console.error(err); });
 | ||||
|   }, 50); | ||||
| } | ||||
| 
 | ||||
| function ping(action) { | ||||
|   setTimeout(function () { | ||||
|     var req = https.request({ | ||||
|       hostname: 'api.therootcompany.com' | ||||
|     , port: 443 | ||||
|     , path: '/api/therootcompany.com/public/ping' | ||||
|     , method: 'POST' | ||||
|     , headers: { 'Content-Type': 'application/json' } | ||||
|     }, function (resp) { | ||||
|       // let the data flow, so we can ignore it
 | ||||
|       resp.on('data', function () { }); | ||||
|       //resp.on('data', function (chunk) { console.log(chunk.toString()); });
 | ||||
|       resp.on('error', function () { /*ignore*/ }); | ||||
|       //resp.on('error', function (err) { console.error(err); });
 | ||||
|     }); | ||||
|     var obj = JSON.parse(JSON.stringify(data)); | ||||
|     obj.action = action; | ||||
|     try { | ||||
|       obj.ppid = ppid(obj.action); | ||||
|     } catch(e) { | ||||
|       // ignore
 | ||||
|       //console.error(e);
 | ||||
|     } | ||||
| 
 | ||||
|     req.write(JSON.stringify(obj, 2, null)); | ||||
|     req.end(); | ||||
|     req.on('error', function (/*e*/) { /*console.error('req.error', e);*/ }); | ||||
|   }, 50); | ||||
| } | ||||
| 
 | ||||
| // to help identify unique installs without getting
 | ||||
| // the personally identifiable info that we don't want
 | ||||
| function ppid(action) { | ||||
|   var parts = [ action, data.package, data.version, data.node, data.arch, data.platform, data.release ]; | ||||
|   var ifaces = os.networkInterfaces(); | ||||
|   Object.keys(ifaces).forEach(function (ifname) { | ||||
|     if (/^en/.test(ifname) || /^eth/.test(ifname) || /^wl/.test(ifname)) { | ||||
|       if  (ifaces[ifname] && ifaces[ifname].length) { | ||||
|         parts.push(ifaces[ifname][0].mac); | ||||
|       } | ||||
|     } | ||||
|   }); | ||||
|   return crypto.createHash('sha1').update(parts.join(',')).digest('base64'); | ||||
| } | ||||
| 
 | ||||
| module.exports.ping = ping; | ||||
| module.exports.joinCommunity = addCommunityMember; | ||||
| 
 | ||||
| if (require.main === module) { | ||||
|   ping('install'); | ||||
|   //addCommunityMember({ name: "AJ ONeal", email: 'coolaj86@gmail.com' });
 | ||||
| } | ||||
| @ -1,11 +1,17 @@ | ||||
| { | ||||
|   "name": "rsa-csr", | ||||
|   "version": "1.0.3", | ||||
|   "version": "1.0.6", | ||||
|   "description": "💯 A focused, zero-dependency library to generate a Certificate Signing Request (CSR) and sign it!", | ||||
|   "homepage": "https://git.coolaj86.com/coolaj86/rsa-csr.js", | ||||
|   "main": "index.js", | ||||
|   "bin": { | ||||
|     "rsa-csr": "bin/rsa-csr.js" | ||||
|   }, | ||||
|   "files": [ | ||||
|     "bin", | ||||
|     "fixtures", | ||||
|     "lib" | ||||
|   ], | ||||
|   "directories": { | ||||
|     "lib": "lib" | ||||
|   }, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user