in client-library/src/Attestation/AttestationClient/lib/AttestationClientImpl.cpp [574:633]
AttestationResult AttestationClientImpl::GetTpmInfo(TpmInfo& tpm_info) {
AttestationResult result(AttestationResult::ErrorCode::SUCCESS);
try {
Tpm tpm;
Buffer aik_cert = tpm.GetAIKCert();
Buffer aik_pub = tpm.GetAIKPub();
attest::PcrList pcrs = GetAttestationPcrList();
// Unpack the PCR quote to get the raw quote and arrange the quote
// signature in a format expected by AAS.
PcrQuote pcr_quote_marshaled = tpm.GetPCRQuote(pcrs, attestation_hash_alg);
PcrQuote pcr_quote = tpm.UnpackPcrQuoteToRSA(pcr_quote_marshaled);
// We get the pcr values from the SHA256 bank since we expect the TCG logs
// to also have SHA256 hash entries.
PcrSet pcr_values = tpm.GetPCRValues(pcrs, attestation_hash_alg);
EphemeralKey enc_key = tpm.GetEphemeralKey(pcr_values);
tpm_info.aik_cert_ = aik_cert;
tpm_info.aik_pub_ = aik_pub;
tpm_info.pcr_values_ = pcr_values;
tpm_info.pcr_quote_ = pcr_quote;
tpm_info.encryption_key_ = enc_key;
}
catch(const Tss2Exception& e) {
result.code_ = AttestationResult::ErrorCode::ERROR_TPM_OPERATION_FAILURE;
result.tpm_error_code_ = e.get_rc();
result.description_ = std::string(e.what());
CLIENT_LOG_ERROR("Failed Tpm operation:%d Error:%s",
result.tpm_error_code_,
result.description_.c_str());
return result;
}
catch(const std::exception& e) {
// Since tss2 errors are throw runtime error exception. Catch it here.
result.code_ = AttestationResult::ErrorCode::ERROR_TPM_INTERNAL_FAILURE;
result.description_ = std::string(e.what());
CLIENT_LOG_ERROR("Tpm internal error:%s",
result.description_.c_str());
return result;
}
catch(...) {
// Unknown exception.
result.code_ = AttestationResult::ErrorCode::ERROR_TPM_INTERNAL_FAILURE;
result.description_ = std::string("Unknown error");
CLIENT_LOG_ERROR("Tpm internal error:%s",
result.description_.c_str());
return result;
}
return result;
}