Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions framework/python/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,20 @@ async def upload_cert(self, file: UploadFile, response: Response):
False, "A certificate with that common name already exists."
)

# Returned when organization name is missing
elif str(e) == "Certificate is missing the organization name":
response.status_code = status.HTTP_400_BAD_REQUEST
return self._generate_msg(
False, "The certificate must contain the organization name"
)

# Returned when common name is missing
elif str(e) == "Certificate is missing the common name":
response.status_code = status.HTTP_400_BAD_REQUEST
return self._generate_msg(
False, "The certificate must contain the common name"
)

# Returned when unable to load PEM file
else:
response.status_code = status.HTTP_400_BAD_REQUEST
Expand Down
23 changes: 18 additions & 5 deletions framework/python/src/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,30 @@ def upload_cert(self, filename, content):
# Parse bytes into x509 object
cert = x509.load_pem_x509_certificate(content, default_backend())

# Extract required properties
common_name = cert.subject.get_attributes_for_oid(
NameOID.COMMON_NAME)[0].value
# Retrieve the common name attributes from the subject
common_name_attr = cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)

# Raise an error if the common name attribute is missing
if not common_name_attr:
raise ValueError('Certificate is missing the common name')

# Extract the organization name value
common_name = common_name_attr[0].value

# Check if any existing certificates have the same common name
for cur_cert in self._certs:
if common_name == cur_cert['name']:
raise ValueError('A certificate with that name already exists')

issuer = cert.issuer.get_attributes_for_oid(
NameOID.ORGANIZATION_NAME)[0].value
# Retrieve the organization name attributes from issuer
issuer_attr = cert.issuer.get_attributes_for_oid(NameOID.ORGANIZATION_NAME)

# Raise an error if the organization name attribute is missing
if not issuer_attr:
raise ValueError('Certificate is missing the organization name')

# Extract the organization name value
issuer = issuer_attr[0].value

status = 'Valid'
if now > cert.not_valid_after_utc:
Expand Down