大佬教程收集整理的这篇文章主要介绍了Node.js:访问客户端证书,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
简化示例:
/** server setup **/ var serverOptions = { key: fs.readFileSync('certs/server.key'),cert: fs.readFileSync('certs/server.crt'),ca: [fs.readFileSync('certs/ca.crt'),fs.readFileSync('certs/bar.cer'),fs.readFileSync('certs/foo.cer')],requestCert: true }; https.createServer(serverOptions,app).listen(SERVER_PORT,'',null,function () { var host = this.address().address; var port = this.address().port; console.log('listening at http://%s:%s',host,port); });
一切都按预期工作,以下代码打印客户端证书的详细信息.
app.get('/',function (req,res) { /*** Dump ***/ res.contentType('application/json'); res.send(util.inspect(req.socket.getPeerCertificate(true),{Colors: truE})); });
但是,我希望能够使用在serverA中获得的此客户端证书,向另一个名为“server B”的服务器发出请求.
options = { hostname: 'localhost',port: '3010',path: '/',method: 'POST',headers: { 'Content-Type': 'text/xml;charset=UTF-8','Content-Length': serverResponse.length,'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',},cert: clientCertificate }; var req = https.request(options,function (res) { console.log('statusCode: ',res.statusCodE); console.log('headers: ',res.headers); res.on('data',function(d) { callBACk(d); }); });
问题是我没有找到使用getPeerCertificate函数获取正确的X509证书的方法,该函数返回证书的“自定义”对象表示.
如official documentation中所述,cert参数必须提供以下数据:
有没有办法以正确的格式获取客户端证书?
以上是大佬教程为你收集整理的Node.js:访问客户端证书全部内容,希望文章能够帮你解决Node.js:访问客户端证书所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。