Skip to content

Commit ec44b65

Browse files
author
Ubuntu
committed
Support PPCIE mode and as many GPUs are in the system.
Needs further testing and validation
1 parent d2c2d59 commit ec44b65

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

inteltrustauthorityclient/nvgpu/gpu_adapter.py

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -41,56 +41,62 @@ def generate_nvgpu_evidence(user_nonce):
4141
try:
4242
nvmlInit()
4343
state = nvmlSystemGetConfComputeState()
44+
print(state.ccFeature)
4445
if state.ccFeature == 0:
45-
err_msg = "The confidential compute feature is disabled !!\nQuitting now."
46-
raise Error(err_msg)
46+
print("WARNING: state.ccFeature = 0 (disabled), but library needs PPCIE support")
47+
#err_msg = "The confidential compute feature is disabled !!\nQuitting now."
48+
#raise Error(err_msg)
4749
if state.devToolsMode != 0:
4850
log.warning("The system is running in CC DevTools mode !!")
4951
evidence_nonce = bytes.fromhex(user_nonce)
5052
number_of_available_gpus = nvmlDeviceGetCount()
5153
if number_of_available_gpus == 0:
5254
err_msg = "No NV GPU found ! \nQuitting now."
5355
raise Error(err_msg)
54-
if number_of_available_gpus > 1:
55-
log.warning("There are more than one NVGPU found, but only the first one used")
56-
gpu_handle = nvmlDeviceGetHandleByIndex(0)
57-
58-
try:
59-
attestation_report_struct = nvmlDeviceGetConfComputeGpuAttestationReport(gpu_handle,
60-
evidence_nonce)
61-
length_of_attestation_report = attestation_report_struct.attestationReportSize
62-
attestation_report = attestation_report_struct.attestationReport
63-
attestation_report_data = list()
64-
65-
for i in range(length_of_attestation_report):
66-
attestation_report_data.append(attestation_report[i])
67-
68-
bin_attestation_report_data = bytes(attestation_report_data)
69-
except Exception as err:
70-
log.error(err)
71-
err_msg = "Something went wrong while fetching the attestation report from the gpu."
72-
raise PynvmlError(err_msg)
73-
74-
try:
75-
cert_struct = nvmlDeviceGetConfComputeGpuCertificate(gpu_handle)
76-
# fetching the attestation cert chain.
77-
length_of_attestation_cert_chain = cert_struct.attestationCertChainSize
78-
attestation_cert_chain = cert_struct.attestationCertChain
79-
attestation_cert_data = list()
80-
81-
for i in range(length_of_attestation_cert_chain):
82-
attestation_cert_data.append(attestation_cert_chain[i])
83-
84-
bin_attestation_cert_data = bytes(attestation_cert_data)
85-
86-
except Exception as err:
87-
log.error(err)
88-
err_msg = "Something went wrong while fetching the certificate chains from the gpu."
89-
raise PynvmlError(err_msg)
56+
#if number_of_available_gpus > 1:
57+
# log.warning("There are more than one NVGPU found, but only the first one used")
58+
59+
for gpu_index in range(number_of_available_gpus):
60+
print("gathering report for gpu index %d" % gpu_index)
61+
gpu_handle = nvmlDeviceGetHandleByIndex(gpu_index)
62+
63+
try:
64+
attestation_report_struct = nvmlDeviceGetConfComputeGpuAttestationReport(gpu_handle,
65+
evidence_nonce)
66+
length_of_attestation_report = attestation_report_struct.attestationReportSize
67+
attestation_report = attestation_report_struct.attestationReport
68+
attestation_report_data = list()
69+
70+
for i in range(length_of_attestation_report):
71+
attestation_report_data.append(attestation_report[i])
72+
73+
bin_attestation_report_data = bytes(attestation_report_data)
74+
except Exception as err:
75+
log.error(err)
76+
err_msg = "Something went wrong while fetching the attestation report from the gpu."
77+
raise PynvmlError(err_msg)
78+
79+
try:
80+
cert_struct = nvmlDeviceGetConfComputeGpuCertificate(gpu_handle)
81+
# fetching the attestation cert chain.
82+
length_of_attestation_cert_chain = cert_struct.attestationCertChainSize
83+
attestation_cert_chain = cert_struct.attestationCertChain
84+
attestation_cert_data = list()
85+
86+
for i in range(length_of_attestation_cert_chain):
87+
attestation_cert_data.append(attestation_cert_chain[i])
88+
89+
bin_attestation_cert_data = bytes(attestation_cert_data)
90+
91+
except Exception as err:
92+
log.error(err)
93+
err_msg = "Something went wrong while fetching the certificate chains from the gpu."
94+
raise PynvmlError(err_msg)
95+
96+
gpu_evidence = {'certChainBase64Encoded': base64.b64encode(bin_attestation_cert_data),
97+
'attestationReportHexStr': bin_attestation_report_data.hex()}
98+
evidence_list.append(gpu_evidence)
9099

91-
gpu_evidence = {'certChainBase64Encoded': base64.b64encode(bin_attestation_cert_data),
92-
'attestationReportHexStr': bin_attestation_report_data.hex()}
93-
evidence_list.append(gpu_evidence)
94100
nvmlShutdown()
95101
except Exception as error:
96102
log.error(error)

0 commit comments

Comments
 (0)