package/package.json000644 001750 001750 0000000753 12140531143013016 0ustar00000000 000000 { "name": "crypto-cacerts", "version": "0.1.0", "description": "Updates SSL certificate chain to use a directory of certificates.", "main": "crypto-cacerts.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "https://github.com/monceaux/crypto-cacerts.git" }, "keywords": [ "SSL", "crypto", "cacerts", "certificates", "HTTPS" ], "author": "Wes Monceaux", "license": "BSD" } package/README.md000644 001750 001750 0000001451 12140533715012012 0ustar00000000 000000 crypto-cacerts ============== Node has a set of trusted certificates compiled into it that is uses during SSL/HTTPS negotiations. The list of certificates can be replaced with user-specified certificates during the usage of the https module, but only for that particular https instance. Sometimes, we need to use libraries that make the HTTPS calls deep within, and cannot modify the code. This module is designed to [monkey patch](http://en.wikipedia.org/wiki/Monkey_patch) the built-in crypto module and allow you to specify a directory of existing certificates that apply to **all** HTTPS connections that are made using the underlying crypto module. Usage: require('./crypto-cacerts').cryptoPatch("/etc/ssl/certs"); This will use all of the certificates in your OpenSSL certificates directory. package/app.js000644 001750 001750 0000001540 12140533602011643 0ustar00000000 000000 var http = require('https'); var fs = require('fs'); require('./crypto-cacerts').cryptoPatch("/etc/ssl/certs"); console.log(JSON.stringify(http.globalAgent)); var options = { host: 'www.google.com', agent: false, rejectUnauthorized: true, path: '/', //cert: fs.readFileSync('/etc/ssl/certs/uit.pem') }; callback = function(response) { var str = ''; //another chunk of data has been recieved, so append it to `str` response.on('data', function (chunk) { str += chunk; }); //the whole response has been recieved, so we just print it out here response.on('end', function () { console.log(str); }); } http.request(options, callback).end(); package/crypto-cacerts.js000644 001750 001750 0000003243 12134327571014040 0ustar00000000 000000 var fs = require('fs'); var path = require('path'); var crypto = require('crypto'); var cacerts = []; var parsePEMFile = function(filename){ var pems = []; var buf = fs.readFileSync(filename, {encoding: 'utf8'}); var lines = buf.split('\n'); var foundBegin = false; var pem = ""; for(var i = 0; i < lines.length; i++){ var line = lines[i]; if(line.indexOf("-BEGIN CERTIFICATE-") >= 0){ foundBegin = true; pem = line + "\n"; } else if(line.indexOf("-END CERTIFICATE-") >= 0){ foundBegin = false; pem += line + "\n"; pems.push(new Buffer(pem)); } else if(foundBegin){ pem += line + "\n"; } } return pems; } var parsePEMDirectory = function(dirname){ var files = fs.readdirSync(dirname); var pems = []; for(var i = 0; i < files.length; i++){ var f = path.join(dirname,files[i]); var stat = fs.statSync(f); if(stat.isFile()){ pems = pems.concat(parsePEMFile(f)); } } return pems; } var createCredentials = function(options, context) { if(options.ca){ options.ca = options.ca.concat(cacerts); } else{ options.ca = cacerts; } return crypto.createCredentialsOriginal(options, context); } var cryptoPatch = function(dirname){ cacerts = parsePEMDirectory(dirname); crypto.createCredentialsOriginal = crypto.createCredentials; crypto.createCredentials = createCredentials; } exports.parsePEMDirectory = parsePEMDirectory; exports.cryptoPatch = cryptoPatch; //console.log(parsePEMDirectory("/home/monceaux/Downloads/node_test"));