certpylot
certpylot is a Python library for managing SSL/TLS certificates with a focus on security and ease of use. It provides tools to fetch, inspect, and manipulate certificates, as well as generate and manage private keys and CSRs (Certificate Signing Requests).
Features
- Fetch and inspect SSL/TLS certificates from files or remote servers
- View certificate details: subject, issuer, validity, fingerprint, and more
- Generate and export private keys
- Create and export CSRs (Certificate Signing Requests)
- Extension and fingerprint utilities
- Simple, object-oriented API
Installation
Install via PyPI (if published):
pip install certpylot
Or install from source:
git clone https://github.com/ollie-galbraith/certpylot.git
cd certpylot
poetry install
Usage
Fetch and Inspect a Certificate from a URL
from certpylot import SSLCertificate
cert = SSLCertificate(url="https://jsonplaceholder.typicode.com")
info = cert.get()
print(info)
Load a Certificate from a File
from certpylot import SSLCertificate
cert = SSLCertificate(path="path/to/cert.pem")
info = cert.get()
print(info)
Generate a Private Key
from certpylot import PrivateKey, KeyType
key = PrivateKey(KeyType.RSA)
key._generate()
key._export("private_key.pem")
Generate a CSR
from certpylot import Csr, PrivateKey, KeyType
key = PrivateKey(KeyType.RSA)
key._generate()
csr = Csr()
csr.generate(["example.com"], key.serialized_key)
csr.export("csr.pem")
Generate a Self-Signed Certificate
from certpylot import SelfSignedCertificate, KeyType
cert = SelfSignedCertificate(key_type=KeyType.RSA)
cert.generate(
common_name="example.com",
organization="My Organization",
sans=["example.com", "*.example.com"],
valid_days=365
)
cert.serialize()
Generate SSH Key Pair
from certpylot import SSHKeyPair, KeyType
ssh_keys = SSHKeyPair(KeyType.ED25519)
ssh_keys.new(path="/path/to/key", passphrase="optional_passphrase", comment="user@host")
API Reference
SSLCertificate
SSLCertificate(path=..., url=..., port=443, certificate_type=Encoding.PEM, debug=False, allow_unverified=False)get(path=None, url=None, port=443, certificate_type=Encoding.PEM)- Get certificate info as dictionaryload(path=None, url=None, port=443, certificate_type=Encoding.PEM)- Load a certificateexport(path)- Export certificate to fileexport_pfx(path, private_key, friendly_name, pfx_password=None, private_key_passphrase=None)- Export as PKCS12/PFXconvert(path, output_type)- Convert certificate to different encoding
Properties:
subject- Certificate subject (RFC4514 format)issuer- Certificate issuer (RFC4514 format)serial_number- Serial number in hex formatfingerprint- SHA-256 fingerprintthumbprint- SHA-1 fingerprintpublic_key- Public key objectsignature_hash_algorithm- Hash algorithm nameextensions- Certificate extensionsnot_valid_before(convert_to_timezone=utc)- Validity start datetimenot_valid_after(convert_to_timezone=utc)- Validity end datetimeexpiring_in- Days until expiration
PrivateKey
PrivateKey(key_type, path=None, passphrase=None)- Create private key instancekey_typeshould beKeyType.RSA,KeyType.ED25519, orKeyType.ECDSA
_generate(key_size=4096)- Generate a new private key_export(path)- Export private key to file (permissions: 600)_serialize()- Serialize the private key to bytesload(path, passphrase=None)- Load private key from filenew(path, passphrase=None)- Generate and save a new key
Csr
Csr()- Create CSR instancegenerate(domains, private_key)- Generate CSRdomains: list of domain namesprivate_key: private key as bytes
export(path)- Export CSR to file
SelfSignedCertificate
SelfSignedCertificate(key_type=KeyType.RSA, key_size=2048, private_key=None)generate(country=None, state=None, locality=None, organization=None, organizational_unit=None, common_name=None, sans=['localhost'], valid_days=365)- Generate self-signed certificateserialize(cert_type=Encoding.PEM)- Serialize certificate to bytes
SSHKeyPair
SSHKeyPair(key_type, path=None, private_key=None)- Create SSH key pair instancenew(path, passphrase=None, comment=None)- Generate and export SSH key pair_generate(comment=None)- Generate public key from private key_export(path)- Export public key to file
Enums
KeyType:
KeyType.RSA- RSA key typeKeyType.ED25519- ED25519 key typeKeyType.ECDSA- ECDSA key type
Encoding:
Encoding.PEM- PEM encodingEncoding.DER- DER encoding
PrivateKeyFormat:
PrivateKeyFormat.TRADITIONAL_OPENSSL- Traditional OpenSSL formatPrivateKeyFormat.PKCS8- PKCS8 formatPrivateKeyFormat.OPENSSH- OpenSSH format
Testing
Run the unit tests with:
pytest
License
This project is licensed under the GPL-3.0 License.
Contributing
Contributions are welcome! Please open issues or pull requests on GitHub.
Author: Oliver Galbraith
Project Home: https://github.com/ollie-galbraith/certpylot
Metadata
Release files for certpylot 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| certpylot-0.2.1.tar.gz | 23.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| certpylot-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 48.0 kB
Release files / certpylot-0.2.1.tar.gz
| Download URL | certpylot-0.2.1.tar.gz |
|---|---|
| Size | 23.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2bb5008c8d4e9776ff4dcdf2a48b4de9bceb04ee23dc240adddddfac833512eb
|
|
BLAKE2b-256 checksum How to use checksums |
4e8e9b37cc2fca7360f80994920879e053d6e7cf2a728f1c9180030e180ce9fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.2 CPython/3.14.7 Linux/6.17.0-1022-azure
|
Release files / certpylot-0.2.1-py3-none-any.whl
| Download URL | certpylot-0.2.1-py3-none-any.whl |
|---|---|
| Size | 25.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0314cd399045d76a2995cdb450153160ea134bac6a3a7923fc549e98922f35e
|
|
BLAKE2b-256 checksum How to use checksums |
7e390853a476cac004a6778a2850dc6fa6755dd44d7374d8f1c69e6df7c1b4aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.2 CPython/3.14.7 Linux/6.17.0-1022-azure
|