From b18c757eda464d72672951879039fcbb8efc9dc9 Mon Sep 17 00:00:00 2001 From: David Drysdale Date: Thu, 15 Jun 2023 09:41:05 +0100 Subject: [PATCH] [RESTRICT AUTOMERGE] Allow extra error code in device ID attestation Generalize the existing helper function to allow more variants. Manual cherry-pick of aosp/2627969 combined with aosp/2648423 to avoid merge conflicts Bug: 286733800 Test: VtsAidlKeyMintTargetTest Merged-In: Ic01c53cbe79f55c2d403a66acbfd04029395c287 Merged-In: I0dcac312ac4516a078b2742721e3a19074da52b1 Change-Id: I328f7b3195d4b4dd1ed1da17377696261094ea76 --- .../aidl/vts/functional/AttestKeyTest.cpp | 4 +--- .../functional/DeviceUniqueAttestationTest.cpp | 2 +- .../vts/functional/KeyMintAidlTestBase.cpp | 18 ++++++++++++++++++ .../aidl/vts/functional/KeyMintAidlTestBase.h | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/security/keymint/aidl/vts/functional/AttestKeyTest.cpp b/security/keymint/aidl/vts/functional/AttestKeyTest.cpp index b9968f8afc..3e37a5ccd6 100644 --- a/security/keymint/aidl/vts/functional/AttestKeyTest.cpp +++ b/security/keymint/aidl/vts/functional/AttestKeyTest.cpp @@ -952,9 +952,7 @@ TEST_P(AttestKeyTest, EcdsaAttestationMismatchID) { vector attested_key_cert_chain; auto result = GenerateKey(builder, attest_key, &attested_key_blob, &attested_key_characteristics, &attested_key_cert_chain); - - ASSERT_TRUE(result == ErrorCode::CANNOT_ATTEST_IDS || result == ErrorCode::INVALID_TAG) - << "result = " << result; + device_id_attestation_check_acceptable_error(invalid_tag.tag, result); } CheckedDeleteKey(&attest_key.keyBlob); } diff --git a/security/keymint/aidl/vts/functional/DeviceUniqueAttestationTest.cpp b/security/keymint/aidl/vts/functional/DeviceUniqueAttestationTest.cpp index 1dc5df3429..c91e4e8b15 100644 --- a/security/keymint/aidl/vts/functional/DeviceUniqueAttestationTest.cpp +++ b/security/keymint/aidl/vts/functional/DeviceUniqueAttestationTest.cpp @@ -349,7 +349,7 @@ TEST_P(DeviceUniqueAttestationTest, EcdsaDeviceUniqueAttestationMismatchID) { builder.push_back(invalid_tag); auto result = GenerateKey(builder, &key_blob, &key_characteristics); - ASSERT_TRUE(result == ErrorCode::CANNOT_ATTEST_IDS || result == ErrorCode::INVALID_TAG); + device_id_attestation_check_acceptable_error(invalid_tag.tag, result); } } diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp index 20c0bf580f..d2d964afa5 100644 --- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp @@ -1924,6 +1924,24 @@ void p256_pub_key(const vector& coseKeyData, EVP_PKEY_Ptr* signingKey) *signingKey = std::move(pubKey); } +// Check the error code from an attempt to perform device ID attestation with an invalid value. +void device_id_attestation_check_acceptable_error(Tag tag, const ErrorCode& result) { + if (result == ErrorCode::CANNOT_ATTEST_IDS) { + // Standard/default error code for ID mismatch. + } else if (result == ErrorCode::INVALID_TAG) { + // Depending on the situation, other error codes may be acceptable. First, allow older + // implementations to use INVALID_TAG. + } else if (result == ErrorCode::ATTESTATION_IDS_NOT_PROVISIONED) { + // If the device is not a phone, it will not have IMEI/MEID values available. Allow + // ATTESTATION_IDS_NOT_PROVISIONED in this case. + ASSERT_TRUE((tag == TAG_ATTESTATION_ID_IMEI || tag == TAG_ATTESTATION_ID_MEID)) + << "incorrect error code on attestation ID mismatch"; + } else { + ADD_FAILURE() << "Error code " << result + << " returned on attestation ID mismatch, should be CANNOT_ATTEST_IDS"; + } +} + // Check whether the given named feature is available. bool check_feature(const std::string& name) { ::android::sp<::android::IServiceManager> sm(::android::defaultServiceManager()); diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h index 7d3bc30b7b..129c7378cf 100644 --- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h +++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h @@ -386,6 +386,7 @@ vector make_name_from_str(const string& name); void check_maced_pubkey(const MacedPublicKey& macedPubKey, bool testMode, vector* payload_value); void p256_pub_key(const vector& coseKeyData, EVP_PKEY_Ptr* signingKey); +void device_id_attestation_check_acceptable_error(Tag tag, const ErrorCode& result); bool check_feature(const std::string& name); AuthorizationSet HwEnforcedAuthorizations(const vector& key_characteristics);