【问题标题】:Confusion on SSL with Node and using cURLSSL 与 Node 和使用 cURL 的混淆
【发布时间】:2015-05-18 16:37:19
【问题描述】:

我已将我的安全节点服务器设置为:

var HTTPSOptions = {
    hostname: config.hostname,
    cert: fs.readFileSync(config.ssl.cert_path),
    key: fs.readFileSync(config.ssl.key_path),
    requestCert: true,
    rejectUnauthorized: false,
    passphrase: config.ssl.ca_key_password
};
HTTPSOptions.agent = new https.Agent(HTTPSOptions);
var httpsServer = https.createServer(HTTPSOptions, app).listen(config.https_port, function () {
    console.info("HTTPS server running on %d", config.https_port);
});

我还为我的一个客户生成了client.keyclient.crtclient.csr,并使用服务器的.key.crt 对其进行了签名。

现在,我想从客户端连接到我的 API。阅读了 cURL 的工作原理,我使用了:

curl --key client.key --cert client.crt:clientPassword mySecureSite.com\api\call

这很好用,除了如果我提供任何密钥/证书或任何密码,或者即使我不提供任何密钥/证书,相同的代码也可以工作!

谁能赐教?

【问题讨论】:

    标签: node.js ssl curl


    【解决方案1】:

    您已将服务器设置为通过 HTTPS 与任何客户端进行通信。如果您希望将与之通信的客户端限制为具有特定证书的客户端,则需要在服务器代码中进行额外检查。

    Nate Good wrote a tutorial that might point you down the right path.这里有一个 sn-p,可以让您了解要研究的内容:

    https.createServer(options, function (req, res) {
        if (req.client.authorized) {
            res.writeHead(200, {"Content-Type": "application/json"});
            res.end('{"status":"approved"}');
        } else {
            res.writeHead(401, {"Content-Type": "application/json"});
            res.end('{"status":"denied"}');
        }
    }).listen(443);
    

    【讨论】:

    • 谢谢!我会读一读,看起来正是我需要的。/
    • 所以我按照上面的说明进行操作,但现在我的req.client.authorized 总是假的......
    猜你喜欢
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 2020-03-02
    相关资源
    最近更新 更多