Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors in OCSPResponse json validation #647

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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