/usr/lib/nodejs/crypto-cacerts/crypto-cacerts.js is in node-crypto-cacerts 0.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 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"));
|