diff --git a/bin/ldnode.js b/bin/ldnode.js index aedaee117..5ef7ec565 100644 --- a/bin/ldnode.js +++ b/bin/ldnode.js @@ -102,7 +102,13 @@ if (process.platform !== 'win32') { // Finally starting ldnode var ldnode = require('../index'); -var app = ldnode.createServer(argv); +var app; +try { + app = ldnode.createServer(argv); +} catch(e) { + console.log(e.message); + return 1; +} app.listen(argv.port, function() { debug('LDP started on port ' + argv.port); }); diff --git a/index.js b/index.js index f768bccc5..7fb7ed54f 100644 --- a/index.js +++ b/index.js @@ -78,11 +78,39 @@ function createServer(argv) { if (opts && (opts.webid || opts.key || opts.cert) ) { debug("SSL Private Key path: " + opts.key); debug("SSL Certificate path: " + opts.cert); + + if (!opts.cert && !opts.key) { + throw new Error("Missing SSL cert and SSL key to enable WebID"); + } + + if (!opts.key && opts.cert) { + throw new Error("Missing path for SSL key"); + } + + if (!opts.cert && opts.key) { + throw new Error("Missing path for SSL cert"); + } + + var key; + try { + key = fs.readFileSync(opts.key); + } catch(e) { + throw new Error("Can't find SSL key in " + opts.key); + } + + var cert; + try { + cert = fs.readFileSync(opts.cert); + } catch(e) { + throw new Error("Can't find SSL cert in " + opts.cert); + } + var credentials = { - key: fs.readFileSync(opts.key), - cert: fs.readFileSync(opts.cert), - requestCert: true - }; + key: key, + cert: cert, + requestCert: true + }; + debug("Private Key: " + credentials.key); debug("Certificate: " + credentials.cert);