selfsigned
Advanced tools
Comparing version 0.0.4 to 0.0.5
21
index.js
@@ -31,12 +31,23 @@ // openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -subj "/CN=contoso.auth0.com" -keyout contoso.key -out contoso.cer | ||
function createResponse (tmpFiles, callback) { | ||
//openssl crl2pkcs7 -nocrl -certfile contoso1.crt -out contoso1.p7b | ||
function createResponse (options, tmpFiles, callback) { | ||
async.parallel([ | ||
function (cb) { fs.readFile(tmpFiles.tmpKeyFile, cb); }, | ||
function (cb) { fs.readFile(tmpFiles.tmpPubFile, cb); } | ||
function (cb) { fs.readFile(tmpFiles.tmpPubFile, cb); }, | ||
function (cb) { | ||
if (!options.pkcs7) return cb(); | ||
exec('openssl crl2pkcs7 -nocrl -certfile ' + tmpFiles.tmpPubFile, function (err, stdout) { | ||
cb(err, stdout); | ||
}); | ||
} | ||
], function (err, files) { | ||
if (err) return callback(err); | ||
callback(null, { | ||
var result = { | ||
privateKey: files[0].toString(), | ||
publicKey: files[1].toString() | ||
}); | ||
}; | ||
if(options.pkcs7) { | ||
result.publicPkcs7Key = files[2]; | ||
} | ||
callback(null, result); | ||
}); | ||
@@ -67,3 +78,3 @@ } | ||
createResponse(files, function (err, result) { | ||
createResponse(options, files, function (err, result) { | ||
if(err) return callback(err); | ||
@@ -70,0 +81,0 @@ |
{ | ||
"name": "selfsigned", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Generate self signed certificates private and public keys", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,10 +10,5 @@ var expect = require('chai').expect; | ||
beforeEach(function (done) { | ||
fs.mkdir(path.join(__dirname, 'tmp'), function () { | ||
fs.unlink(path.join(__dirname, 'tmp', 'test.pem'), function () { | ||
fs.unlink(path.join(__dirname, 'tmp', 'test.key'), function () { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
beforeEach(function () { | ||
rimraf.sync(path.join(__dirname, 'tmp')); | ||
fs.mkdirSync(path.join(__dirname, 'tmp')); | ||
}); | ||
@@ -32,6 +27,6 @@ | ||
var cmd = "(openssl x509 -noout -modulus -in test.pem | openssl md5 ;\\ " + | ||
"openssl rsa -noout -modulus -in test.key | openssl md5) | uniq"; | ||
it('should generate valid private public keys', function (done) { | ||
var cmd = "(openssl x509 -noout -modulus -in test.pem | openssl md5 ;\\ " + | ||
"openssl rsa -noout -modulus -in test.key | openssl md5) | uniq"; | ||
selfsigned.generate({subj: '/CN=contoso.com' }, function (err, result) { | ||
@@ -48,2 +43,20 @@ if(err) return done(err); | ||
}); | ||
it('should generate a valid pkcs7', function (done) { | ||
var cmd = "(openssl pkcs7 -noout -modulus -in test.pb7 | openssl md5 ;\\ " + | ||
"openssl rsa -noout -modulus -in test.key | openssl md5) | uniq"; | ||
selfsigned.generate({subj: '/CN=contoso.com', pkcs7: true }, | ||
function (err, result) { | ||
if(err) return done(err); | ||
fs.writeFileSync(path.join(__dirname, 'tmp', 'test.key'), result.privateKey); | ||
fs.writeFileSync(path.join(__dirname, 'tmp', 'test.pb7'), result.publicPkcs7Key); | ||
exec(cmd, function (err, stdout) { | ||
if(err) return done(err); | ||
expect(stdout.trim().split('\n').length).to.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
8719
125