Skip to content

Instantly share code, notes, and snippets.

@nnarhinen
Last active August 29, 2015 14:10
Show Gist options
  • Save nnarhinen/f3e78051ccdd2b55bdde to your computer and use it in GitHub Desktop.
Save nnarhinen/f3e78051ccdd2b55bdde to your computer and use it in GitHub Desktop.
Openssl wrapper for nodejs
'use strict';
var spawn = require('child_process').spawn,
Promise = require('bluebird'),
_ = require('underscore'),
concat = require('concat-stream');
var o = module.exports = {};
o.req = function(privKeyPem, subjectData) {
return new Promise(function(resolve, reject) {
var subjStr = '/' + _.pairs(subjectData).map(function(p) { return p.join('='); }).join('/') + '/';
var openSsl = spawn('openssl', ['req', '-outform', 'DER', '-key', '/dev/stdin', '-subj', subjStr, '-new']);
openSsl.stdout.pipe(concat(function(str) {
if (!str.length) return;
resolve(str);
}));
openSsl.stderr.pipe(concat(function(str) {
reject(str.toString('utf8'));
}));
openSsl.stdin.write(privKeyPem);
openSsl.stdin.end();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment