3

I am running node v4.1.1 and npm 2.14.4 on Mac OS X. For the same express app I want to launch an http and https server. The http one runs just perfect, but the other crashes with the consequent error:

if (process.features.tls_npn && !opts.NPNProtocols) {
                                       ^
TypeError: Cannot read property 'NPNProtocols' of undefined
at new Server (https.js:13:40)
at Object.exports.createServer (https.js:37:10)

The following code runs the whole express app and invokes http methods:

#!/usr/bin/env node

var app = require('./src')
, config = require('./config')
, cmd = require('commander')
, http = require('http')
, https = require('https')
, path = require('path')

cmd
.version('0.1.42')
.option('-p, --port <n>', 'Port to start the HTTP server', parseInt)
.parse(process.argv)

// Launch server with web sockets
var server = http.createServer(app)
var sslServer = https.createServer({
    key: fs.readFileSync('ryans-ley.pem'),
    cert: fs.readFileSync('ryans-cert.pem')
}, app)

// Listen on provided port, on all network interfaces.
server.listen(config.port || cmd.port, function () {
  console.log('http marketplace started on %s:%s', 
    server.address().address,
    server.address().port)
})

sslServer.listen(443, function () {
  console.log('https marketplace started on %s:%s', 
    sslServer.address().address,
    sslServer.address().port)
})

Those certs have been generated with this guide: https://nodejs.org/api/tls.html#tls_tls_ssl.

If I run the same code, without providing options to https.createServer it does not crush. However when trying to reach https://localhost the browser answers with ERR_SSL_VERSION_OR_CIPHER_MISMATCH(chrome browser)

With curl

curl https://localhost
curl: (35) Unknown SSL protocol error in connection to localhost:-9824
jsdario
  • 6,477
  • 7
  • 41
  • 75
  • Same issue, except, that I have an "official" cert/key pair. Did you have any progress on it? – david Dec 04 '15 at 13:38
  • 1
    Yes, it happened to be a typo. It was really silent though. if key + cert are well paired and those are perfectly readable, there should be no errors. Double check paths. – jsdario Dec 18 '15 at 13:22

2 Answers2

2

Cert or chain were not valid, but the error did not reflect it. So to anyone going through the same problem, please try with other key pair.

jsdario
  • 6,477
  • 7
  • 41
  • 75
0

Setting the allowed protocols in the options solved it for me:

NPNProtocols: ['http/2.0', 'spdy', 'http/1.1', 'http/1.0']

So server instantiation would look like following in your code example:

var sslServer = https.createServer({
    key: fs.readFileSync('ryans-ley.pem'),
    cert: fs.readFileSync('ryans-cert.pem'),
    NPNProtocols: ['http/2.0', 'spdy', 'http/1.1', 'http/1.0']
}, app)
david
  • 2,529
  • 1
  • 34
  • 50