Skip to content

Commit

Permalink
Remove prefix 16 from organization number in Expitrust certs
Browse files Browse the repository at this point in the history
  • Loading branch information
johanlundberg committed Mar 13, 2024
1 parent 36a8691 commit 82583e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/auth_server/cert_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def cert_within_validity_period(cert: Certificate) -> bool:
check if certificate is within the validity period
"""
cert_fingerprint = rfc8705_fingerprint(cert)
now = datetime.utcnow()
now = datetime.utcnow() # datetimes in cert are not timezone aware
if now < cert.not_valid_before:
logger.error(f"Certificate {cert_fingerprint} not valid before {cert.not_valid_before}")
return False
Expand Down Expand Up @@ -117,13 +117,14 @@ def get_org_id_from_cert(cert: Certificate, ca_name: str) -> Optional[str]:

def get_org_id_expitrust(cert: Certificate) -> Optional[str]:
"""
The org number is just the serial number of the certificate.
The org number is the serial number of the certificate with prefix 16.
"""
cert_fingerprint = rfc8705_fingerprint(cert)
serial_number = get_oid_for_name(x509_name=cert.subject, oid=OID_SERIAL_NUMBER)
if serial_number is None:
logger.error(f"certificate {cert_fingerprint} has no subject serial number")
return serial_number
return None
return serial_number.removeprefix("16")


def get_org_id_siths(cert: Certificate) -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion src/auth_server/tests/test_ca_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _do_mtls_transaction(self, cert: Certificate) -> Response:

def test_mtls_transaction(self):
parameters = [
("bolag_a.crt", True, "SE165560000167"),
("bolag_a.crt", True, "SE5560000167"),
("bolag_b.crt", False, "client certificate revoked"),
("bolag_c.crt", False, "client certificate expired or not yet valid"),
("bolag_e.crt", False, "client certificate expired or not yet valid"),
Expand Down

0 comments on commit 82583e6

Please sign in to comment.