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

时间:2019-06-26 10:46:56

标签: node.js ssl tls1.2

我有“让我们加密证书”捆绑包。它包括私钥和certificate.crt

使用node.js和node-forge(不是openssl),如何获取certificate.crt的到期日期?

2 个答案:

答案 0 :(得分:0)

您可以使用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"
}

答案 1 :(得分:0)

您可以使用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);