简体   繁体   中英

Self signed cert NodeJS rejectUnauthorized

I created a structure certificates to authenticate client-> server, allowing only certificates recognized by the CA using this step by step: https://jamielinux.com/docs/openssl-certificate-authority/create-the-root-pair.html

I checked the authority with openssl, and it returns to me OK the certificate server and client, with the same CA. But by setting the parameter rejectUnauthorized to true on the server, the client can not connect.

Is there any extra parameter should I set up to allow authentication by a certificate that I generated?

---- Edit

On the client side I get the following error: ""ECONNRESET" socket hang up"

I spent a long time digging into a similar issue, and I wrote up this to talk about how to dig into various OpenSSL issues with node.js: http://www.thedreaming.org/2016/09/27/nodejs-ssl/

The short answer, though, is if you need to pass the ca parameter when creating you client connection. If you have the self-signed certificate stored in cert.pem , then the client code looks something like:

var https = require('https');
var fs = require('fs');    
var certificate = fs.readFileSync('cert.pem');

var options = {
    host: serverHost,
    port: 443,
    path: '/',
    ca: [certificate]
};
https.request(options, function(res) {
    res.pipe(process.stdout);
}).end();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM