add key pairs

This commit is contained in:
AJ ONeal 2015-11-19 12:34:59 +00:00
parent 17c18a15f3
commit 6d3d334370
4 changed files with 28 additions and 0 deletions

View File

@ -82,6 +82,9 @@ cluster.on('online', function (worker) {
var config = require('../config'); var config = require('../config');
info.conf.primaryNameserver = config.primaryNameserver; info.conf.primaryNameserver = config.primaryNameserver;
info.conf.nameservers = config.nameservers; info.conf.nameservers = config.nameservers;
// TODO get this from db config instead
info.conf.privkey = config.privkey;
info.conf.pubkey = config.pubkey;
worker.send(info); worker.send(info);
}); });
} }

View File

@ -19,6 +19,7 @@ module.exports.create = function (conf, deps/*, Services*/) {
return new PromiseA(function (resolve, reject) { return new PromiseA(function (resolve, reject) {
var myApp; var myApp;
var ursa;
try { try {
// TODO dynamic requires are a no-no // TODO dynamic requires are a no-no
@ -26,9 +27,22 @@ module.exports.create = function (conf, deps/*, Services*/) {
// module.exports = { {{pkgpath}}: function () { return require({{pkgpath}}) } } // module.exports = { {{pkgpath}}: function () { return require({{pkgpath}}) } }
// requirer[pkgpath]() // requirer[pkgpath]()
myApp = express(); myApp = express();
myApp.disable('x-powered-by');
if (app.get('trust proxy')) { if (app.get('trust proxy')) {
myApp.set('trust proxy', app.get('trust proxy')); myApp.set('trust proxy', app.get('trust proxy'));
} }
if (!conf.pubkey) {
/*
return ursa.createPrivateKey(pem, password, encoding);
var pem = myKey.toPrivatePem();
return jwt.verifyAsync(token, myKey.toPublicPem(), { ignoreExpiration: false && true }).then(function (decoded) {
});
*/
ursa = require('ursa');
conf.keypair = ursa.createPrivateKey(conf.privkey, 'ascii');
conf.pubkey = ursa.createPublicKey(conf.pubkey, 'ascii'); //conf.keypair.toPublicKey();
}
// TODO give pub/priv pair for app and all public keys
route.route = require(pkgpath).create(conf, deps, myApp); route.route = require(pkgpath).create(conf, deps, myApp);
} catch(e) { } catch(e) {
reject(e); reject(e);
@ -114,6 +128,7 @@ module.exports.create = function (conf, deps/*, Services*/) {
} }
if (!route.api) { if (!route.api) {
console.error('missing route:', req.url);
nextify(new Error("no api available for this route")); nextify(new Error("no api available for this route"));
return; return;
} }

View File

@ -38,6 +38,7 @@ module.exports.create = function (webserver, info, state) {
}); });
var cstore = require('cluster-store'); var cstore = require('cluster-store');
app.disable('x-powered-by');
if (info.conf.trustProxy) { if (info.conf.trustProxy) {
console.info('[Trust Proxy]'); console.info('[Trust Proxy]');
app.set('trust proxy', ['loopback']); app.set('trust proxy', ['loopback']);
@ -161,6 +162,8 @@ module.exports.create = function (webserver, info, state) {
, externalPort: info.conf.externalPort , externalPort: info.conf.externalPort
, primaryNameserver: info.conf.primaryNameserver , primaryNameserver: info.conf.primaryNameserver
, nameservers: info.conf.nameservers , nameservers: info.conf.nameservers
, privkey: info.conf.privkey
, pubkey: info.conf.pubkey
, apiPrefix: '/api' , apiPrefix: '/api'
}; };
@ -252,6 +255,12 @@ module.exports.create = function (webserver, info, state) {
} else { } else {
res.send('<html><head><title>ERROR</title></head><body>Error</body></html>'); res.send('<html><head><title>ERROR</title></head><body>Error</body></html>');
} }
// sadly express uses arity checking
// so the fourth parameter must exist
if (false) {
next();
}
}); });
return app; return app;

View File

@ -68,6 +68,7 @@
"escape-string-regexp": "1.x", "escape-string-regexp": "1.x",
"etag": "^1.5.1", "etag": "^1.5.1",
"express": "4.x", "express": "4.x",
"express-jwt": "^3.3.0",
"express-lazy": "^1.1.1", "express-lazy": "^1.1.1",
"express-session": "^1.11.3", "express-session": "^1.11.3",
"finalhandler": "^0.3.4", "finalhandler": "^0.3.4",