Skip to content

Commit

Permalink
Handle errors in OCSPResponse json validation
Browse files Browse the repository at this point in the history
  • Loading branch information
FestiveKyle committed Apr 11, 2024
1 parent 761892b commit cf4d767
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion sslyze/plugins/certificate_info/json_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.x509 import NameAttribute, ObjectIdentifier, Name, Certificate
from cryptography.x509 import NameAttribute, ObjectIdentifier, Name, Certificate, ocsp
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePublicKey

from sslyze import (
Expand Down Expand Up @@ -213,6 +213,30 @@ class _OcspResponseAsJson(BaseModelWithOrmMode):

serial_number: Optional[int]

@model_validator(mode="before")
@classmethod
def _handle_object(cls, ocsp_response: ocsp.OCSPResponse) -> Any:
response_status = ocsp_response.response_status.name
if ocsp_response.response_status != ocsp.OCSPResponseStatus.SUCCESSFUL:
return dict(
response_status=response_status,
certificate_status=None,
revocation_time=None,
produced_at=None,
this_update=None,
next_update=None,
serial_number=None,
)
return dict(
response_status=ocsp_response.response_status,
certificate_status=ocsp_response.certificate_status,
revocation_time=ocsp_response.revocation_time,
produced_at=ocsp_response.produced_at,
this_update=ocsp_response.this_update,
next_update=ocsp_response.next_update,
serial_number=ocsp_response.serial_number,
)


class _TrustStoreAsJson(BaseModelWithOrmMode):
path: Path
Expand Down

0 comments on commit cf4d767

Please sign in to comment.