1

我正在尝试编写一个使用客户端证书身份验证作为主要身份验证方法的程序。我有一个为我的网站签署的证书,我想让这个应用程序使用它。我阅读了http://blog.nategood.com/nodejs-ssl-client-cert-auth-api-rest并打算按照此人的文章所述实现我的服务器,但我想向浏览器展示我的签名证书,然后使用我自己的证书颁发机构使用 keygen 属性对他们生成的证书进行签名。

示例代码:

var https = require("https");
var http = require("http");
var fs = require("fs");

var options = {
    key:fs.readFileSync("./myserver.key"),
    cert:fs.readFileSync("./server.crt"),
    ca:fs.readFileSync("server.ca_bundle"),
    //I want to have a separate certificate for checking client certificates here, but I would be ok with any solution to the problem.
    requestCert:true,
    rejectUnauthorized: false   
};

https.createServer(options, function (req, res) {
    res.writeHead(200, "Content-type: text/plain");
    res.write("Authorized: "+JSON.stringify(req.client.authorized))
}).listen(443);
4

0 回答 0