node.js -如何检查/获取SSL证书到期日期

pieyvz9o  于 2023-06-05  发布在  Node.js
关注(0)|答案(3)|浏览(354)

我有Let's encrypt证书包。它包括私钥和证书. crt
使用node.js和node-forge(不是openssl),我如何获得证书.crt的到期日期?

cx6n0qe3

cx6n0qe31#

可以使用x509模块

var crt_pem = "<certificate in pem format which is content of your certificate.crt>";
const x509 = require('x509');
var crt_obj = x509.parseCert(crt_pem);
console.log(crt_obj.notBefore);
console.log(crt_obj.notAfter);
vx6bjr1n

vx6bjr1n2#

可以使用Node SSL Checker

$ npm install ssl-checker --save # npm i -s ssh-checker

代码中:

var sslChecker = require("ssl-checker")
sslChecker('example.com', 'GET', 443).then(result => console.info(result));

响应将如下所示:

{
"valid": true,
"days_remaining" : 90,
"valid_from" : "issue date",
"valid_to" : "expiry date"
}
ulydmbyx

ulydmbyx3#

您可以使用内置的crypto模块:

const { X509Certificate } = require('crypto');

const { validTo } = new X509Certificate(certificate);

这在v15.6及以后版本中可用。

相关问题