Skip to content

load_certificate can't load certificate created with non-matching hostname and CN #55

@lawndoc

Description

@lawndoc

If you issue a certificate with non-matching hostname and common_name values, you cannot use load_certificate() to fetch the certificate for later use. You end up with one of the following errors:

Using the hostname as the argument value:

ownca.exceptions.OwnCAInconsistentData: Initialized CN name does not match with current existent common_name: <hostname>

Using the CN as the argument value:

ownca.exceptions.OwnCAInvalidCertificate: The certificate does not exist for 'example.com'.

Example code that will reproduce the issue:

from ownca import CertificateAuthority
from ownca.exceptions import OwnCAInconsistentData, OwnCAInvalidCertificate

CA_CERT_DIR = <enter your own for testing>

ca = CertificateAuthority(ca_storage=CA_CERT_DIR, common_name="ownca")

serverCert = ca.issue_certificate(hostname="frontend",
                                  maximum_days=825,
                                  common_name="example.com",
                                  dns_names=[],
                                  oids=certOids,
                                  public_exponent=65537,
                                  key_size=2048)

print("-- load_certificate(<hostname>) --")
try: 
    sameCert = ca.load_certificate("frontend")
except OwnCAInconsistentData as e:
    print(e)

print("-- load_certificate(<common_name>) --")
try: 
    sameCert = ca.load_certificate("example.com")
except OwnCAInvalidCertificate as e:
    print(e)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdocumentationImprovements or additions to documentationgood first issueGood for newcomers

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions