I am running a node.js server developed using express and it is working perfectly. I am trying to secure it using https module. I generated self-signed certificate and key using openssl, but getting the below error from firefox while trying to connect. IE is also not loading the secure page.
Secure Connection Failed
An error occurred during a connection to localhost:3001. Cannot communicate securely with peer: no common encryption algorithm(s). (Error code: ssl_error_no_cypher_overlap)
The page you are trying to view cannot be shown because the authenticity of the received data could not be verified. Please contact the web site owners to inform them of this problem.
I created the key and certificate using the below commands:
>> openssl genrsa 1024 > key.pem
>> openssl req -x509 -new -key key.pem > key-cert.pem
I am using firefox 39.0, node 0.12.4, express 4.13.1, openssl 0.9.81 and working in windows server 2008 R2 Enterprise.
This is my code. server.js is the starting point: node server.js
server.js:
var http = require('http');
var https = require('https');
var fs = require('fs');
var app = require('./app');
var credentials = {
key: fs.readFileSync('./certificate/key.pem'),
cert: fs.readFileSync('./certificate/key-cert.pem')
};
http.createServer(app).listen(3000);
https.createServer(credentials, app).listen(3001);
app.js:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var register = require('./routes/register');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//app.get("/", login.form);
app.get("/register", register.form);
app.post("/register", register.submit);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
I am trying to access the application using: https://localhost:3001/register
I am stuck in this. Please help me with a solution.