Skip to content

Commit

Permalink
Merge pull request #647 from FestiveKyle/handle-ocsp-json-validation
Browse files Browse the repository at this point in the history
Handle errors in OCSPResponse json validation
  • Loading branch information
nabla-c0d3 authored Jun 23, 2024
2 parents 0ad77c1 + cf4d767 commit 1b2e3f8
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 1b2e3f8

Please sign in to comment.