Skip to main content

Cnert is trying to be a simple API for creating TLS Certificates testing purposes.

Project description

cnert

PyPI version Documentation Status pre-commit.ci status workflow ci codecov License

Cnert - TLS Certificates for testing

Cnert is trying to be a simple API for creating TLS Certificates testing purposes.

[cnert.CA][] makes CAs, intermediate CAs and [certificates][cnert._Cert] and has several methods for introspection.

Usage

Create a root CA

>>> import cnert
>>> ca = cnert.CA()

>>> ca.is_root_ca
True

>>> ca.is_intermediate_ca
False

>>> ca.parent is None
True

Issue an intermediate CA

>>> intermediate = ca.issue_intermediate()
>>> intermediate.is_intermediate_ca
True

>>> intermediate.is_root_ca
False

>>> intermediate.parent is ca
True

Inspect the CA's certificate

>>> ca.cert
<cnert.Cert at 0x112a14c50>

>>> ca.cert.subject_attrs
NameAttrs(ORGANIZATION_NAME="Root CA")

>>> ca.cert.ca.cert.issuer_attrs
NameAttrs(ORGANIZATION_NAME="Root CA")

>>> ca.cert.not_valid_before
datetime.datetime(2023, 3, 24, 21, 27, 50, 579389

>>> ca.cert.not_valid_after
datetime.datetime(2023, 6, 23, 20, 20, 47, 999034)

>>> ca.cert.not_valid_after
datetime.datetime(2023, 6, 23, 20, 20, 47, 999034)

>>> ca.cert.serial_number
710111479237500376112637726504312543434663217892

>>> ca.cert.path_length
9

>>> ca.cert.public_key.key_size
2048

>>> ca.cert.public_key_pem
b'-----BEGIN CERTIFICATE-----\nMIIC9zCCAd+gAwIBAgIUGyCBgdyVPVGlYIJj25+x1AMQPHswDQYJKoZIhvcNAQEL\nBQAwEjEQMA4GA1UECgwHUm9vdCBDQTAeFw0yMzA1MDgwODQyNThaFw0yMzA4MDcw\nODQyNThaMBIxEDAOBgNVBAoMB1Jvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IB\nDwAwggEKAoIBAQDK13Q6dZdK17SPmplwTq4Phh7TatM4HQqONEq6+xE2VnJ9eeCh\nQYM5w5dnxIUeV10j3ODPJz5L+6IirV/e6voCWkS6Vgzh/lAVTbUVGANR26NpMnjm\n/qU0NUYuSQo5QFJuwFEx9CZ1xGTac9gspBo1jO7E9m01pRAXlr1HqTZT7mY4LNWb\nDyjKmMa/tfK0+itiKce48hZDxqy3YLnWYyIAZ+rTrf9RW5hpLb6g/KeAf3w5q55Q\nL2dCsC6flZ6NFVRm7okpawwN2tf5c451fMm3B+GtVJJMP+6lmk6MC3h++pcwOimg\nUwB8tYEPoZHuMjd1hacZcbfGFzCGAbme+BZbAgMBAAGjRTBDMB0GA1UdDgQWBBSA\nIsRH6giY94MEfhzafTd5WC2HMzASBgNVHRMBAf8ECDAGAQH/AgEJMA4GA1UdDwEB\n/wQEAwIBpjANBgkqhkiG9w0BAQsFAAOCAQEACLdxWMlmr3drMvA7GaQArzlbe/ny\nx8mThDhZP6gx+yTJ6LXk8CFc7S23JXFZVquwcV5yFa0DavaodBI3RNWknx/Yu5Lm\nM7cOByu2IuJhcEu4o+ZntLZLb7heFMXMIf01lVkYpyYyvS/NvVdu9km8f6ZvxV9r\nDyTDDMjeh+hg5l2Wwc4P6UGoMlmOruUiunsb8hiDLhD+brYBHKHqJY9pCrzJQd0v\nWEkAOsBwaTv/POO0F4VDZSfA5CqjYOkppupw9nXXfJkk9PvKuDI1G2XO7pcW1PWh\nDdGK6Wz0AXMWWbbX8LToDrFA9q7YOxGNOVPhbHZ++bDJvLNmjrtruy3UTQ==\n-----END CERTIFICATE-----\n'

Inspect the Intermediate CA

>>> intermediate.cert.subject_attrs
NameAttrs(ORGANIZATION_NAME="CA Intermediate 1")

>>> intermediate.cert.ca.cert.issuer_attrs
NameAttrs(ORGANIZATION_NAME="Root CA")

>>> intermediate.cert.path_length
8

Issue a cert from a CA

>>> cert = ca.issue_cert()

>>> cert.subject_attrs
NameAttrs(COMMON_NAME="example.com")

>>> cert.public_key
<cryptography.hazmat.backends.openssl.rsa._RSAPublicKey object at 0x10361c150>

>>> cert.public_key_pem
b'-----BEGIN CERTIFICATE-----\nMIIDITCCAgmgAwIBAgIUAx6AA8z3BqH/ICCmqOJXGI7PH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ERTIFICATE-----\n'

Issue a cert from a CA with alt names

>>> cert = ca.issue_cert("www.example.com", "host1.example.com", "example.com")

>>> cert.subject_attrs
NameAttrs(COMMON_NAME="www.example.com")

>>> cert.sans
('www.example.com', 'host1.example.com', 'example.com')

>>> cert.certificate.extensions[4]
<Extension(oid=<ObjectIdentifier(oid=2.5.29.17, name=subjectAltName)>, critical=True, value=<SubjectAlte rnativeName(<GeneralNames([<DNSName(value='www.example.com')>, <DNSName(value='host1.example.com')>, <DNSName(val ue='example.com')>])>)>)>

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

cnert-0.2.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

cnert-0.2.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file cnert-0.2.0.tar.gz.

File metadata

  • Download URL: cnert-0.2.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0

File hashes

Hashes for cnert-0.2.0.tar.gz
Algorithm Hash digest
SHA256 99edf32a3bac5a3cc8ff40976171a7182757efc030484ae0408dd1b97fffa965
MD5 054f094664308c095df010fd9e0c1b05
BLAKE2b-256 467b7fe7f3c7ba7f16e4a45f2e36b4b9a7dbe515b2605924588fae4a9f0ed4c9

See more details on using hashes here.

File details

Details for the file cnert-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cnert-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0

File hashes

Hashes for cnert-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2023a8a80e9c30995b2f7d32bf752534df31739f9fe70baab0221203877e18ae
MD5 4c2635d8a75134211c0b9afc54e8c731
BLAKE2b-256 9146eaabc8b9c53768cc8e595190cb64c42976b36746f964089c5d1becfdea06

See more details on using hashes here.

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