Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS https server returning ERR_SSL_PROTOCOL_ERROR using express

I'm trying to get SSL https working on my nodejs server but the browser returns a ERR_SSL_PROTOCOL_ERROR

code:

var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');

var options = {
    key: fs.readFileSync('key.pem'),
    cert: fs.readFileSync('cert.pem')
}

http.createServer(app).listen(80);
https.createServer(options, app).listen(443);
like image 280
Callum Avatar asked Jan 27 '17 11:01

Callum


1 Answers

This will happen if your key isn't generated correctly.

A lot of places will tell you to do this:

openssl genrsa -out key.pem

That will not work if you're on a Mac, and instead you need to do this to make the key length 2048:

openssl genrsa -out key.pem 2048

In summary, do these steps to make a correct key on Mac:

openssl genrsa -out key.pem 2048
openssl req -new -key key.pem -out client.csr
openssl x509 -req -in client.csr -signkey key.pem -out cert.pem
like image 101
Allan Wintersieck Avatar answered Oct 20 '22 01:10

Allan Wintersieck