[Pkg-javascript-commits] [node-crypto-cacerts] 01/02: Imported Upstream version 0.1.0

Thorsten Alteholz alteholz at moszumanska.debian.org
Sun Apr 3 14:45:25 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-crypto-cacerts.

commit 4214136b9b7311b847952d0de453b8df33eeb569
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Sun Apr 3 16:45:21 2016 +0200

    Imported Upstream version 0.1.0
---
 README.md         | 12 +++++++++++
 app.js            | 31 +++++++++++++++++++++++++++
 crypto-cacerts.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json      | 22 +++++++++++++++++++
 4 files changed, 129 insertions(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..99cc084
--- /dev/null
+++ b/README.md
@@ -0,0 +1,12 @@
+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.
diff --git a/app.js b/app.js
new file mode 100644
index 0000000..4383767
--- /dev/null
+++ b/app.js
@@ -0,0 +1,31 @@
+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();
+
diff --git a/crypto-cacerts.js b/crypto-cacerts.js
new file mode 100644
index 0000000..db39651
--- /dev/null
+++ b/crypto-cacerts.js
@@ -0,0 +1,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"));
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..ed7e78a
--- /dev/null
+++ b/package.json
@@ -0,0 +1,22 @@
+{
+  "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"
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-crypto-cacerts.git



More information about the Pkg-javascript-commits mailing list