fix #6
This commit is contained in:
parent
409a937e81
commit
268e892a41
|
@ -9,6 +9,7 @@ var fs = require('fs')
|
|||
, HEADER
|
||||
, outputFile
|
||||
, outputPemsDir
|
||||
, Promise = require('es6-promise').Promise
|
||||
;
|
||||
|
||||
HEADER =
|
||||
|
@ -143,6 +144,7 @@ function dumpCerts(certs, filename, pemsDir) {
|
|||
|
||||
fs.writeFileSync(pemsFile, pem.value);
|
||||
});
|
||||
|
||||
console.info("Wrote " + certs.length + " certificates in '"
|
||||
+ path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'.");
|
||||
|
||||
|
@ -172,38 +174,62 @@ function dumpCerts(certs, filename, pemsDir) {
|
|||
console.info("Wrote '" + filename.replace(/'/g, "\\'") + "'.");
|
||||
}
|
||||
|
||||
if (process.argv[2] === null) {
|
||||
console.error("Error: No file specified");
|
||||
console.info("Usage: %s <outputfile>", process.argv[1]);
|
||||
console.info(" where <outputfile> 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 <outputfile>, containing individual .pem files.");
|
||||
process.exit(3);
|
||||
function run(filename) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (!filename) {
|
||||
console.error("Error: No file specified");
|
||||
console.info("Usage: %s <outputfile>", process.argv[1]);
|
||||
console.info(" where <outputfile> 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 <outputfile>, containing individual .pem files.");
|
||||
reject(3);
|
||||
return;
|
||||
}
|
||||
|
||||
// main (combined) output file location, relative to this script's location
|
||||
outputFile = path.resolve(__dirname, filename);
|
||||
|
||||
// pems/ output directory, in the same directory as the outputFile
|
||||
outputPemsDir = path.resolve(outputFile, '../pems');
|
||||
|
||||
|
||||
console.info("Loading latest certificates from " + CERTDB_URL);
|
||||
request.get(CERTDB_URL, function (error, response, body) {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
console.error(error.stacktrace);
|
||||
reject({ code: 1, error: error });
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.statusCode !== 200) {
|
||||
console.error("Fetching failed with status code %s", response.statusCode);
|
||||
reject({ code: 2, error: "Fetching failed with status code " + response.statusCode });
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = body.split("\n")
|
||||
, certs = parseCertData(lines)
|
||||
, pemsFile = path.join(outputPemsDir, 'mozilla-certdata.txt')
|
||||
;
|
||||
|
||||
fs.writeFileSync(pemsFile, body);
|
||||
dumpCerts(certs, outputFile, outputPemsDir);
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// main (combined) output file location, relative to this script's location
|
||||
outputFile = path.resolve(__dirname, process.argv[2]);
|
||||
module.exports.generate = run;
|
||||
|
||||
// pems/ output directory, in the same directory as the outputFile
|
||||
outputPemsDir = path.resolve(outputFile, '../pems');
|
||||
|
||||
|
||||
console.info("Loading latest certificates from " + CERTDB_URL);
|
||||
request.get(CERTDB_URL, function (error, response, body) {
|
||||
if (error) {
|
||||
console.error(error.stacktrace);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (response.statusCode !== 200) {
|
||||
console.error("Fetching failed with status code %s", response.statusCode);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
var lines = body.split("\n")
|
||||
, certs = parseCertData(lines)
|
||||
, pemsFile = path.join(outputPemsDir, 'mozilla-certdata.txt')
|
||||
;
|
||||
|
||||
fs.writeFileSync(pemsFile, body);
|
||||
dumpCerts(certs, outputFile, outputPemsDir);
|
||||
});
|
||||
if (require.main === module) {
|
||||
run(process.argv[2])
|
||||
.then
|
||||
(function () {
|
||||
// something
|
||||
}
|
||||
, function (errcode) {
|
||||
process.exit(errcode);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
|
||||
var fs = require('fs')
|
||||
, path = require('path')
|
||||
, generate = require('./ca-store-generator').generate
|
||||
, latestFile = path.join(__dirname, 'ssl-root-cas-latest.js')
|
||||
;
|
||||
|
||||
if (!fs.existsSync(latestFile)) {
|
||||
console.log('needs latest', latestFile);
|
||||
module.exports = require('./ssl-root-cas');
|
||||
generate(latestFile).then(function () {
|
||||
console.info('\n');
|
||||
console.info('##########################################################################################');
|
||||
console.info('# #');
|
||||
console.info('# Downloaded the latest Root Certificate Authorities. Restart your server to use them. #');
|
||||
console.info('# #');
|
||||
console.info('##########################################################################################');
|
||||
console.info('\n');
|
||||
}, function (e) {
|
||||
console.warn('\n\n');
|
||||
console.warn("Couldn't download the latest Root CAs, but it's not a big deal.");
|
||||
console.warn('');
|
||||
console.warn('Use "require(\'ssl-root-cas\')" instead of "require(\'ssl-root-cas/latest\')"');
|
||||
console.warn('');
|
||||
});
|
||||
} else {
|
||||
console.log('has latest');
|
||||
module.exports = require('./ssl-root-cas-latest');
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
"scripts": {
|
||||
"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"
|
||||
"postinstall": "node latest.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -29,6 +29,7 @@
|
|||
},
|
||||
"homepage": "https://github.com/coolaj86/node-ssl-root-cas",
|
||||
"dependencies": {
|
||||
"es6-promise": "^1.0.0",
|
||||
"request": "~2.34.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue