Last active
August 29, 2015 14:10
-
-
Save nnarhinen/f3e78051ccdd2b55bdde to your computer and use it in GitHub Desktop.
Openssl wrapper for nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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