How to determine SSL cert expiration date from a PEM encoded certificate?

前端 未结 9 2109
感动是毒
感动是毒 2020-11-30 16:21

If I have the actual file and a Bash shell in Mac or Linux, how can I query the cert file for when it will expire? Not a web site, but actually the certificate file itself,

9条回答
  •  感情败类
    2020-11-30 16:51

    Here's my bash command line to list multiple certificates in order of their expiration, most recently expiring first.

    for pem in /etc/ssl/certs/*.pem; do 
       printf '%s: %s\n' \
          "$(date --date="$(openssl x509 -enddate -noout -in "$pem"|cut -d= -f 2)" --iso-8601)" \
          "$pem"
    done | sort
    

    Sample output:

    2015-12-16: /etc/ssl/certs/Staat_der_Nederlanden_Root_CA.pem
    2016-03-22: /etc/ssl/certs/CA_Disig.pem
    2016-08-14: /etc/ssl/certs/EBG_Elektronik_Sertifika_Hizmet_S.pem
    

提交回复
热议问题