Skip to content

Commit

Permalink
Fix error handling and deprecation warnings (#93)
Browse files Browse the repository at this point in the history
This is a follow up to https://github.com/andris9/pem/pull/91, ensuring that errors from fs.unlink() calls get bubbled up correctly. This also ensures all fs.unlink() calls have a callback, which is important to avoid deprecation warnings on Node 7.
  • Loading branch information
sholladay authored and Josef Fröhle c5252118 committed Dec 1, 2016
1 parent 5b4aac7 commit 34f3fe6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 29 deletions.
20 changes: 15 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
language: node_js
sudo: false
cache:
directories:
- node_modules
node_js:
- "0.10"
- "0.12"
- "4"
- "5"
- "iojs-v1.8"
- "iojs-v2.5"
- "iojs-v3.3"
- "6"
- "7"
before_install:
- npm install -g grunt-cli
before_script:
- npm prune
script:
- grunt
after_success:
- npm run semantic-release
branches:
except:
- /^v\d+\.\d+\.\d+$/
notifications:
email:
recipients:
- github@josef-froehle.de
on_success: change
on_failure: change

53 changes: 33 additions & 20 deletions lib/pem.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,24 @@ function createPrivateKey(keyBitsize, options, callback) {

params.push(keyBitsize);

execOpenSSL(params, 'RSA PRIVATE KEY', function(error, key) {
if(clientKeyPassword) {
fs.unlink(clientKeyPassword, function() {});
execOpenSSL(params, 'RSA PRIVATE KEY', function(sslErr, key) {
function done(err) {
if (err) {
return callback(err);
}
callback(null, {
key: key
});
}
if (error) {
return callback(error);

if (clientKeyPassword) {
fs.unlink(clientKeyPassword, function(fsErr) {
done(sslErr || fsErr);
});
}
else {
done(sslErr);
}
return callback(null, {
key: key
});
});
}

Expand Down Expand Up @@ -217,20 +225,25 @@ function createCSR(options, callback) {
params.push('file:' + passwordFilePath);
}

execOpenSSL(params, 'CERTIFICATE REQUEST', tmpfiles, function(error, data) {
execOpenSSL(params, 'CERTIFICATE REQUEST', tmpfiles, function(sslErr, data) {
function done(err) {
if (err) {
return callback(err);
}
callback(null, {
csr: data,
config: config,
clientKey: options.clientKey
});
}
if (passwordFilePath) {
fs.unlink(passwordFilePath);
fs.unlink(passwordFilePath, function (fsErr) {
done(sslErr || fsErr);
});
}
if (error) {
return callback(error);
else {
done(sslErr);
}
var response = {
csr: data,
config: config,
clientKey: options.clientKey
};
return callback(null, response);

});
}

Expand Down Expand Up @@ -1002,7 +1015,7 @@ function spawnWrapper(params, tmpfiles, binary, callback) {

spawnOpenSSL(params, binary, function(err, code, stdout, stderr) {
files.forEach(function(file) {
fs.unlink(file.path);
fs.unlinkSync(file.path);
});
callback(err, code, stdout, stderr);
});
Expand Down
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
],
"name": "pem",
"description": "Create private keys and certificates with node.js and io.js",
"version": "1.8.3",
"version": "1.9.1",
"repository": {
"type": "git",
"url": "git://github.com/andris9/pem.git"
"url": "https://github.com/Dexus/pem.git"
},
"main": "lib/pem",
"scripts": {
"test": "grunt"
"test": "grunt",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"dependencies": {
"os-tmpdir": "^1.0.1",
Expand All @@ -26,11 +27,19 @@
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-nodeunit": "^0.4.1",
"nodeunit": "^0.9.1"
"nodeunit": "^0.9.1",
"semantic-release": "^6.3.2",
"semantic-release-tamia": "^1.0.0"
},
"optionalDependencies": {},
"engines": {
"node": "*",
"iojs": "*"
},
"release": {
"analyzeCommits": "semantic-release-tamia/analyzeCommits",
"generateNotes": "semantic-release-tamia/generateNotes",
"verifyRelease": "semantic-release-tamia/verifyRelease",
"verifyConditions": "./"
}
}

0 comments on commit 34f3fe6

Please sign in to comment.