Comparing version 1.5.0 to 1.6.0
'use strict'; | ||
var spawn = require('child_process').spawn, | ||
os = require('os'), | ||
pathlib = require('path'), | ||
fs = require('fs'), | ||
net = require('net'), | ||
crypto = require('crypto'), | ||
which = require('which'), | ||
pathOpenSSL, | ||
tempDir = process.env.PEMJS_TMPDIR || (os.tmpdir || os.tmpDir) && (os.tmpdir || os.tmpDir)() || '/tmp'; | ||
var spawn = require('child_process').spawn; | ||
var os = require('os'); | ||
var pathlib = require('path'); | ||
var fs = require('fs'); | ||
var net = require('net'); | ||
var crypto = require('crypto'); | ||
var which = require('which'); | ||
var pathOpenSSL; | ||
var tempDir = process.env.PEMJS_TMPDIR || (os.tmpdir || os.tmpDir) && (os.tmpdir || os.tmpDir)() || '/tmp'; | ||
module.exports.createPrivateKey = createPrivateKey; | ||
module.exports.createDhparam = createDhparam; | ||
module.exports.createCSR = createCSR; | ||
@@ -54,3 +55,34 @@ module.exports.createCertificate = createCertificate; | ||
/** | ||
* Creates a dhparam key | ||
* | ||
* @param {Number} [keyBitsize=512] Size of the key, defaults to 512bit | ||
* @param {Function} callback Callback function with an error object and {dhparam} | ||
*/ | ||
function createDhparam(keyBitsize, callback) { | ||
if (!callback && typeof keyBitsize === 'function') { | ||
callback = keyBitsize; | ||
keyBitsize = undefined; | ||
} | ||
keyBitsize = Number(keyBitsize) || 512; | ||
var params = ['dhparam', | ||
'-outform', | ||
'PEM', | ||
keyBitsize | ||
]; | ||
execOpenSSL(params, 'DH PARAMETERS', function(error, dhparam) { | ||
if (error) { | ||
return callback(error); | ||
} | ||
return callback(null, { | ||
dhparam: dhparam | ||
}); | ||
}); | ||
} | ||
/** | ||
* Creates a Certificate Signing Request | ||
@@ -383,3 +415,11 @@ * | ||
*/ | ||
function getFingerprint(certificate, callback) { | ||
function getFingerprint(certificate, hash, callback) { | ||
if (!callback && typeof hash === 'function') { | ||
callback = hash; | ||
hash = undefined; | ||
} | ||
hash = hash || 'sha1'; | ||
var params = ['x509', | ||
@@ -389,3 +429,4 @@ '-in', | ||
'-fingerprint', | ||
'-noout' | ||
'-noout', | ||
'-' + hash | ||
]; | ||
@@ -392,0 +433,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Create private keys and certificates with node.js", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"repository": { | ||
@@ -13,3 +13,3 @@ "type": "git", | ||
"scripts": { | ||
"test": "nodeunit test" | ||
"test": "grunt" | ||
}, | ||
@@ -20,3 +20,5 @@ "dependencies": { | ||
"devDependencies": { | ||
"nodeunit": "*" | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-jshint": "^0.11.0", | ||
"grunt-contrib-nodeunit": "^0.4.1" | ||
}, | ||
@@ -23,0 +25,0 @@ "optionalDependencies": {}, |
@@ -49,2 +49,13 @@ pem | ||
### Create a dhparam key | ||
Use `createDhparam` for creating dhparam keys | ||
pem.createDhparam(keyBitsize, callback) | ||
Where | ||
* **keyBitsize** is an optional size of the key, defaults to 512 (bit) | ||
* **callback** is a callback function with an error object and `{dhparam}` | ||
### Create a private key | ||
@@ -135,5 +146,5 @@ | ||
Use `getFingerprint` to get the SHA1 fingerprint for a certificate | ||
Use `getFingerprint` to get the default SHA1 fingerprint for a certificate | ||
pem.getFingerprint(certificate, callback) | ||
pem.getFingerprint(certificate, [hash,] callback) | ||
@@ -143,2 +154,3 @@ Where | ||
* **certificate** is a PEM encoded certificate | ||
* **hash** is a hash function to use (either `md5`, `sha1` or `sha256`, defaults to `sha1`) | ||
* **callback** is a callback function with an error object and `{fingerprint}` | ||
@@ -145,0 +157,0 @@ |
@@ -14,2 +14,28 @@ 'use strict'; | ||
'Create default sized dhparam key': function(test) { | ||
pem.createDhparam(function(error, data) { | ||
var dhparam = (data && data.dhparam || '').toString(); | ||
test.ifError(error); | ||
test.ok(dhparam); | ||
test.ok(dhparam.match(/^\n*\-\-\-\-\-BEGIN DH PARAMETERS\-\-\-\-\-\n/)); | ||
test.ok(dhparam.match(/\n\-\-\-\-\-END DH PARAMETERS\-\-\-\-\-\n*$/)); | ||
test.ok(dhparam.trim().length > 150 && dhparam.trim().length < 160); | ||
test.ok(fs.readdirSync('./tmp').length === 0); | ||
test.done(); | ||
}); | ||
}, | ||
'Create 2048bit dhparam key': function(test) { | ||
pem.createDhparam(2048, function(error, data) { | ||
var dhparam = (data && data.dhparam || '').toString(); | ||
test.ifError(error); | ||
test.ok(dhparam); | ||
test.ok(dhparam.match(/^\n*\-\-\-\-\-BEGIN DH PARAMETERS\-\-\-\-\-\n/)); | ||
test.ok(dhparam.match(/\n\-\-\-\-\-END DH PARAMETERS\-\-\-\-\-\n*$/)); | ||
test.ok(dhparam.trim().length > 420 && dhparam.trim().length < 430); | ||
test.ok(fs.readdirSync('./tmp').length === 0); | ||
test.done(); | ||
}); | ||
}, | ||
'Create default sized Private key': function(test) { | ||
@@ -16,0 +42,0 @@ pem.createPrivateKey(function(error, data) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44831
9
991
181
3