in src/local_gpu_verifier/src/verifier/cc_admin_utils.py [0:0]
def verify_attestation_report(attestation_report_obj, gpu_leaf_certificate, nonce, driver_version,
vbios_version, settings):
""" Performs the verification of the attestation report. This contains matching the nonce in the attestation report with
the one generated by the cc admin, matching the driver version and vbios version in the attestation report with the one
fetched from the driver. And then performing the signature verification of the attestation report.
Args:
attestation_report_obj (SpdmMeasurementResponseMessage): the object representing the attestation report.
gpu_leaf_certificate (OpenSSL.crypto.X509): the gpu leaf attestation certificate.
nonce (bytes): the nonce generated by the cc_admin.
driver_version (str): the driver version fetched from the GPU.
vbios_version (str): the vbios version fetched from the GPU.
settings (config.HopperSettings): the object containing the various config info.
Raises:
NonceMismatchError: it is raised in case the nonce generated by cc admin does not match with the one in the attestation report.
DriverVersionMismatchError: it is raised in case of the driver version does not matches with the one in the attestation report.
VBIOSVersionMismatchError: it is raised in case of the vbios version does not matches with the one in the attestation report.
SignatureVerificationError: it is raised in case the signature verification of the attestation report fails.
Returns:
[bool]: return True if the signature verification is successful.
"""
assert isinstance(attestation_report_obj, AttestationReport)
assert isinstance(gpu_leaf_certificate, crypto.X509)
assert isinstance(nonce, bytes) and len(nonce) == settings.SIZE_OF_NONCE_IN_BYTES
# Here the attestation report is the concatenated SPDM GET_MEASUREMENTS request with the SPDM GET_MEASUREMENT response message.
request_nonce = attestation_report_obj.get_request_message().get_nonce()
if len(nonce) > settings.SIZE_OF_NONCE_IN_BYTES or len(request_nonce) > settings.SIZE_OF_NONCE_IN_BYTES:
err_msg = "\t\t Length of Nonce is greater than max nonce size allowed."
event_log.error(err_msg)
raise InvalidNonceError(err_msg)
# compare the generated nonce with the nonce of SPDM GET MEASUREMENT request message in the attestation report.
if request_nonce != nonce:
err_msg = "\t\tThe nonce in the SPDM GET MEASUREMENT request message is not matching with the generated nonce."
event_log.error(err_msg)
raise NonceMismatchError(err_msg)
else:
info_log.info("\t\tThe nonce in the SPDM GET MEASUREMENT request message is matching with the generated nonce.")
settings.mark_nonce_as_matching()
# Checking driver version.
driver_version_from_attestation_report = attestation_report_obj.get_response_message().get_opaque_data().get_data("OPAQUE_FIELD_ID_DRIVER_VERSION")
driver_version_from_attestation_report = driver_version_from_attestation_report.decode()
if driver_version_from_attestation_report[-1] == '\0':
driver_version_from_attestation_report = driver_version_from_attestation_report[:-1]
info_log.info(f'\t\tDriver version fetched from the attestation report : {driver_version_from_attestation_report}')
if driver_version_from_attestation_report != driver_version:
err_msg = "\t\tThe driver version in attestation report is not matching with the driver version fetched from the driver."
event_log.error(err_msg)
raise DriverVersionMismatchError(err_msg)
event_log.debug("Driver version in attestation report is matching.")
settings.mark_attestation_report_driver_version_as_matching()
# Checking vbios version.
vbios_version_from_attestation_report = attestation_report_obj.get_response_message().get_opaque_data().get_data("OPAQUE_FIELD_ID_VBIOS_VERSION")
vbios_version_from_attestation_report = format_vbios_version(vbios_version_from_attestation_report)
info_log.info(f'\t\tVBIOS version fetched from the attestation report : {vbios_version_from_attestation_report}')
if vbios_version_from_attestation_report != vbios_version:
err_msg = "\t\tThe vbios version in attestation report is not matching with the vbios verison fetched from the driver."
event_log.error(err_msg)
raise VBIOSVersionMismatchError(err_msg)
event_log.debug("VBIOS version in attestation report is matching.")
settings.mark_attestation_report_vbios_version_as_matching()
# Performing the signature verification.
attestation_report_verification_status = attestation_report_obj.verify_signature(gpu_leaf_certificate.to_cryptography(),
settings.signature_length,
settings.HashFunction)
if attestation_report_verification_status:
info_log.info("\t\tAttestation report signature verification successful.")
settings.mark_attestation_report_signature_verified()
else:
err_msg = "\t\tAttestation report signature verification failed."
event_log.error(err_msg)
raise SignatureVerificationError(err_msg)
return attestation_report_verification_status