Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL handshake failing with Express server under latest Node & NPM

I upgraded Node.js on my Mac to the latest, 0.12.4, as well as NPM to 2.10.1, and I re-ran npm install for my Express project.

Now, when I visit https://localhost:3001, I get "This webpage is not available / ERR_CONNECTION_REFUSED" in Chrome. When I run curl -v https://localhost:3001 I get

curl -v https://localhost:3001/
* Hostname was NOT found in DNS cache
*   Trying ::1...
* Connected to localhost (::1) port 3001 (#0)
* Server aborted the SSL handshake
* Closing connection 0
curl: (35) Server aborted the SSL handshake

This is definitely a result of upgrading Node.js, as the problem cropped up immediately after upgrading.

I start my service like this:

options = {
    key: fs.readFileSync('sslkey.pem'),
    cert: fs.readFileSync('sslcert.pem')
};
http.createServer(app).listen(settings.apiPort);
https.createServer(options, app).listen(settings.apiSSLPort);
console.log('Listening on ports: ' + settings.apiPort + ' and ' + settings.apiSSLPort);

Does anyone have any ideas what is causing this problem?

like image 958
Chad Johnson Avatar asked May 27 '15 16:05

Chad Johnson


1 Answers

I had the same problem, try this:

options = {
        key: fs.readFileSync('sslkey.pem', 'utf-8'),
        cert: fs.readFileSync('sslcert.pem', 'utf-8'),
        ca: fs.readFileSync(<CA_FILE>, 'utf-8'),
        requestCert: true,
        rejectUnauthorized: false
    };
like image 188
Mohamed Amjad LASRI Avatar answered Nov 13 '22 15:11

Mohamed Amjad LASRI