From 207322654aa4d0fcc60ba2d19324d7cbda41dc15 Mon Sep 17 00:00:00 2001 From: Shawn Willden Date: Fri, 21 Apr 2023 16:36:00 -0600 Subject: [PATCH] Check for MGF1 digests in key characteristics. A bug in the Trusty HAL service caused it to replace MGF1 digest tags with Tag::INVALID. This tests that MGF1 tags are returned properly in the MGF1 success test, and verifies that Tag::INVALID is never returned by any test. Bug: 278157584 Test: adb shell /data/nativetest/VtsAidlKeyMintTargetTest/VtsAidlKeyMintTargetTest Change-Id: I5d391310795c99f37acf3c48310c127a7a31fac3 --- .../aidl/vts/functional/KeyMintAidlTestBase.cpp | 7 +++++++ .../keymint/aidl/vts/functional/KeyMintTest.cpp | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp index 5e27bd0e5b..60d8748395 100644 --- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp @@ -71,6 +71,11 @@ const uint32_t kInvalidPatchlevel = 99998877; // additional overhead, for the digest algorithmIdentifier required by PKCS#1. const size_t kPkcs1UndigestedSignaturePaddingOverhead = 11; +size_t count_tag_invalid_entries(const std::vector& authorizations) { + return std::count_if(authorizations.begin(), authorizations.end(), + [](const KeyParameter& e) -> bool { return e.tag == Tag::INVALID; }); +} + typedef KeyMintAidlTestBase::KeyData KeyData; // Predicate for testing basic characteristics validity in generation or import. bool KeyCharacteristicsBasicallyValid(SecurityLevel secLevel, @@ -84,6 +89,8 @@ bool KeyCharacteristicsBasicallyValid(SecurityLevel secLevel, return false; } + EXPECT_EQ(count_tag_invalid_entries(entry.authorizations), 0); + // Just ignore the SecurityLevel::KEYSTORE as the KM won't do any enforcement on this. if (entry.securityLevel == SecurityLevel::KEYSTORE) continue; diff --git a/security/keymint/aidl/vts/functional/KeyMintTest.cpp b/security/keymint/aidl/vts/functional/KeyMintTest.cpp index e99149bf17..0a70bafb83 100644 --- a/security/keymint/aidl/vts/functional/KeyMintTest.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintTest.cpp @@ -5314,6 +5314,20 @@ TEST_P(EncryptionOperationsTest, RsaOaepWithMGFDigestSuccess) { .Digest(Digest::SHA_2_256) .SetDefaultValidity())); + std::vector mgf1DigestsInAuths; + mgf1DigestsInAuths.reserve(digests.size()); + const auto& hw_auths = SecLevelAuthorizations(key_characteristics_); + std::for_each(hw_auths.begin(), hw_auths.end(), [&](auto& param) { + if (param.tag == Tag::RSA_OAEP_MGF_DIGEST) { + KeyParameterValue value = param.value; + mgf1DigestsInAuths.push_back(param.value.template get()); + } + }); + + std::sort(digests.begin(), digests.end()); + std::sort(mgf1DigestsInAuths.begin(), mgf1DigestsInAuths.end()); + EXPECT_EQ(digests, mgf1DigestsInAuths); + string message = "Hello"; for (auto digest : digests) {