2014-06-25 111 views
1

我設置了一個HTTPS node.js服務器,但我無法正確理解如何正確使用它。Node.js SSL身份驗證

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你是誰',這意味着SSL認證失敗。

我很確定我在這裏錯過了一步。

P.S.,如果它很重要,我爲加密目的設置SSL。

+0

req.client.authorized是什麼呢?也許它是不確定的,這就是爲什麼你總是得到'idk你是誰'。 – Edgar

+0

它控制檯日誌爲false –

回答