简体   繁体   English

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

[英]node.js - how to check/get ssl certificate expiry date

I have the Let's encrypt certificate bundle.我有让我们加密证书包。 It includes the private key and certificate.crt它包括私钥和certificate.crt

Using node.js and node-forge (not openssl), how can I get the expiry date of the certificate.crt?使用 node.js 和 node-forge(不是 openssl),如何获取certificate.crt 的到期日期?

You can use Node SSL Checker 您可以使用Node SSL Checker

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

In your code: 在您的代码中:

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

the response will look like this: 响应将如下所示:

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

You can use x509 module 您可以使用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);

You can use built-in crypto module:您可以使用内置的crypto模块:

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

const { validTo } = new X509Certificate(certificate);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM