diff options
author | David Drysdale <drysdale@google.com> | 2021-03-22 07:51:43 +0000 |
---|---|---|
committer | David Drysdale <drysdale@google.com> | 2021-03-29 09:17:54 +0100 |
commit | f0d516d28181eb51b7654ca2a4e7170bdd406a0c (patch) | |
tree | cc7ef6b386f6df6cf9cd1a3e3ce657dd19b7b3cc /security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp | |
parent | e99ed8667ace3e33b74c915e4b50675e5b88437c (diff) |
Test that provisioned keys can be used with KeyMint
Test: VtsRemotelyProvisionedComponentTests
Change-Id: I2f5187bfb4fd1572d10c306377e07a6d167689fa
Diffstat (limited to 'security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp')
-rw-r--r-- | security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp | 69 |
1 files changed, 45 insertions, 24 deletions
diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp index 3e87b6b2da..ce6f67a84a 100644 --- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp @@ -811,30 +811,6 @@ const vector<KeyParameter>& KeyMintAidlTestBase::SecLevelAuthorizations( return (found == key_characteristics.end()) ? kEmptyAuthList : found->authorizations; } -AuthorizationSet KeyMintAidlTestBase::HwEnforcedAuthorizations( - const vector<KeyCharacteristics>& key_characteristics) { - AuthorizationSet authList; - for (auto& entry : key_characteristics) { - if (entry.securityLevel == SecurityLevel::STRONGBOX || - entry.securityLevel == SecurityLevel::TRUSTED_ENVIRONMENT) { - authList.push_back(AuthorizationSet(entry.authorizations)); - } - } - return authList; -} - -AuthorizationSet KeyMintAidlTestBase::SwEnforcedAuthorizations( - const vector<KeyCharacteristics>& key_characteristics) { - AuthorizationSet authList; - for (auto& entry : key_characteristics) { - if (entry.securityLevel == SecurityLevel::SOFTWARE || - entry.securityLevel == SecurityLevel::KEYSTORE) { - authList.push_back(AuthorizationSet(entry.authorizations)); - } - } - return authList; -} - ErrorCode KeyMintAidlTestBase::UseAesKey(const vector<uint8_t>& aesKeyBlob) { auto [result, ciphertext] = ProcessMessage( aesKeyBlob, KeyPurpose::ENCRYPT, "1234567890123456", @@ -1046,6 +1022,28 @@ string bin2hex(const vector<uint8_t>& data) { return retval; } +AuthorizationSet HwEnforcedAuthorizations(const vector<KeyCharacteristics>& key_characteristics) { + AuthorizationSet authList; + for (auto& entry : key_characteristics) { + if (entry.securityLevel == SecurityLevel::STRONGBOX || + entry.securityLevel == SecurityLevel::TRUSTED_ENVIRONMENT) { + authList.push_back(AuthorizationSet(entry.authorizations)); + } + } + return authList; +} + +AuthorizationSet SwEnforcedAuthorizations(const vector<KeyCharacteristics>& key_characteristics) { + AuthorizationSet authList; + for (auto& entry : key_characteristics) { + if (entry.securityLevel == SecurityLevel::SOFTWARE || + entry.securityLevel == SecurityLevel::KEYSTORE) { + authList.push_back(AuthorizationSet(entry.authorizations)); + } + } + return authList; +} + AssertionResult ChainSignaturesAreValid(const vector<Certificate>& chain) { std::stringstream cert_data; @@ -1097,6 +1095,29 @@ X509_Ptr parse_cert_blob(const vector<uint8_t>& blob) { return X509_Ptr(d2i_X509(nullptr /* allocate new */, &p, blob.size())); } +vector<uint8_t> make_name_from_str(const string& name) { + X509_NAME_Ptr x509_name(X509_NAME_new()); + EXPECT_TRUE(x509_name.get() != nullptr); + if (!x509_name) return {}; + + EXPECT_EQ(1, X509_NAME_add_entry_by_txt(x509_name.get(), // + "CN", // + MBSTRING_ASC, + reinterpret_cast<const uint8_t*>(name.c_str()), + -1, // len + -1, // loc + 0 /* set */)); + + int len = i2d_X509_NAME(x509_name.get(), nullptr /* only return length */); + EXPECT_GT(len, 0); + + vector<uint8_t> retval(len); + uint8_t* p = retval.data(); + i2d_X509_NAME(x509_name.get(), &p); + + return retval; +} + } // namespace test } // namespace aidl::android::hardware::security::keymint |