Skip to content
Snippets Groups Projects
Commit 7fd2921f authored by Shane Tomlinson's avatar Shane Tomlinson
Browse files

Merge pull request #2146 from mozilla/nodejs-ephemeral-keys

Nodejs ephemeral keys

issue #1769
parents ac8f602d a4db4c7e
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
"jshint": "0.7.1" "jshint": "0.7.1"
}, },
"scripts": { "scripts": {
"postinstall": "./scripts/generate_ephemeral_keys.sh", "postinstall": "node ./scripts/generate_ephemeral_keys.js",
"test": "./scripts/test", "test": "./scripts/test",
"start": "./scripts/run_locally.js" "start": "./scripts/run_locally.js"
}, },
......
var fs = require('fs');
var path = require('path');
var child_process = require('child_process');
var existsSync = fs.existsSync || path.existsSync;
var VAR = path.join(__dirname, '../var');
var CERT = path.join(VAR, 'root.cert');
function exec(file, args, next) {
child_process.exec([file, args].join(' '), function(err, stdout, stderr) {
if (err) throw err;
if (stderr) console.error(stderr);
next && next(stdout);
});
}
// if keys already exist, do nothing
if (existsSync(CERT)) {
process.exit(0);
}
var GENERATE_KEYPAIR = path.join(__dirname, '../node_modules/.bin/generate-keypair');
var CERTIFY = path.join(__dirname, '../node_modules/.bin/certify');
if (!existsSync(GENERATE_KEYPAIR)) {
console.error('cannot find generate-keypair from jwcrypto. try: npm install');
process.exit(1);
}
if (!existsSync(CERTIFY)) {
console.error('cannot find certify from jwcrypto. try: rm -rf node_modules && npm install');
process.exit(1);
}
console.log('*** Generating ephemeral keys used for testing ***');
exec(GENERATE_KEYPAIR, '-k 256 -a rsa', function(stdout) {
if (stdout) console.log(stdout);
if (!existsSync(VAR)) fs.mkdirSync(VAR);
exec(CERTIFY, '-s key.secretkey -p key.publickey', function(cert) {
fs.writeFileSync(CERT, cert);
fs.unlinkSync('key.publickey');
fs.renameSync('key.secretkey', path.join(VAR, 'root.secretkey'));
});
});
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
VAR=$SCRIPT_DIR/../var
export PATH=$PATH:$SCRIPT_DIR/../node_modules/.bin
# if keys already exist, do nothing
if [ -f $VAR/root.cert ] ; then
exit 0
fi
GENERATE_KEYPAIR=`which generate-keypair 2> /dev/null`
CERTIFY=`which certify 2> /dev/null`
if [ ! -x "$GENERATE_KEYPAIR" ] ; then
echo "can't find generate-keypair from the jwcrypto package. try: npm install"
exit 1
fi
if [ ! -x "$CERTIFY" ] ; then
echo "can't find certify from the jwcrypto package. try: rm -rf node_modules && npm install"
exit 1
fi
echo '*** Generating ephemeral keys used for testing ***'
$GENERATE_KEYPAIR -k 256 -a rsa
mkdir -p $VAR
# public key will be stored as a self signed certificate with an embedded
# creation date (so that if the key is updated, we can revoke outstanding
# certificates - GH-599 & GH-600)
$CERTIFY -s key.secretkey -p key.publickey > $VAR/root.cert
rm key.publickey
mv key.secretkey $VAR/root.secretkey
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment