Skip to main content

Python Stand-alone Library to Download SSL Certificate for Any Host™

Project description

Cert Hero

https://img.shields.io/pypi/v/cert-hero.svg https://img.shields.io/pypi/pyversions/cert-hero.svg https://github.com/rnag/cert-hero/actions/workflows/dev.yml/badge.svg Documentation Status Updates

Python Stand-alone Library to Download SSL Certificate for Any Host™

Rationale

The builtin Python module ssl can be used to retrieve a certificate from a server via getpeercert, but it’ll work only if the certificate of interest can be successfully verified (source).

If, for any reason, verification fails, like, for example, with expired or a self-signed certificate, we’ll get ssl.SSLCertVerificationError instead of the requested info.

We can work around this by asking for the certificate in the binary form:

getpeercert(binary_form=True)

But now we have to convert it, and thus we can use a third party asn1crypto module, instead of the (bulkier) cryptography module.

Usage

Retrieve the certificate for host google.com:

import json
import cert_hero

cert = cert_hero.cert_please('google.com')

print('Cert is Valid Till:', cert.not_after_date.isoformat())
print(f'Cert Details:', json.dumps(cert, indent=2), sep='\n')

Output (Sample):

Cert is Valid Till: 2023-10-28
Cert Details:
{
  "Serial": "753DD6FF20CB1B4510CB4C1EA27DA2EB",
  "Subject Name": {
    "Common Name": "*.google.com"
  },
  "Issuer Name": {
    "Country": "US",
    "State/Province": "California",
    "Organization": "Zscaler Inc.",
    "Organization Unit": "Zscaler Inc.",
    "Common Name": "Zscaler Intermediate Root CA (zscalerthree.net) (t) "
  },
  "Validity": {
    "Not After": "2023-10-28",
    "Not Before": "2023-10-14"
  },
  "Wildcard": true,
  "Signature Algorithm": "SHA256WITHRSA",
  "Key Algorithm": "RSA-2048",
  "Subject Alt Names": [
    "*.google.com",
    "*.appengine.google.com",
    "youtu.be",
    "*.youtube.com",
    ...
  ],
  "Location": "https://www.google.com/",
  "Status": 301
}

Usage as a CLI

After the installation step you can use cert-hero just typing ch in your terminal window.

The ch command allows you to retrieve the SSL certificate(s) for one or more given host.

For example:

ch google.com cnn.com

You can get help about the main command using:

ch --help

Credits

This package was created with Cookiecutter and the rnag/cookiecutter-pypackage project template.

History

0.1.0 (2023-10-16)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cert-hero-0.1.0.tar.gz (14.9 kB view hashes)

Uploaded Source

Built Distribution

cert_hero-0.1.0-py2.py3-none-any.whl (9.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page