From af5fad4036bdd1febc19a40a79b93d3fa06a22ac Mon Sep 17 00:00:00 2001 From: Iris Chang Date: Thu, 14 Sep 2017 15:23:18 +0800 Subject: [PATCH] VTS: fix VtsHalKeymasterV3_0Target issue Failed cases: AttestationTest.RsaAttestation AttestationTest.EcAttestation Analysis: The verify_attestation_record() in Keymaster_hidl_hal_test.cpp calls parse_attestation_record() to set the value of att_challenge. It fails to compare att_challenge with challenge by memcmp. Because setToExternal() method uses buffer pointer to local variable (record), not use memcpy to copy into itself buffer in parse_attestation_record(). When it leaves the parse_attestation_record(), we will get the att_challenge which is null buffer to compare with challenge incorrectly. Fix: use memcpy to copy the buffer. Bug: 65039571 Test: build passed. VtsHalKeymasterV3_0Target -> PASSED: 106, FAILED: 0. Change-Id: I700a9242cc9a5f4cb196b62860823601e4088531 Merged-In: I700a9242cc9a5f4cb196b62860823601e4088531 (cherry picked from 54ca32a130a0450b444848046199d62876b55301) (cherry picked from commit 926a8e7440a0c85d39dbf7143bfe03964363ddec) --- keymaster/3.0/vts/functional/attestation_record.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/keymaster/3.0/vts/functional/attestation_record.cpp b/keymaster/3.0/vts/functional/attestation_record.cpp index 5d96fff803..a428989de2 100644 --- a/keymaster/3.0/vts/functional/attestation_record.cpp +++ b/keymaster/3.0/vts/functional/attestation_record.cpp @@ -274,10 +274,12 @@ ErrorCode parse_attestation_record(const uint8_t* asn1_key_desc, size_t asn1_key *keymaster_security_level = static_cast(ASN1_ENUMERATED_get(record->keymaster_security_level)); - attestation_challenge->setToExternal(record->attestation_challenge->data, - record->attestation_challenge->length); - - unique_id->setToExternal(record->unique_id->data, record->unique_id->length); + auto& chall = record->attestation_challenge; + attestation_challenge->resize(chall->length); + memcpy(attestation_challenge->data(), chall->data, chall->length); + auto& uid = record->unique_id; + unique_id->resize(uid->length); + memcpy(unique_id->data(), uid->data, uid->length); ErrorCode error = extract_auth_list(record->software_enforced, software_enforced); if (error != ErrorCode::OK) return error;