Node.js SSL与节点和使用cURL的混淆
我已将安全节点服务器设置为:Node.js SSL与节点和使用cURL的混淆,node.js,ssl,curl,Node.js,Ssl,Curl,我已将安全节点服务器设置为: 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
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.key
、client.crt
和client.csr
,并用服务器的.key
和.crt
签名
现在,我想从客户端连接到我的API。在阅读cURL的工作原理时,我使用了:
curl --key client.key --cert client.crt:clientPassword mySecureSite.com\api\call
这很好用,但如果我提供任何密钥/证书或密码,或者即使我没有提供任何密钥/证书,相同的代码也可以用
有人能告诉我吗?您已将服务器设置为通过HTTPS与任何客户端通信。如果您希望将与之通信的客户端限制为具有特定证书的客户端,则需要在服务器代码中执行其他检查 下面是一个片段,让您了解需要研究的内容:
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
总是错误的。。。