Skip to content

Commit 2cc0ec2

Browse files
author
Andrei
committed
Merge pull request nodeSolidServer#76 from nicola/SSLErrors
Fix nodeSolidServer#50, showing errors on SSL missing keys or wrong paths
2 parents b79286d + b376098 commit 2cc0ec2

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

bin/ldnode.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ if (process.platform !== 'win32') {
102102

103103
// Finally starting ldnode
104104
var ldnode = require('../index');
105-
var app = ldnode.createServer(argv);
105+
var app;
106+
try {
107+
app = ldnode.createServer(argv);
108+
} catch(e) {
109+
console.log(e.message);
110+
return 1;
111+
}
106112
app.listen(argv.port, function() {
107113
debug('LDP started on port ' + argv.port);
108114
});

index.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,39 @@ function createServer(argv) {
7878
if (opts && (opts.webid || opts.key || opts.cert) ) {
7979
debug("SSL Private Key path: " + opts.key);
8080
debug("SSL Certificate path: " + opts.cert);
81+
82+
if (!opts.cert && !opts.key) {
83+
throw new Error("Missing SSL cert and SSL key to enable WebID");
84+
}
85+
86+
if (!opts.key && opts.cert) {
87+
throw new Error("Missing path for SSL key");
88+
}
89+
90+
if (!opts.cert && opts.key) {
91+
throw new Error("Missing path for SSL cert");
92+
}
93+
94+
var key;
95+
try {
96+
key = fs.readFileSync(opts.key);
97+
} catch(e) {
98+
throw new Error("Can't find SSL key in " + opts.key);
99+
}
100+
101+
var cert;
102+
try {
103+
cert = fs.readFileSync(opts.cert);
104+
} catch(e) {
105+
throw new Error("Can't find SSL cert in " + opts.cert);
106+
}
107+
81108
var credentials = {
82-
key: fs.readFileSync(opts.key),
83-
cert: fs.readFileSync(opts.cert),
84-
requestCert: true
85-
};
109+
key: key,
110+
cert: cert,
111+
requestCert: true
112+
};
113+
86114
debug("Private Key: " + credentials.key);
87115
debug("Certificate: " + credentials.cert);
88116

0 commit comments

Comments
 (0)