NodeJS检查SSL认证其他主机的有效性 [英] NodeJS check validity of SSL certification other host

查看:182
本文介绍了NodeJS检查SSL认证其他主机的有效性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的服务器检查SSL证书是否在其他服务器/域上有效。有什么方法可以检查这个吗?

I want to check from my server, if the SSL certificate is valid on another server/domain. Is there any way how I can check this?

我想我需要使用 https API,但我不确定。

I think I need to use the https API from NodeJS, but I'm not sure.

推荐答案

当你使用其https库从NodeJS发出SSL请求,它将负责验证它所联系的服务器的有效性。

When you make an SSL request from NodeJS using its https library, it will take care of the job of verifying the validity of the server it's contacting.

来自 NodeJS doc


rejectUnauthorized:如果为true,则根据提供的CA列表验证服务器证书
。如果
验证失败,则会发出错误事件。验证发生在连接级别,
发送HTTP请求之前。 默认为true

此外,您可以断言 res.socket.authorized响应中的属性:

Further more, you can assert the res.socket.authorized attribute in the response:

var https = require('https');

var options = {
  host: 'google.com',
  method: 'get',
  path: '/'
};

var req = https.request(options,
  function (res) {
    console.log('certificate authorized:' + res.socket.authorized);
  });

req.end(); 

您还可以使用 res.socket.getPeerCertificate()获取服务器证书的详细信息。

You can also use res.socket.getPeerCertificate() to get detailed information on the server certificate.

这篇关于NodeJS检查SSL认证其他主机的有效性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆