Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssl version or cipher mismatch ExpressJS

I have a problem with https in express and I don't really understand it:

This is from my last project (it works):

index.js:

var fs = require('fs');

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

var privateKey  = fs.readFileSync(__dirname + '/cert/server.key', 'utf8');
var certificate = fs.readFileSync(__dirname + '/cert/server.cert', 'utf8');

var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();

var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);

httpServer.listen(80);
httpsServer.listen(443);

//Force https
app.use(function(req, res, next) {
  if(!req.secure) {
    return res.redirect(['https://', req.get('Host'), req.url].join(''));
  }
  next();
});

This is from my current project (doesn't work):

index.js:

var fs = require('fs');

 var configRaw = fs.readFileSync(__dirname + '/config.json', 'utf8', function(err, data) {
     if(err) {
         return abort('Can not read/ find' + __dirname + '/config.json'); //FIXME
     }
 });

 var config = JSON.parse(configRaw);

 console.log('  - loading webserver script..');
 var webServer = require(__dirname + '/lib/web_server.js');

 webServer.init(config.httpPort, config.httpsPort);

web_server.js:

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

var privateKey = fs.readFileSync(__dirname + '/../ssl/server.key', 'utf8');
var certificate = fs.readFileSync(__dirname + '/../ssl/server.cert', 'utf8');

var credential = { key: privateKey, vert: certificate };
var express = require('express');
var app = express();

var httpServer = http.createServer(app);
var httpsServer = https.createServer(credential, app);

this.init = function(httpPort, httpsPort){
   httpServer.listen(httpPort);
   httpsServer.listen(httpsPort);
}

app.use(function(req, res, next) {
if(!req.secure) {
    return res.redirect(['https://', req.get('Host'), req.url].join(''));
}
   next();  
});

I am using the same certificate and key as before and never got an fs-error while reading a file or something.

But when I go to localhost via the browser I get this message: ERR_SSL_VERSION_OR_CIPHER_MISMATCH.

Please keep in mind that I am fairly new to Node.js - thank you very much in advance! ;)

like image 825
000000000000000000000 Avatar asked Dec 15 '22 11:12

000000000000000000000


1 Answers

Looks like you've got a typo:

var credential = { key: privateKey, vert: certificate };

"vert" instead of "cert" :)

like image 74
Pointy Avatar answered Dec 17 '22 00:12

Pointy