I'm having an issue setting up a node server with let's encrypt certificates. I'm using Express to create https server like this:
var fs = require('fs');
var app = require('express')();
var https = require('https');
var server = https.createServer({
key:
fs.readFileSync('/etc/letsencrypt/live/mydomain.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/mydomain.com/cert.pem'),
ca: fs.readFileSync('/etc/letsencrypt/live/mydomain.com/chain.pem'),
requestCert: true,
rejectUnauthorized: true},app);
app.get("/express", function(request, response){
response.end("Express Response");
});
server.listen(8082);
I want to set rejectUnauthorized: true because I've read that disabling it makes the client/server communication vulnerable to MITM attack. For the client side i'm using the request module to make the https GET request like this:
var path = require('path');
var requests = require('request');
var fileSystem = require('fs');
var checkRequestOpts = {
url: "https://example.com:8082/express",
agentOtions: {
ca: fileSystem.readFileSync(__dirname + '/chain1.pem')
},
method: 'GET',
json: true,
formData: {
'x': 100,
'y': 500,
'z': 97
}
};
requests(checkRequestOpts, function(err, sr, rb)
{
if(err)
console.log('Error occured' + err);
else
{
console.log('Response: ' + rb);
}
});
However, when I run the client side app it crashes with error
Error occuredError: write EPROTO 140593052855168:error:14094410:SSL
routines:ssl3_read_bytes:sslv3 alert handshake
failure:../ssl/record/rec_layer_s3.c:1399:SSL alert number 40
The server does not have to provide content to a broswer it just needs to work with the client node app. It works when I set rejectUnauthorized: false but not when it is set to true. I'd be really thankful if someone could help me out on this or give any leads to a possible solution. Thanks!