fix #6
This commit is contained in:
parent
409a937e81
commit
268e892a41
|
@ -9,6 +9,7 @@ var fs = require('fs')
|
||||||
, HEADER
|
, HEADER
|
||||||
, outputFile
|
, outputFile
|
||||||
, outputPemsDir
|
, outputPemsDir
|
||||||
|
, Promise = require('es6-promise').Promise
|
||||||
;
|
;
|
||||||
|
|
||||||
HEADER =
|
HEADER =
|
||||||
|
@ -143,6 +144,7 @@ function dumpCerts(certs, filename, pemsDir) {
|
||||||
|
|
||||||
fs.writeFileSync(pemsFile, pem.value);
|
fs.writeFileSync(pemsFile, pem.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.info("Wrote " + certs.length + " certificates in '"
|
console.info("Wrote " + certs.length + " certificates in '"
|
||||||
+ path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'.");
|
+ path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'.");
|
||||||
|
|
||||||
|
@ -172,38 +174,62 @@ function dumpCerts(certs, filename, pemsDir) {
|
||||||
console.info("Wrote '" + filename.replace(/'/g, "\\'") + "'.");
|
console.info("Wrote '" + filename.replace(/'/g, "\\'") + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv[2] === null) {
|
function run(filename) {
|
||||||
console.error("Error: No file specified");
|
return new Promise(function (resolve, reject) {
|
||||||
console.info("Usage: %s <outputfile>", process.argv[1]);
|
if (!filename) {
|
||||||
console.info(" where <outputfile> is the name of the file to write to, relative to %s", process.argv[1]);
|
console.error("Error: No file specified");
|
||||||
console.info("Note that a 'pems/' directory will also be created at the same location as the <outputfile>, containing individual .pem files.");
|
console.info("Usage: %s <outputfile>", process.argv[1]);
|
||||||
process.exit(3);
|
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
|
module.exports.generate = run;
|
||||||
outputFile = path.resolve(__dirname, process.argv[2]);
|
|
||||||
|
|
||||||
// pems/ output directory, in the same directory as the outputFile
|
if (require.main === module) {
|
||||||
outputPemsDir = path.resolve(outputFile, '../pems');
|
run(process.argv[2])
|
||||||
|
.then
|
||||||
|
(function () {
|
||||||
console.info("Loading latest certificates from " + CERTDB_URL);
|
// something
|
||||||
request.get(CERTDB_URL, function (error, response, body) {
|
}
|
||||||
if (error) {
|
, function (errcode) {
|
||||||
console.error(error.stacktrace);
|
process.exit(errcode);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
|
@ -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": {
|
"scripts": {
|
||||||
"test": "node ca-store-generator.js ssl-root-cas-test.js",
|
"test": "node ca-store-generator.js ssl-root-cas-test.js",
|
||||||
"prepublish": "node ca-store-generator.js ssl-root-cas.js",
|
"prepublish": "node ca-store-generator.js ssl-root-cas.js",
|
||||||
"postinstall": "node ca-store-generator.js latest.js"
|
"postinstall": "node latest.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -29,6 +29,7 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/coolaj86/node-ssl-root-cas",
|
"homepage": "https://github.com/coolaj86/node-ssl-root-cas",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"es6-promise": "^1.0.0",
|
||||||
"request": "~2.34.0"
|
"request": "~2.34.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue