1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SSL証明書の期限取得

Last updated at Posted at 2017-07-24

SSL証明書の期限取得する関数です。戻ってくるのがJSTではないので、調整しています。

# ssl の期限の読み込み
def get_ssl_end(domain):
    import ssl
    import OpenSSL
    import datetime
    from datetime import datetime as dt
    cert = ssl.get_server_certificate((domain, 443),
    ssl_version=ssl.PROTOCOL_SSLv23)
    x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
    return((dt.strptime(str(x509.get_notAfter())[2:16],'%Y%m%d%H%M%S')  + datetime.timedelta(hours=9)).strftime('%Y %m %d'))
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?