nodejs version : 0.8.6
i have created a ssl csr file using using openssl with the following command:
openssl req -nodes -newkey rsa:2048 -keyout myserver.key -out myserver.csr
now i wanted to create a SSL secure server :
var fs = require("fs");
var https = require('https');
var credentials = {
key: fs.readFileSync(options.base_project_folder + 'privatekey.pem'),
cert: fs.readFileSync(options.base_project_folder + 'certificate.pem')
};
var server = https.createServer(credentials, app);
server.listen(port, address, function() {
var addr = this.address();
console.log('listening on %s:%d', addr.address, addr.port);
});
server is running , but i get : "SSL connection error"
trying to check the problem i did : openssl s_client -connect my_dns:443 // my_dns points to my nodejs server ofcourse
RESULT:
CONNECTED(00000003)
139813382997664:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:s23_lib.c:177:
no peer certificate available
No client certificate CA names sent
SSL handshake has read 0 bytes and written 226 bytes
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
can anyone help me ? i lost my way in the SSL darkness :(
To create an HTTPS server, you need two things: an SSL certificate, and built-in https Node. js module. We need to start out with a word about SSL certificates. Speaking generally, there are two kinds of certificates: those signed by a 'Certificate Authority', or CA, and 'self-signed certificates'.
Try adding the CA like so:
var credentials = {
key: fs.readFileSync(options.base_project_folder + 'privatekey.pem'),
cert: fs.readFileSync(options.base_project_folder + 'certificate.pem'),
ca: fs.readFileSync(/path/to/CA/cert)
};
The docs say that the options argument is similar to tls.createServer
I believe you need to specify a CA certificate for the signer as well. Since this is not a self signed certificate you should have received a bundle from wherever you got the cert.
A couple links that should help: http://qugstart.com/blog/node-js/install-comodo-positivessl-certificate-with-node-js/ http://www.gettingcirrius.com/2012/06/securing-nodejs-and-express-with-ssl.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With