From b52fc86671ae42f19fd395c5c4ab35bf490b9104 Mon Sep 17 00:00:00 2001 From: Greg MacLellan Date: Mon, 16 Jun 2014 14:11:15 -0400 Subject: [PATCH 1/3] Pass parameters to ca-store-generator.js to avoid platform differences in command-line execution of multiple commands --- ca-store-generator.js | 16 +++++++++++----- package.json | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ca-store-generator.js b/ca-store-generator.js index 26a09ea..653028a 100644 --- a/ca-store-generator.js +++ b/ca-store-generator.js @@ -6,7 +6,6 @@ var fs = require('fs') , path = require('path') , request = require('request') , CERTDB_URL = 'https://mxr.mozilla.org/nss/source/lib/ckfw/builtins/certdata.txt?raw=1' - , OUTFILE = path.join(__dirname, './ssl-root-cas-latest.js') , HEADER ; @@ -112,7 +111,7 @@ function parseCertData(lines) { return certs; } -function dumpCerts(certs) { +function dumpCerts(certs, filename) { certs.forEach(function (cert, i) { var pathname = path.join(__dirname, 'pems', 'ca-' + i + '.pem') ; @@ -123,7 +122,7 @@ function dumpCerts(certs) { + path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'."); fs.writeFileSync( - OUTFILE + filename , HEADER + 'var cas = module.exports = [\n' + certs.map(function (cert) { return cert.quasiPEM(); }).join(',\n\n') @@ -145,9 +144,16 @@ function dumpCerts(certs) { + " return module.exports;\n" + "};\n" ); - console.info("Wrote '" + OUTFILE.replace(/'/g, "\\'") + "'."); + console.info("Wrote '" + filename.replace(/'/g, "\\'") + "'."); } +//Expects a filename as the second command line argument +var outputFile = process.argv[2]; +if(outputFile == null) { + outputFile = path.join(__dirname, 'ssl-root-cas-latest.js'); +} + +console.info("Loading latest certificates from " + CERTDB_URL); request(CERTDB_URL, function (error, response, body) { if (error) { console.error(error.stacktrace); @@ -160,5 +166,5 @@ request(CERTDB_URL, function (error, response, body) { } var lines = body.split("\n"); - dumpCerts(parseCertData(lines)); + dumpCerts(parseCertData(lines), outputFile); }); diff --git a/package.json b/package.json index 04986d1..a8839e1 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "description": "The module you need to solve node's SSL woes when including a custom certificate.", "main": "ssl-root-cas", "scripts": { - "test": "node ca-store-generator.js", - "prepublish": "node ca-store-generator.js; mv ssl-root-cas-latest.js ssl-root-cas.js", - "postinstall": "node ca-store-generator.js; mv ssl-root-cas-latest.js latest.js" + "test": "node ca-store-generator.js ssl-root-cas-test.js", + "prepublish": "node ca-store-generator.js ssl-root-cas.js", + "postinstall": "node ca-store-generator.js latest.js" }, "repository": { "type": "git", From ecaf4e4eab5d5a29e7903a9e3fa3663c8dbca790 Mon Sep 17 00:00:00 2001 From: Greg MacLellan Date: Mon, 16 Jun 2014 14:21:06 -0400 Subject: [PATCH 2/3] Require outputfile command line argument, display usage info if missing, and always make relative to script location --- ca-store-generator.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ca-store-generator.js b/ca-store-generator.js index 653028a..74f3299 100644 --- a/ca-store-generator.js +++ b/ca-store-generator.js @@ -147,12 +147,16 @@ function dumpCerts(certs, filename) { console.info("Wrote '" + filename.replace(/'/g, "\\'") + "'."); } -//Expects a filename as the second command line argument -var outputFile = process.argv[2]; -if(outputFile == null) { - outputFile = path.join(__dirname, 'ssl-root-cas-latest.js'); +if (process.argv[2] == null) { + console.error("Error: No file specified"); + console.info("Usage: %s ", process.argv[1]); + console.info(" where is the name of the file to write to, relative to %s", process.argv[1]); + process.exit(3); } +//Expects a filename as the second command line argument; made relative to directory of this file +var outputFile = path.resolve(__dirname, process.argv[2]); + console.info("Loading latest certificates from " + CERTDB_URL); request(CERTDB_URL, function (error, response, body) { if (error) { From a85f6ed77f37cf5251e85668e9fa9d588057f15a Mon Sep 17 00:00:00 2001 From: Greg MacLellan Date: Mon, 16 Jun 2014 14:26:45 -0400 Subject: [PATCH 3/3] Create pems/ directory in same location as outputfile --- ca-store-generator.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ca-store-generator.js b/ca-store-generator.js index 74f3299..9f854f4 100644 --- a/ca-store-generator.js +++ b/ca-store-generator.js @@ -111,12 +111,10 @@ function parseCertData(lines) { return certs; } -function dumpCerts(certs, filename) { +function dumpCerts(certs, filename, pemsDir) { certs.forEach(function (cert, i) { - var pathname = path.join(__dirname, 'pems', 'ca-' + i + '.pem') - ; - - fs.writeFileSync(pathname, cert.quasiPEM()); + var pemsFile = path.join(pemsDir, 'ca-' + i + '.pem'); + fs.writeFileSync(pemsFile, cert.quasiPEM()); }); console.info("Wrote " + certs.length + " certificates in '" + path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'."); @@ -151,12 +149,17 @@ if (process.argv[2] == null) { console.error("Error: No file specified"); console.info("Usage: %s ", process.argv[1]); console.info(" where is the name of the file to write to, relative to %s", process.argv[1]); + console.info("Note that a 'pems/' directory will also be created at the same location as the , containing individual .pem files."); process.exit(3); } -//Expects a filename as the second command line argument; made relative to directory of this file +// main (combined) output file location, relative to this script's location var outputFile = path.resolve(__dirname, process.argv[2]); +// pems/ output directory, in the same directory as the outputFile +var outputPemsDir = path.resolve(outputFile, '../pems') + + console.info("Loading latest certificates from " + CERTDB_URL); request(CERTDB_URL, function (error, response, body) { if (error) { @@ -170,5 +173,5 @@ request(CERTDB_URL, function (error, response, body) { } var lines = body.split("\n"); - dumpCerts(parseCertData(lines), outputFile); + dumpCerts(parseCertData(lines), outputFile, outputPemsDir); });