Node.js SSLauthentication

我设置了一个HTTPS node.js服务器,但是我很难理解如何正确使用它。

app.get('/test', function(req, res){ console.log('got in'); if(req.client.authorized){ res.send(200, 'certified'); }else{ res.send(200, 'idk who you are'); } }); require('https').createServer({ key: fs.readFileSync('key.pem'), cert: fs.readFileSync('cert.pem'), requestCert: true, rejectUnauthorized: false }, app).listen(8080); 

客户必须做什么才能在我的服务器上“授权”?

我可以浏览到

 https://localhost:8080/test 

它告诉我,我的证书是不可信的(没关系,SSL现在是自签名的)。 我仍然继续,但我总是去'idk你是谁',这意味着SSLauthentication失败。

我很确定我在这里错过了一步。

PS,如果它很重要,我设置SSLencryption的目的。

authorized属性是错误的,因为客户端提供的证书没有由可信任的证书颁发机构签名。 拒绝rejectUnauthorized是虚假的,连接不被拒绝,而是被标记为未授权。

看到这里 – https://github.com/joyent/node/blob/master/lib/_tls_wrap.js#L512