Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Seth Moore | f1f6215 | 2022-09-13 12:00:30 -0700 | [diff] [blame] | 17 | #include <memory> |
Seth Moore | 2fc6f83 | 2022-09-13 16:10:11 -0700 | [diff] [blame] | 18 | #include <string> |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 19 | #define LOG_TAG "VtsRemotelyProvisionableComponentTests" |
| 20 | |
Seth Moore | 8f810b1 | 2022-12-12 16:51:01 -0800 | [diff] [blame] | 21 | #include <aidl/android/hardware/security/keymint/BnRemotelyProvisionedComponent.h> |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 22 | #include <aidl/android/hardware/security/keymint/IRemotelyProvisionedComponent.h> |
| 23 | #include <aidl/android/hardware/security/keymint/SecurityLevel.h> |
| 24 | #include <android/binder_manager.h> |
Seth Moore | fc86bf4 | 2021-12-09 14:07:04 -0800 | [diff] [blame] | 25 | #include <binder/IServiceManager.h> |
Tri Vo | ec50ee1 | 2023-02-14 16:29:53 -0800 | [diff] [blame] | 26 | #include <cppbor.h> |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 27 | #include <cppbor_parse.h> |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 28 | #include <gmock/gmock.h> |
Max Bires | 9704ff6 | 2021-04-07 11:12:01 -0700 | [diff] [blame] | 29 | #include <keymaster/cppcose/cppcose.h> |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 30 | #include <keymaster/keymaster_configuration.h> |
David Drysdale | f0d516d | 2021-03-22 07:51:43 +0000 | [diff] [blame] | 31 | #include <keymint_support/authorization_set.h> |
| 32 | #include <openssl/ec.h> |
| 33 | #include <openssl/ec_key.h> |
| 34 | #include <openssl/x509.h> |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 35 | #include <remote_prov/remote_prov_utils.h> |
Max Bires | 757ed42 | 2022-09-07 16:20:31 -0700 | [diff] [blame] | 36 | #include <optional> |
Seth Moore | fc86bf4 | 2021-12-09 14:07:04 -0800 | [diff] [blame] | 37 | #include <set> |
Seth Moore | 42c1133 | 2021-07-02 15:38:17 -0700 | [diff] [blame] | 38 | #include <vector> |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 39 | |
David Drysdale | f0d516d | 2021-03-22 07:51:43 +0000 | [diff] [blame] | 40 | #include "KeyMintAidlTestBase.h" |
| 41 | |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 42 | namespace aidl::android::hardware::security::keymint::test { |
| 43 | |
| 44 | using ::std::string; |
| 45 | using ::std::vector; |
| 46 | |
| 47 | namespace { |
| 48 | |
Seth Moore | fc86bf4 | 2021-12-09 14:07:04 -0800 | [diff] [blame] | 49 | constexpr int32_t VERSION_WITH_UNIQUE_ID_SUPPORT = 2; |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 50 | constexpr int32_t VERSION_WITHOUT_TEST_MODE = 3; |
Seth Moore | fc86bf4 | 2021-12-09 14:07:04 -0800 | [diff] [blame] | 51 | |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 52 | #define INSTANTIATE_REM_PROV_AIDL_TEST(name) \ |
Seth Moore | 6305e23 | 2021-07-27 14:20:17 -0700 | [diff] [blame] | 53 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(name); \ |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 54 | INSTANTIATE_TEST_SUITE_P( \ |
| 55 | PerInstance, name, \ |
| 56 | testing::ValuesIn(VtsRemotelyProvisionedComponentTests::build_params()), \ |
| 57 | ::android::PrintInstanceNameToString) |
| 58 | |
Seth Moore | fc86bf4 | 2021-12-09 14:07:04 -0800 | [diff] [blame] | 59 | using ::android::sp; |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 60 | using bytevec = std::vector<uint8_t>; |
| 61 | using testing::MatchesRegex; |
| 62 | using namespace remote_prov; |
| 63 | using namespace keymaster; |
| 64 | |
| 65 | bytevec string_to_bytevec(const char* s) { |
| 66 | const uint8_t* p = reinterpret_cast<const uint8_t*>(s); |
| 67 | return bytevec(p, p + strlen(s)); |
| 68 | } |
| 69 | |
David Drysdale | e99ed86 | 2021-03-15 16:43:06 +0000 | [diff] [blame] | 70 | ErrMsgOr<MacedPublicKey> corrupt_maced_key(const MacedPublicKey& macedPubKey) { |
| 71 | auto [coseMac0, _, mac0ParseErr] = cppbor::parse(macedPubKey.macedKey); |
| 72 | if (!coseMac0 || coseMac0->asArray()->size() != kCoseMac0EntryCount) { |
| 73 | return "COSE Mac0 parse failed"; |
| 74 | } |
| 75 | auto protParams = coseMac0->asArray()->get(kCoseMac0ProtectedParams)->asBstr(); |
| 76 | auto unprotParams = coseMac0->asArray()->get(kCoseMac0UnprotectedParams)->asMap(); |
| 77 | auto payload = coseMac0->asArray()->get(kCoseMac0Payload)->asBstr(); |
| 78 | auto tag = coseMac0->asArray()->get(kCoseMac0Tag)->asBstr(); |
| 79 | if (!protParams || !unprotParams || !payload || !tag) { |
| 80 | return "Invalid COSE_Sign1: missing content"; |
| 81 | } |
| 82 | auto corruptMac0 = cppbor::Array(); |
| 83 | corruptMac0.add(protParams->clone()); |
| 84 | corruptMac0.add(unprotParams->clone()); |
| 85 | corruptMac0.add(payload->clone()); |
| 86 | vector<uint8_t> tagData = tag->value(); |
| 87 | tagData[0] ^= 0x08; |
| 88 | tagData[tagData.size() - 1] ^= 0x80; |
| 89 | corruptMac0.add(cppbor::Bstr(tagData)); |
| 90 | |
| 91 | return MacedPublicKey{corruptMac0.encode()}; |
| 92 | } |
| 93 | |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 94 | ErrMsgOr<cppbor::Array> corrupt_sig(const cppbor::Array* coseSign1) { |
| 95 | if (coseSign1->size() != kCoseSign1EntryCount) { |
| 96 | return "Invalid COSE_Sign1, wrong entry count"; |
| 97 | } |
| 98 | const cppbor::Bstr* protectedParams = coseSign1->get(kCoseSign1ProtectedParams)->asBstr(); |
| 99 | const cppbor::Map* unprotectedParams = coseSign1->get(kCoseSign1UnprotectedParams)->asMap(); |
| 100 | const cppbor::Bstr* payload = coseSign1->get(kCoseSign1Payload)->asBstr(); |
| 101 | const cppbor::Bstr* signature = coseSign1->get(kCoseSign1Signature)->asBstr(); |
| 102 | if (!protectedParams || !unprotectedParams || !payload || !signature) { |
| 103 | return "Invalid COSE_Sign1: missing content"; |
| 104 | } |
| 105 | |
| 106 | auto corruptSig = cppbor::Array(); |
| 107 | corruptSig.add(protectedParams->clone()); |
| 108 | corruptSig.add(unprotectedParams->clone()); |
| 109 | corruptSig.add(payload->clone()); |
| 110 | vector<uint8_t> sigData = signature->value(); |
| 111 | sigData[0] ^= 0x08; |
| 112 | corruptSig.add(cppbor::Bstr(sigData)); |
| 113 | |
| 114 | return std::move(corruptSig); |
| 115 | } |
| 116 | |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 117 | ErrMsgOr<bytevec> corrupt_sig_chain(const bytevec& encodedEekChain, int which) { |
| 118 | auto [chain, _, parseErr] = cppbor::parse(encodedEekChain); |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 119 | if (!chain || !chain->asArray()) { |
| 120 | return "EekChain parse failed"; |
| 121 | } |
| 122 | |
| 123 | cppbor::Array* eekChain = chain->asArray(); |
| 124 | if (which >= eekChain->size()) { |
| 125 | return "selected sig out of range"; |
| 126 | } |
| 127 | auto corruptChain = cppbor::Array(); |
| 128 | |
| 129 | for (int ii = 0; ii < eekChain->size(); ++ii) { |
| 130 | if (ii == which) { |
| 131 | auto sig = corrupt_sig(eekChain->get(which)->asArray()); |
| 132 | if (!sig) { |
| 133 | return "Failed to build corrupted signature" + sig.moveMessage(); |
| 134 | } |
| 135 | corruptChain.add(sig.moveValue()); |
| 136 | } else { |
| 137 | corruptChain.add(eekChain->get(ii)->clone()); |
| 138 | } |
| 139 | } |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 140 | return corruptChain.encode(); |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 141 | } |
| 142 | |
David Drysdale | 4d3c298 | 2021-03-31 18:21:40 +0100 | [diff] [blame] | 143 | string device_suffix(const string& name) { |
| 144 | size_t pos = name.find('/'); |
| 145 | if (pos == string::npos) { |
| 146 | return name; |
| 147 | } |
| 148 | return name.substr(pos + 1); |
| 149 | } |
| 150 | |
| 151 | bool matching_keymint_device(const string& rp_name, std::shared_ptr<IKeyMintDevice>* keyMint) { |
| 152 | string rp_suffix = device_suffix(rp_name); |
| 153 | |
| 154 | vector<string> km_names = ::android::getAidlHalInstanceNames(IKeyMintDevice::descriptor); |
| 155 | for (const string& km_name : km_names) { |
| 156 | // If the suffix of the KeyMint instance equals the suffix of the |
| 157 | // RemotelyProvisionedComponent instance, assume they match. |
| 158 | if (device_suffix(km_name) == rp_suffix && AServiceManager_isDeclared(km_name.c_str())) { |
| 159 | ::ndk::SpAIBinder binder(AServiceManager_waitForService(km_name.c_str())); |
| 160 | *keyMint = IKeyMintDevice::fromBinder(binder); |
| 161 | return true; |
| 162 | } |
| 163 | } |
| 164 | return false; |
| 165 | } |
| 166 | |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 167 | } // namespace |
| 168 | |
| 169 | class VtsRemotelyProvisionedComponentTests : public testing::TestWithParam<std::string> { |
| 170 | public: |
| 171 | virtual void SetUp() override { |
| 172 | if (AServiceManager_isDeclared(GetParam().c_str())) { |
| 173 | ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str())); |
| 174 | provisionable_ = IRemotelyProvisionedComponent::fromBinder(binder); |
| 175 | } |
| 176 | ASSERT_NE(provisionable_, nullptr); |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 177 | ASSERT_TRUE(provisionable_->getHardwareInfo(&rpcHardwareInfo).isOk()); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static vector<string> build_params() { |
| 181 | auto params = ::android::getAidlHalInstanceNames(IRemotelyProvisionedComponent::descriptor); |
| 182 | return params; |
| 183 | } |
| 184 | |
| 185 | protected: |
| 186 | std::shared_ptr<IRemotelyProvisionedComponent> provisionable_; |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 187 | RpcHardwareInfo rpcHardwareInfo; |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 188 | }; |
| 189 | |
Seth Moore | fc86bf4 | 2021-12-09 14:07:04 -0800 | [diff] [blame] | 190 | /** |
| 191 | * Verify that every implementation reports a different unique id. |
| 192 | */ |
| 193 | TEST(NonParameterizedTests, eachRpcHasAUniqueId) { |
| 194 | std::set<std::string> uniqueIds; |
| 195 | for (auto hal : ::android::getAidlHalInstanceNames(IRemotelyProvisionedComponent::descriptor)) { |
| 196 | ASSERT_TRUE(AServiceManager_isDeclared(hal.c_str())); |
| 197 | ::ndk::SpAIBinder binder(AServiceManager_waitForService(hal.c_str())); |
| 198 | std::shared_ptr<IRemotelyProvisionedComponent> rpc = |
| 199 | IRemotelyProvisionedComponent::fromBinder(binder); |
| 200 | ASSERT_NE(rpc, nullptr); |
| 201 | |
| 202 | RpcHardwareInfo hwInfo; |
| 203 | ASSERT_TRUE(rpc->getHardwareInfo(&hwInfo).isOk()); |
| 204 | |
Tri Vo | dd12c48 | 2022-10-12 22:41:28 +0000 | [diff] [blame] | 205 | if (hwInfo.versionNumber >= VERSION_WITH_UNIQUE_ID_SUPPORT) { |
Seth Moore | fc86bf4 | 2021-12-09 14:07:04 -0800 | [diff] [blame] | 206 | ASSERT_TRUE(hwInfo.uniqueId); |
| 207 | auto [_, wasInserted] = uniqueIds.insert(*hwInfo.uniqueId); |
| 208 | EXPECT_TRUE(wasInserted); |
| 209 | } else { |
| 210 | ASSERT_FALSE(hwInfo.uniqueId); |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | using GetHardwareInfoTests = VtsRemotelyProvisionedComponentTests; |
| 216 | |
| 217 | INSTANTIATE_REM_PROV_AIDL_TEST(GetHardwareInfoTests); |
| 218 | |
| 219 | /** |
| 220 | * Verify that a valid curve is reported by the implementation. |
| 221 | */ |
| 222 | TEST_P(GetHardwareInfoTests, supportsValidCurve) { |
| 223 | RpcHardwareInfo hwInfo; |
| 224 | ASSERT_TRUE(provisionable_->getHardwareInfo(&hwInfo).isOk()); |
| 225 | |
| 226 | const std::set<int> validCurves = {RpcHardwareInfo::CURVE_P256, RpcHardwareInfo::CURVE_25519}; |
Hasini Gunasinghe | 666b271 | 2023-01-05 21:35:51 +0000 | [diff] [blame] | 227 | // First check for the implementations that supports only IRPC V3+. |
| 228 | if (rpcHardwareInfo.versionNumber >= VERSION_WITHOUT_TEST_MODE) { |
| 229 | bytevec keysToSignMac; |
| 230 | DeviceInfo deviceInfo; |
| 231 | ProtectedData protectedData; |
| 232 | auto status = provisionable_->generateCertificateRequest(false, {}, {}, {}, &deviceInfo, |
| 233 | &protectedData, &keysToSignMac); |
| 234 | if (!status.isOk() && |
| 235 | (status.getServiceSpecificError() == BnRemotelyProvisionedComponent::STATUS_REMOVED)) { |
| 236 | ASSERT_EQ(hwInfo.supportedEekCurve, RpcHardwareInfo::CURVE_NONE) |
| 237 | << "Invalid curve: " << hwInfo.supportedEekCurve; |
| 238 | return; |
| 239 | } |
| 240 | } |
Seth Moore | fc86bf4 | 2021-12-09 14:07:04 -0800 | [diff] [blame] | 241 | ASSERT_EQ(validCurves.count(hwInfo.supportedEekCurve), 1) |
| 242 | << "Invalid curve: " << hwInfo.supportedEekCurve; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Verify that the unique id is within the length limits as described in RpcHardwareInfo.aidl. |
| 247 | */ |
| 248 | TEST_P(GetHardwareInfoTests, uniqueId) { |
Tri Vo | dd12c48 | 2022-10-12 22:41:28 +0000 | [diff] [blame] | 249 | if (rpcHardwareInfo.versionNumber < VERSION_WITH_UNIQUE_ID_SUPPORT) { |
Seth Moore | fc86bf4 | 2021-12-09 14:07:04 -0800 | [diff] [blame] | 250 | return; |
| 251 | } |
| 252 | |
| 253 | RpcHardwareInfo hwInfo; |
| 254 | ASSERT_TRUE(provisionable_->getHardwareInfo(&hwInfo).isOk()); |
| 255 | ASSERT_TRUE(hwInfo.uniqueId); |
| 256 | EXPECT_GE(hwInfo.uniqueId->size(), 1); |
| 257 | EXPECT_LE(hwInfo.uniqueId->size(), 32); |
| 258 | } |
| 259 | |
Tri Vo | 9cab73c | 2022-10-28 13:40:24 -0700 | [diff] [blame] | 260 | /** |
| 261 | * Verify implementation supports at least MIN_SUPPORTED_NUM_KEYS_IN_CSR keys in a CSR. |
| 262 | */ |
| 263 | TEST_P(GetHardwareInfoTests, supportedNumKeysInCsr) { |
| 264 | if (rpcHardwareInfo.versionNumber < VERSION_WITHOUT_TEST_MODE) { |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | RpcHardwareInfo hwInfo; |
| 269 | ASSERT_TRUE(provisionable_->getHardwareInfo(&hwInfo).isOk()); |
| 270 | ASSERT_GE(hwInfo.supportedNumKeysInCsr, RpcHardwareInfo::MIN_SUPPORTED_NUM_KEYS_IN_CSR); |
| 271 | } |
| 272 | |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 273 | using GenerateKeyTests = VtsRemotelyProvisionedComponentTests; |
| 274 | |
| 275 | INSTANTIATE_REM_PROV_AIDL_TEST(GenerateKeyTests); |
| 276 | |
| 277 | /** |
David Drysdale | f0d516d | 2021-03-22 07:51:43 +0000 | [diff] [blame] | 278 | * Generate and validate a production-mode key. MAC tag can't be verified, but |
| 279 | * the private key blob should be usable in KeyMint operations. |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 280 | */ |
Max Bires | 126869a | 2021-02-21 18:32:59 -0800 | [diff] [blame] | 281 | TEST_P(GenerateKeyTests, generateEcdsaP256Key_prodMode) { |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 282 | MacedPublicKey macedPubKey; |
| 283 | bytevec privateKeyBlob; |
| 284 | bool testMode = false; |
| 285 | auto status = provisionable_->generateEcdsaP256KeyPair(testMode, &macedPubKey, &privateKeyBlob); |
| 286 | ASSERT_TRUE(status.isOk()); |
David Drysdale | f0d516d | 2021-03-22 07:51:43 +0000 | [diff] [blame] | 287 | vector<uint8_t> coseKeyData; |
Tri Vo | b0b8acc | 2022-11-30 16:22:23 -0800 | [diff] [blame] | 288 | check_maced_pubkey(macedPubKey, testMode, &coseKeyData); |
David Drysdale | 4d3c298 | 2021-03-31 18:21:40 +0100 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Generate and validate a production-mode key, then use it as a KeyMint attestation key. |
| 293 | */ |
| 294 | TEST_P(GenerateKeyTests, generateAndUseEcdsaP256Key_prodMode) { |
| 295 | // See if there is a matching IKeyMintDevice for this IRemotelyProvisionedComponent. |
| 296 | std::shared_ptr<IKeyMintDevice> keyMint; |
| 297 | if (!matching_keymint_device(GetParam(), &keyMint)) { |
| 298 | // No matching IKeyMintDevice. |
| 299 | GTEST_SKIP() << "Skipping key use test as no matching KeyMint device found"; |
| 300 | return; |
| 301 | } |
| 302 | KeyMintHardwareInfo info; |
| 303 | ASSERT_TRUE(keyMint->getHardwareInfo(&info).isOk()); |
| 304 | |
| 305 | MacedPublicKey macedPubKey; |
| 306 | bytevec privateKeyBlob; |
| 307 | bool testMode = false; |
| 308 | auto status = provisionable_->generateEcdsaP256KeyPair(testMode, &macedPubKey, &privateKeyBlob); |
| 309 | ASSERT_TRUE(status.isOk()); |
| 310 | vector<uint8_t> coseKeyData; |
Tri Vo | b0b8acc | 2022-11-30 16:22:23 -0800 | [diff] [blame] | 311 | check_maced_pubkey(macedPubKey, testMode, &coseKeyData); |
David Drysdale | 4d3c298 | 2021-03-31 18:21:40 +0100 | [diff] [blame] | 312 | |
David Drysdale | f0d516d | 2021-03-22 07:51:43 +0000 | [diff] [blame] | 313 | AttestationKey attestKey; |
| 314 | attestKey.keyBlob = std::move(privateKeyBlob); |
| 315 | attestKey.issuerSubjectName = make_name_from_str("Android Keystore Key"); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 316 | |
David Drysdale | f0d516d | 2021-03-22 07:51:43 +0000 | [diff] [blame] | 317 | // Generate an ECDSA key that is attested by the generated P256 keypair. |
| 318 | AuthorizationSet keyDesc = AuthorizationSetBuilder() |
| 319 | .Authorization(TAG_NO_AUTH_REQUIRED) |
David Drysdale | 915ce25 | 2021-10-14 15:17:36 +0100 | [diff] [blame] | 320 | .EcdsaSigningKey(EcCurve::P_256) |
David Drysdale | f0d516d | 2021-03-22 07:51:43 +0000 | [diff] [blame] | 321 | .AttestationChallenge("foo") |
| 322 | .AttestationApplicationId("bar") |
| 323 | .Digest(Digest::NONE) |
| 324 | .SetDefaultValidity(); |
| 325 | KeyCreationResult creationResult; |
| 326 | auto result = keyMint->generateKey(keyDesc.vector_data(), attestKey, &creationResult); |
| 327 | ASSERT_TRUE(result.isOk()); |
| 328 | vector<uint8_t> attested_key_blob = std::move(creationResult.keyBlob); |
| 329 | vector<KeyCharacteristics> attested_key_characteristics = |
| 330 | std::move(creationResult.keyCharacteristics); |
| 331 | vector<Certificate> attested_key_cert_chain = std::move(creationResult.certificateChain); |
| 332 | EXPECT_EQ(attested_key_cert_chain.size(), 1); |
| 333 | |
David Drysdale | 7dff4fc | 2021-12-10 10:10:52 +0000 | [diff] [blame] | 334 | int32_t aidl_version = 0; |
| 335 | ASSERT_TRUE(keyMint->getInterfaceVersion(&aidl_version).isOk()); |
David Drysdale | f0d516d | 2021-03-22 07:51:43 +0000 | [diff] [blame] | 336 | AuthorizationSet hw_enforced = HwEnforcedAuthorizations(attested_key_characteristics); |
| 337 | AuthorizationSet sw_enforced = SwEnforcedAuthorizations(attested_key_characteristics); |
David Drysdale | 7dff4fc | 2021-12-10 10:10:52 +0000 | [diff] [blame] | 338 | EXPECT_TRUE(verify_attestation_record(aidl_version, "foo", "bar", sw_enforced, hw_enforced, |
David Drysdale | f0d516d | 2021-03-22 07:51:43 +0000 | [diff] [blame] | 339 | info.securityLevel, |
| 340 | attested_key_cert_chain[0].encodedCertificate)); |
| 341 | |
| 342 | // Attestation by itself is not valid (last entry is not self-signed). |
| 343 | EXPECT_FALSE(ChainSignaturesAreValid(attested_key_cert_chain)); |
| 344 | |
| 345 | // The signature over the attested key should correspond to the P256 public key. |
| 346 | X509_Ptr key_cert(parse_cert_blob(attested_key_cert_chain[0].encodedCertificate)); |
| 347 | ASSERT_TRUE(key_cert.get()); |
| 348 | EVP_PKEY_Ptr signing_pubkey; |
| 349 | p256_pub_key(coseKeyData, &signing_pubkey); |
| 350 | ASSERT_TRUE(signing_pubkey.get()); |
| 351 | |
| 352 | ASSERT_TRUE(X509_verify(key_cert.get(), signing_pubkey.get())) |
| 353 | << "Verification of attested certificate failed " |
| 354 | << "OpenSSL error string: " << ERR_error_string(ERR_get_error(), NULL); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Generate and validate a test-mode key. |
| 359 | */ |
Max Bires | 126869a | 2021-02-21 18:32:59 -0800 | [diff] [blame] | 360 | TEST_P(GenerateKeyTests, generateEcdsaP256Key_testMode) { |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 361 | MacedPublicKey macedPubKey; |
| 362 | bytevec privateKeyBlob; |
| 363 | bool testMode = true; |
| 364 | auto status = provisionable_->generateEcdsaP256KeyPair(testMode, &macedPubKey, &privateKeyBlob); |
| 365 | ASSERT_TRUE(status.isOk()); |
Tri Vo | b0b8acc | 2022-11-30 16:22:23 -0800 | [diff] [blame] | 366 | check_maced_pubkey(macedPubKey, testMode, nullptr); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 367 | } |
| 368 | |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 369 | class CertificateRequestTestBase : public VtsRemotelyProvisionedComponentTests { |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 370 | protected: |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 371 | CertificateRequestTestBase() |
| 372 | : eekId_(string_to_bytevec("eekid")), challenge_(randomBytes(64)) {} |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 373 | |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 374 | void generateTestEekChain(size_t eekLength) { |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 375 | auto chain = generateEekChain(rpcHardwareInfo.supportedEekCurve, eekLength, eekId_); |
David Drysdale | 08696a7 | 2022-03-10 10:43:25 +0000 | [diff] [blame] | 376 | ASSERT_TRUE(chain) << chain.message(); |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 377 | if (chain) testEekChain_ = chain.moveValue(); |
| 378 | testEekLength_ = eekLength; |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void generateKeys(bool testMode, size_t numKeys) { |
| 382 | keysToSign_ = std::vector<MacedPublicKey>(numKeys); |
| 383 | cborKeysToSign_ = cppbor::Array(); |
| 384 | |
| 385 | for (auto& key : keysToSign_) { |
| 386 | bytevec privateKeyBlob; |
| 387 | auto status = provisionable_->generateEcdsaP256KeyPair(testMode, &key, &privateKeyBlob); |
| 388 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 389 | |
David Drysdale | c840077 | 2021-03-11 12:35:11 +0000 | [diff] [blame] | 390 | vector<uint8_t> payload_value; |
Tri Vo | b0b8acc | 2022-11-30 16:22:23 -0800 | [diff] [blame] | 391 | check_maced_pubkey(key, testMode, &payload_value); |
David Drysdale | c840077 | 2021-03-11 12:35:11 +0000 | [diff] [blame] | 392 | cborKeysToSign_.add(cppbor::EncodedItem(payload_value)); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
| 396 | bytevec eekId_; |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 397 | size_t testEekLength_; |
| 398 | EekChain testEekChain_; |
David Drysdale | c840077 | 2021-03-11 12:35:11 +0000 | [diff] [blame] | 399 | bytevec challenge_; |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 400 | std::vector<MacedPublicKey> keysToSign_; |
| 401 | cppbor::Array cborKeysToSign_; |
| 402 | }; |
| 403 | |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 404 | class CertificateRequestTest : public CertificateRequestTestBase { |
| 405 | protected: |
| 406 | void SetUp() override { |
| 407 | CertificateRequestTestBase::SetUp(); |
Andrew Scull | 1bcb602 | 2022-12-27 10:43:27 +0000 | [diff] [blame] | 408 | ASSERT_FALSE(HasFatalFailure()); |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 409 | |
| 410 | if (rpcHardwareInfo.versionNumber >= VERSION_WITHOUT_TEST_MODE) { |
Tri Vo | b0b8acc | 2022-11-30 16:22:23 -0800 | [diff] [blame] | 411 | bytevec keysToSignMac; |
| 412 | DeviceInfo deviceInfo; |
| 413 | ProtectedData protectedData; |
| 414 | auto status = provisionable_->generateCertificateRequest( |
| 415 | false, {}, {}, {}, &deviceInfo, &protectedData, &keysToSignMac); |
| 416 | if (!status.isOk() && (status.getServiceSpecificError() == |
| 417 | BnRemotelyProvisionedComponent::STATUS_REMOVED)) { |
| 418 | GTEST_SKIP() << "This test case applies to RKP v3+ only if " |
| 419 | << "generateCertificateRequest() is implemented."; |
| 420 | } |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | }; |
| 424 | |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 425 | /** |
| 426 | * Generate an empty certificate request in test mode, and decrypt and verify the structure and |
| 427 | * content. |
| 428 | */ |
Max Bires | 126869a | 2021-02-21 18:32:59 -0800 | [diff] [blame] | 429 | TEST_P(CertificateRequestTest, EmptyRequest_testMode) { |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 430 | bool testMode = true; |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 431 | for (size_t eekLength : {2, 3, 7}) { |
| 432 | SCOPED_TRACE(testing::Message() << "EEK of length " << eekLength); |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 433 | generateTestEekChain(eekLength); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 434 | |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 435 | bytevec keysToSignMac; |
| 436 | DeviceInfo deviceInfo; |
| 437 | ProtectedData protectedData; |
| 438 | auto status = provisionable_->generateCertificateRequest( |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 439 | testMode, {} /* keysToSign */, testEekChain_.chain, challenge_, &deviceInfo, |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 440 | &protectedData, &keysToSignMac); |
| 441 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 442 | |
Seth Moore | 2fc6f83 | 2022-09-13 16:10:11 -0700 | [diff] [blame] | 443 | auto result = verifyProductionProtectedData( |
| 444 | deviceInfo, cppbor::Array(), keysToSignMac, protectedData, testEekChain_, eekId_, |
| 445 | rpcHardwareInfo.supportedEekCurve, provisionable_.get(), challenge_); |
| 446 | ASSERT_TRUE(result) << result.message(); |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 447 | } |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /** |
Seth Moore | 42c1133 | 2021-07-02 15:38:17 -0700 | [diff] [blame] | 451 | * Ensure that test mode outputs a unique BCC root key every time we request a |
| 452 | * certificate request. Else, it's possible that the test mode API could be used |
| 453 | * to fingerprint devices. Only the GEEK should be allowed to decrypt the same |
| 454 | * device public key multiple times. |
| 455 | */ |
| 456 | TEST_P(CertificateRequestTest, NewKeyPerCallInTestMode) { |
| 457 | constexpr bool testMode = true; |
Seth Moore | 42c1133 | 2021-07-02 15:38:17 -0700 | [diff] [blame] | 458 | |
| 459 | bytevec keysToSignMac; |
| 460 | DeviceInfo deviceInfo; |
| 461 | ProtectedData protectedData; |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 462 | generateTestEekChain(3); |
Seth Moore | 42c1133 | 2021-07-02 15:38:17 -0700 | [diff] [blame] | 463 | auto status = provisionable_->generateCertificateRequest( |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 464 | testMode, {} /* keysToSign */, testEekChain_.chain, challenge_, &deviceInfo, |
| 465 | &protectedData, &keysToSignMac); |
Seth Moore | 42c1133 | 2021-07-02 15:38:17 -0700 | [diff] [blame] | 466 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 467 | |
Seth Moore | 2fc6f83 | 2022-09-13 16:10:11 -0700 | [diff] [blame] | 468 | auto firstBcc = verifyProductionProtectedData( |
| 469 | deviceInfo, /*keysToSign=*/cppbor::Array(), keysToSignMac, protectedData, testEekChain_, |
| 470 | eekId_, rpcHardwareInfo.supportedEekCurve, provisionable_.get(), challenge_); |
| 471 | ASSERT_TRUE(firstBcc) << firstBcc.message(); |
Seth Moore | 42c1133 | 2021-07-02 15:38:17 -0700 | [diff] [blame] | 472 | |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 473 | status = provisionable_->generateCertificateRequest( |
| 474 | testMode, {} /* keysToSign */, testEekChain_.chain, challenge_, &deviceInfo, |
| 475 | &protectedData, &keysToSignMac); |
Seth Moore | 42c1133 | 2021-07-02 15:38:17 -0700 | [diff] [blame] | 476 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 477 | |
Seth Moore | 2fc6f83 | 2022-09-13 16:10:11 -0700 | [diff] [blame] | 478 | auto secondBcc = verifyProductionProtectedData( |
| 479 | deviceInfo, /*keysToSign=*/cppbor::Array(), keysToSignMac, protectedData, testEekChain_, |
| 480 | eekId_, rpcHardwareInfo.supportedEekCurve, provisionable_.get(), challenge_); |
| 481 | ASSERT_TRUE(secondBcc) << secondBcc.message(); |
Seth Moore | 42c1133 | 2021-07-02 15:38:17 -0700 | [diff] [blame] | 482 | |
| 483 | // Verify that none of the keys in the first BCC are repeated in the second one. |
Seth Moore | 2fc6f83 | 2022-09-13 16:10:11 -0700 | [diff] [blame] | 484 | for (const auto& i : *firstBcc) { |
| 485 | for (auto& j : *secondBcc) { |
Seth Moore | 42c1133 | 2021-07-02 15:38:17 -0700 | [diff] [blame] | 486 | ASSERT_THAT(i.pubKey, testing::Not(testing::ElementsAreArray(j.pubKey))) |
| 487 | << "Found a repeated pubkey in two generateCertificateRequest test mode calls"; |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /** |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 493 | * Generate an empty certificate request in prod mode. This test must be run explicitly, and |
| 494 | * is not run by default. Not all devices are GMS devices, and therefore they do not all |
| 495 | * trust the Google EEK root. |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 496 | */ |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 497 | TEST_P(CertificateRequestTest, DISABLED_EmptyRequest_prodMode) { |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 498 | bool testMode = false; |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 499 | |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 500 | bytevec keysToSignMac; |
| 501 | DeviceInfo deviceInfo; |
| 502 | ProtectedData protectedData; |
| 503 | auto status = provisionable_->generateCertificateRequest( |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 504 | testMode, {} /* keysToSign */, getProdEekChain(rpcHardwareInfo.supportedEekCurve), |
| 505 | challenge_, &deviceInfo, &protectedData, &keysToSignMac); |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 506 | EXPECT_TRUE(status.isOk()); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Generate a non-empty certificate request in test mode. Decrypt, parse and validate the contents. |
| 511 | */ |
Max Bires | 126869a | 2021-02-21 18:32:59 -0800 | [diff] [blame] | 512 | TEST_P(CertificateRequestTest, NonEmptyRequest_testMode) { |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 513 | bool testMode = true; |
| 514 | generateKeys(testMode, 4 /* numKeys */); |
| 515 | |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 516 | for (size_t eekLength : {2, 3, 7}) { |
| 517 | SCOPED_TRACE(testing::Message() << "EEK of length " << eekLength); |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 518 | generateTestEekChain(eekLength); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 519 | |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 520 | bytevec keysToSignMac; |
| 521 | DeviceInfo deviceInfo; |
| 522 | ProtectedData protectedData; |
| 523 | auto status = provisionable_->generateCertificateRequest( |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 524 | testMode, keysToSign_, testEekChain_.chain, challenge_, &deviceInfo, &protectedData, |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 525 | &keysToSignMac); |
| 526 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 527 | |
Seth Moore | 2fc6f83 | 2022-09-13 16:10:11 -0700 | [diff] [blame] | 528 | auto result = verifyProductionProtectedData( |
| 529 | deviceInfo, cborKeysToSign_, keysToSignMac, protectedData, testEekChain_, eekId_, |
| 530 | rpcHardwareInfo.supportedEekCurve, provisionable_.get(), challenge_); |
| 531 | ASSERT_TRUE(result) << result.message(); |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 532 | } |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /** |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 536 | * Generate a non-empty certificate request in prod mode. This test must be run explicitly, and |
| 537 | * is not run by default. Not all devices are GMS devices, and therefore they do not all |
| 538 | * trust the Google EEK root. |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 539 | */ |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 540 | TEST_P(CertificateRequestTest, DISABLED_NonEmptyRequest_prodMode) { |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 541 | bool testMode = false; |
| 542 | generateKeys(testMode, 4 /* numKeys */); |
| 543 | |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 544 | bytevec keysToSignMac; |
| 545 | DeviceInfo deviceInfo; |
| 546 | ProtectedData protectedData; |
| 547 | auto status = provisionable_->generateCertificateRequest( |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 548 | testMode, keysToSign_, getProdEekChain(rpcHardwareInfo.supportedEekCurve), challenge_, |
| 549 | &deviceInfo, &protectedData, &keysToSignMac); |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 550 | EXPECT_TRUE(status.isOk()); |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /** |
David Drysdale | e99ed86 | 2021-03-15 16:43:06 +0000 | [diff] [blame] | 554 | * Generate a non-empty certificate request in test mode, but with the MAC corrupted on the keypair. |
| 555 | */ |
| 556 | TEST_P(CertificateRequestTest, NonEmptyRequestCorruptMac_testMode) { |
| 557 | bool testMode = true; |
| 558 | generateKeys(testMode, 1 /* numKeys */); |
David Drysdale | 08696a7 | 2022-03-10 10:43:25 +0000 | [diff] [blame] | 559 | auto result = corrupt_maced_key(keysToSign_[0]); |
| 560 | ASSERT_TRUE(result) << result.moveMessage(); |
| 561 | MacedPublicKey keyWithCorruptMac = result.moveValue(); |
David Drysdale | e99ed86 | 2021-03-15 16:43:06 +0000 | [diff] [blame] | 562 | |
| 563 | bytevec keysToSignMac; |
| 564 | DeviceInfo deviceInfo; |
| 565 | ProtectedData protectedData; |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 566 | generateTestEekChain(3); |
David Drysdale | e99ed86 | 2021-03-15 16:43:06 +0000 | [diff] [blame] | 567 | auto status = provisionable_->generateCertificateRequest( |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 568 | testMode, {keyWithCorruptMac}, testEekChain_.chain, challenge_, &deviceInfo, |
| 569 | &protectedData, &keysToSignMac); |
David Drysdale | e99ed86 | 2021-03-15 16:43:06 +0000 | [diff] [blame] | 570 | ASSERT_FALSE(status.isOk()) << status.getMessage(); |
| 571 | EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_INVALID_MAC); |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Generate a non-empty certificate request in prod mode, but with the MAC corrupted on the keypair. |
| 576 | */ |
| 577 | TEST_P(CertificateRequestTest, NonEmptyRequestCorruptMac_prodMode) { |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 578 | bool testMode = false; |
David Drysdale | e99ed86 | 2021-03-15 16:43:06 +0000 | [diff] [blame] | 579 | generateKeys(testMode, 1 /* numKeys */); |
David Drysdale | 08696a7 | 2022-03-10 10:43:25 +0000 | [diff] [blame] | 580 | auto result = corrupt_maced_key(keysToSign_[0]); |
| 581 | ASSERT_TRUE(result) << result.moveMessage(); |
| 582 | MacedPublicKey keyWithCorruptMac = result.moveValue(); |
David Drysdale | e99ed86 | 2021-03-15 16:43:06 +0000 | [diff] [blame] | 583 | |
| 584 | bytevec keysToSignMac; |
| 585 | DeviceInfo deviceInfo; |
| 586 | ProtectedData protectedData; |
| 587 | auto status = provisionable_->generateCertificateRequest( |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 588 | testMode, {keyWithCorruptMac}, getProdEekChain(rpcHardwareInfo.supportedEekCurve), |
| 589 | challenge_, &deviceInfo, &protectedData, &keysToSignMac); |
David Drysdale | e99ed86 | 2021-03-15 16:43:06 +0000 | [diff] [blame] | 590 | ASSERT_FALSE(status.isOk()) << status.getMessage(); |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 591 | EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_INVALID_MAC); |
David Drysdale | e99ed86 | 2021-03-15 16:43:06 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /** |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 595 | * Generate a non-empty certificate request in prod mode that has a corrupt EEK chain. |
| 596 | * Confirm that the request is rejected. |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 597 | */ |
| 598 | TEST_P(CertificateRequestTest, NonEmptyCorruptEekRequest_prodMode) { |
| 599 | bool testMode = false; |
| 600 | generateKeys(testMode, 4 /* numKeys */); |
| 601 | |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 602 | auto prodEekChain = getProdEekChain(rpcHardwareInfo.supportedEekCurve); |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 603 | auto [parsedChain, _, parseErr] = cppbor::parse(prodEekChain); |
| 604 | ASSERT_NE(parsedChain, nullptr) << parseErr; |
| 605 | ASSERT_NE(parsedChain->asArray(), nullptr); |
| 606 | |
| 607 | for (int ii = 0; ii < parsedChain->asArray()->size(); ++ii) { |
| 608 | auto chain = corrupt_sig_chain(prodEekChain, ii); |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 609 | ASSERT_TRUE(chain) << chain.message(); |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 610 | |
| 611 | bytevec keysToSignMac; |
| 612 | DeviceInfo deviceInfo; |
| 613 | ProtectedData protectedData; |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 614 | auto status = provisionable_->generateCertificateRequest(testMode, keysToSign_, *chain, |
| 615 | challenge_, &deviceInfo, |
| 616 | &protectedData, &keysToSignMac); |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 617 | ASSERT_FALSE(status.isOk()); |
| 618 | ASSERT_EQ(status.getServiceSpecificError(), |
| 619 | BnRemotelyProvisionedComponent::STATUS_INVALID_EEK); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Generate a non-empty certificate request in prod mode that has an incomplete EEK chain. |
| 625 | * Confirm that the request is rejected. |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 626 | */ |
| 627 | TEST_P(CertificateRequestTest, NonEmptyIncompleteEekRequest_prodMode) { |
| 628 | bool testMode = false; |
| 629 | generateKeys(testMode, 4 /* numKeys */); |
| 630 | |
| 631 | // Build an EEK chain that omits the first self-signed cert. |
| 632 | auto truncatedChain = cppbor::Array(); |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 633 | auto [chain, _, parseErr] = cppbor::parse(getProdEekChain(rpcHardwareInfo.supportedEekCurve)); |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 634 | ASSERT_TRUE(chain); |
| 635 | auto eekChain = chain->asArray(); |
| 636 | ASSERT_NE(eekChain, nullptr); |
| 637 | for (size_t ii = 1; ii < eekChain->size(); ii++) { |
| 638 | truncatedChain.add(eekChain->get(ii)->clone()); |
| 639 | } |
| 640 | |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 641 | bytevec keysToSignMac; |
Max Bires | fdbb904 | 2021-03-23 12:43:38 -0700 | [diff] [blame] | 642 | DeviceInfo deviceInfo; |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 643 | ProtectedData protectedData; |
David Drysdale | cceca9f | 2021-03-12 15:49:47 +0000 | [diff] [blame] | 644 | auto status = provisionable_->generateCertificateRequest( |
| 645 | testMode, keysToSign_, truncatedChain.encode(), challenge_, &deviceInfo, &protectedData, |
| 646 | &keysToSignMac); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 647 | ASSERT_FALSE(status.isOk()); |
| 648 | ASSERT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_INVALID_EEK); |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * Generate a non-empty certificate request in test mode, with prod keys. Must fail with |
| 653 | * STATUS_PRODUCTION_KEY_IN_TEST_REQUEST. |
| 654 | */ |
Max Bires | 126869a | 2021-02-21 18:32:59 -0800 | [diff] [blame] | 655 | TEST_P(CertificateRequestTest, NonEmptyRequest_prodKeyInTestCert) { |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 656 | generateKeys(false /* testMode */, 2 /* numKeys */); |
| 657 | |
| 658 | bytevec keysToSignMac; |
Max Bires | fdbb904 | 2021-03-23 12:43:38 -0700 | [diff] [blame] | 659 | DeviceInfo deviceInfo; |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 660 | ProtectedData protectedData; |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 661 | generateTestEekChain(3); |
Max Bires | fdbb904 | 2021-03-23 12:43:38 -0700 | [diff] [blame] | 662 | auto status = provisionable_->generateCertificateRequest( |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 663 | true /* testMode */, keysToSign_, testEekChain_.chain, challenge_, &deviceInfo, |
Max Bires | fdbb904 | 2021-03-23 12:43:38 -0700 | [diff] [blame] | 664 | &protectedData, &keysToSignMac); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 665 | ASSERT_FALSE(status.isOk()); |
| 666 | ASSERT_EQ(status.getServiceSpecificError(), |
| 667 | BnRemotelyProvisionedComponent::STATUS_PRODUCTION_KEY_IN_TEST_REQUEST); |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Generate a non-empty certificate request in prod mode, with test keys. Must fail with |
| 672 | * STATUS_TEST_KEY_IN_PRODUCTION_REQUEST. |
| 673 | */ |
Max Bires | 126869a | 2021-02-21 18:32:59 -0800 | [diff] [blame] | 674 | TEST_P(CertificateRequestTest, NonEmptyRequest_testKeyInProdCert) { |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 675 | generateKeys(true /* testMode */, 2 /* numKeys */); |
| 676 | |
| 677 | bytevec keysToSignMac; |
Max Bires | fdbb904 | 2021-03-23 12:43:38 -0700 | [diff] [blame] | 678 | DeviceInfo deviceInfo; |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 679 | ProtectedData protectedData; |
subrahmanyaman | fb213d6 | 2022-02-02 23:10:55 +0000 | [diff] [blame] | 680 | generateTestEekChain(3); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 681 | auto status = provisionable_->generateCertificateRequest( |
Seth Moore | 19acbe9 | 2021-06-23 15:15:52 -0700 | [diff] [blame] | 682 | false /* testMode */, keysToSign_, testEekChain_.chain, challenge_, &deviceInfo, |
David Drysdale | c840077 | 2021-03-11 12:35:11 +0000 | [diff] [blame] | 683 | &protectedData, &keysToSignMac); |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 684 | ASSERT_FALSE(status.isOk()); |
| 685 | ASSERT_EQ(status.getServiceSpecificError(), |
| 686 | BnRemotelyProvisionedComponent::STATUS_TEST_KEY_IN_PRODUCTION_REQUEST); |
| 687 | } |
| 688 | |
| 689 | INSTANTIATE_REM_PROV_AIDL_TEST(CertificateRequestTest); |
| 690 | |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 691 | class CertificateRequestV2Test : public CertificateRequestTestBase { |
| 692 | void SetUp() override { |
| 693 | CertificateRequestTestBase::SetUp(); |
Andrew Scull | 1bcb602 | 2022-12-27 10:43:27 +0000 | [diff] [blame] | 694 | ASSERT_FALSE(HasFatalFailure()); |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 695 | |
| 696 | if (rpcHardwareInfo.versionNumber < VERSION_WITHOUT_TEST_MODE) { |
| 697 | GTEST_SKIP() << "This test case only applies to RKP v3 and above. " |
| 698 | << "RKP version discovered: " << rpcHardwareInfo.versionNumber; |
| 699 | } |
| 700 | } |
| 701 | }; |
| 702 | |
| 703 | /** |
| 704 | * Generate an empty certificate request, and decrypt and verify the structure and content. |
| 705 | */ |
| 706 | TEST_P(CertificateRequestV2Test, EmptyRequest) { |
| 707 | bytevec csr; |
| 708 | |
| 709 | auto status = |
| 710 | provisionable_->generateCertificateRequestV2({} /* keysToSign */, challenge_, &csr); |
| 711 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 712 | |
| 713 | auto result = verifyProductionCsr(cppbor::Array(), csr, provisionable_.get(), challenge_); |
| 714 | ASSERT_TRUE(result) << result.message(); |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * Generate a non-empty certificate request. Decrypt, parse and validate the contents. |
| 719 | */ |
| 720 | TEST_P(CertificateRequestV2Test, NonEmptyRequest) { |
| 721 | generateKeys(false /* testMode */, 1 /* numKeys */); |
| 722 | |
| 723 | bytevec csr; |
| 724 | |
| 725 | auto status = provisionable_->generateCertificateRequestV2(keysToSign_, challenge_, &csr); |
| 726 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 727 | |
| 728 | auto result = verifyProductionCsr(cborKeysToSign_, csr, provisionable_.get(), challenge_); |
| 729 | ASSERT_TRUE(result) << result.message(); |
| 730 | } |
| 731 | |
| 732 | /** |
Andrew Scull | fb49ad2 | 2022-11-09 21:02:48 +0000 | [diff] [blame] | 733 | * Generate a non-empty certificate request. Make sure contents are reproducible but allow for the |
| 734 | * signature to be different since algorithms including ECDSA P-256 can include a random value. |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 735 | */ |
| 736 | TEST_P(CertificateRequestV2Test, NonEmptyRequestReproducible) { |
| 737 | generateKeys(false /* testMode */, 1 /* numKeys */); |
| 738 | |
| 739 | bytevec csr; |
| 740 | |
| 741 | auto status = provisionable_->generateCertificateRequestV2(keysToSign_, challenge_, &csr); |
| 742 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 743 | |
Andrew Scull | fb49ad2 | 2022-11-09 21:02:48 +0000 | [diff] [blame] | 744 | auto firstCsr = verifyProductionCsr(cborKeysToSign_, csr, provisionable_.get(), challenge_); |
| 745 | ASSERT_TRUE(firstCsr) << firstCsr.message(); |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 746 | |
| 747 | status = provisionable_->generateCertificateRequestV2(keysToSign_, challenge_, &csr); |
| 748 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 749 | |
Andrew Scull | fb49ad2 | 2022-11-09 21:02:48 +0000 | [diff] [blame] | 750 | auto secondCsr = verifyProductionCsr(cborKeysToSign_, csr, provisionable_.get(), challenge_); |
| 751 | ASSERT_TRUE(secondCsr) << secondCsr.message(); |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 752 | |
Andrew Scull | fb49ad2 | 2022-11-09 21:02:48 +0000 | [diff] [blame] | 753 | ASSERT_EQ(**firstCsr, **secondCsr); |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Generate a non-empty certificate request with multiple keys. |
| 758 | */ |
| 759 | TEST_P(CertificateRequestV2Test, NonEmptyRequestMultipleKeys) { |
Tri Vo | 9cab73c | 2022-10-28 13:40:24 -0700 | [diff] [blame] | 760 | generateKeys(false /* testMode */, rpcHardwareInfo.supportedNumKeysInCsr /* numKeys */); |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 761 | |
| 762 | bytevec csr; |
| 763 | |
| 764 | auto status = provisionable_->generateCertificateRequestV2(keysToSign_, challenge_, &csr); |
| 765 | ASSERT_TRUE(status.isOk()) << status.getMessage(); |
| 766 | |
| 767 | auto result = verifyProductionCsr(cborKeysToSign_, csr, provisionable_.get(), challenge_); |
| 768 | ASSERT_TRUE(result) << result.message(); |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * Generate a non-empty certificate request, but with the MAC corrupted on the keypair. |
| 773 | */ |
| 774 | TEST_P(CertificateRequestV2Test, NonEmptyRequestCorruptMac) { |
| 775 | generateKeys(false /* testMode */, 1 /* numKeys */); |
| 776 | auto result = corrupt_maced_key(keysToSign_[0]); |
| 777 | ASSERT_TRUE(result) << result.moveMessage(); |
| 778 | MacedPublicKey keyWithCorruptMac = result.moveValue(); |
| 779 | |
| 780 | bytevec csr; |
| 781 | auto status = |
| 782 | provisionable_->generateCertificateRequestV2({keyWithCorruptMac}, challenge_, &csr); |
| 783 | ASSERT_FALSE(status.isOk()) << status.getMessage(); |
| 784 | EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_INVALID_MAC); |
| 785 | } |
| 786 | |
| 787 | /** |
Tri Vo | b0b8acc | 2022-11-30 16:22:23 -0800 | [diff] [blame] | 788 | * Generate a non-empty certificate request in prod mode, with test keys. Must fail with |
| 789 | * STATUS_TEST_KEY_IN_PRODUCTION_REQUEST. |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 790 | */ |
| 791 | TEST_P(CertificateRequestV2Test, NonEmptyRequest_testKeyInProdCert) { |
| 792 | generateKeys(true /* testMode */, 1 /* numKeys */); |
| 793 | |
| 794 | bytevec csr; |
| 795 | auto status = provisionable_->generateCertificateRequestV2(keysToSign_, challenge_, &csr); |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 796 | ASSERT_FALSE(status.isOk()) << status.getMessage(); |
Tri Vo | b0b8acc | 2022-11-30 16:22:23 -0800 | [diff] [blame] | 797 | ASSERT_EQ(status.getServiceSpecificError(), |
| 798 | BnRemotelyProvisionedComponent::STATUS_TEST_KEY_IN_PRODUCTION_REQUEST); |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Tri Vo | ec50ee1 | 2023-02-14 16:29:53 -0800 | [diff] [blame] | 801 | void parse_root_of_trust(const vector<uint8_t>& attestation_cert, |
| 802 | vector<uint8_t>* verified_boot_key, VerifiedBoot* verified_boot_state, |
| 803 | bool* device_locked, vector<uint8_t>* verified_boot_hash) { |
| 804 | X509_Ptr cert(parse_cert_blob(attestation_cert)); |
| 805 | ASSERT_TRUE(cert.get()); |
| 806 | |
| 807 | ASN1_OCTET_STRING* attest_rec = get_attestation_record(cert.get()); |
| 808 | ASSERT_TRUE(attest_rec); |
| 809 | |
| 810 | auto error = parse_root_of_trust(attest_rec->data, attest_rec->length, verified_boot_key, |
| 811 | verified_boot_state, device_locked, verified_boot_hash); |
| 812 | ASSERT_EQ(error, ErrorCode::OK); |
| 813 | } |
| 814 | |
| 815 | /** |
| 816 | * Generate a CSR and verify DeviceInfo against IDs attested by KeyMint. |
| 817 | */ |
| 818 | TEST_P(CertificateRequestV2Test, DeviceInfo) { |
| 819 | // See if there is a matching IKeyMintDevice for this IRemotelyProvisionedComponent. |
| 820 | std::shared_ptr<IKeyMintDevice> keyMint; |
| 821 | if (!matching_keymint_device(GetParam(), &keyMint)) { |
| 822 | // No matching IKeyMintDevice. |
| 823 | GTEST_SKIP() << "Skipping key use test as no matching KeyMint device found"; |
| 824 | return; |
| 825 | } |
| 826 | KeyMintHardwareInfo info; |
| 827 | ASSERT_TRUE(keyMint->getHardwareInfo(&info).isOk()); |
| 828 | |
| 829 | // Get IDs attested by KeyMint. |
| 830 | MacedPublicKey macedPubKey; |
| 831 | bytevec privateKeyBlob; |
| 832 | auto irpcStatus = |
| 833 | provisionable_->generateEcdsaP256KeyPair(false, &macedPubKey, &privateKeyBlob); |
| 834 | ASSERT_TRUE(irpcStatus.isOk()); |
| 835 | |
| 836 | AttestationKey attestKey; |
| 837 | attestKey.keyBlob = std::move(privateKeyBlob); |
| 838 | attestKey.issuerSubjectName = make_name_from_str("Android Keystore Key"); |
| 839 | |
| 840 | // Generate an ECDSA key that is attested by the generated P256 keypair. |
| 841 | AuthorizationSet keyDesc = AuthorizationSetBuilder() |
| 842 | .Authorization(TAG_NO_AUTH_REQUIRED) |
| 843 | .EcdsaSigningKey(EcCurve::P_256) |
| 844 | .AttestationChallenge("foo") |
| 845 | .AttestationApplicationId("bar") |
| 846 | .Digest(Digest::NONE) |
| 847 | .SetDefaultValidity(); |
| 848 | KeyCreationResult creationResult; |
| 849 | auto kmStatus = keyMint->generateKey(keyDesc.vector_data(), attestKey, &creationResult); |
| 850 | ASSERT_TRUE(kmStatus.isOk()); |
| 851 | |
| 852 | vector<KeyCharacteristics> key_characteristics = std::move(creationResult.keyCharacteristics); |
| 853 | vector<Certificate> key_cert_chain = std::move(creationResult.certificateChain); |
| 854 | // We didn't provision the attestation key. |
| 855 | ASSERT_EQ(key_cert_chain.size(), 1); |
| 856 | |
| 857 | // Parse attested patch levels. |
| 858 | auto auths = HwEnforcedAuthorizations(key_characteristics); |
| 859 | |
| 860 | auto attestedSystemPatchLevel = auths.GetTagValue(TAG_OS_PATCHLEVEL); |
| 861 | auto attestedVendorPatchLevel = auths.GetTagValue(TAG_VENDOR_PATCHLEVEL); |
| 862 | auto attestedBootPatchLevel = auths.GetTagValue(TAG_BOOT_PATCHLEVEL); |
| 863 | |
| 864 | ASSERT_TRUE(attestedSystemPatchLevel.has_value()); |
| 865 | ASSERT_TRUE(attestedVendorPatchLevel.has_value()); |
| 866 | ASSERT_TRUE(attestedBootPatchLevel.has_value()); |
| 867 | |
| 868 | // Parse attested AVB values. |
| 869 | vector<uint8_t> key; |
| 870 | VerifiedBoot attestedVbState; |
| 871 | bool attestedBootloaderState; |
| 872 | vector<uint8_t> attestedVbmetaDigest; |
| 873 | parse_root_of_trust(key_cert_chain[0].encodedCertificate, &key, &attestedVbState, |
| 874 | &attestedBootloaderState, &attestedVbmetaDigest); |
| 875 | |
| 876 | // Get IDs from DeviceInfo. |
| 877 | bytevec csr; |
| 878 | irpcStatus = |
| 879 | provisionable_->generateCertificateRequestV2({} /* keysToSign */, challenge_, &csr); |
| 880 | ASSERT_TRUE(irpcStatus.isOk()) << irpcStatus.getMessage(); |
| 881 | |
| 882 | auto result = verifyProductionCsr(cppbor::Array(), csr, provisionable_.get(), challenge_); |
| 883 | ASSERT_TRUE(result) << result.message(); |
| 884 | |
| 885 | std::unique_ptr<cppbor::Array> csrPayload = std::move(*result); |
| 886 | ASSERT_TRUE(csrPayload); |
| 887 | |
| 888 | auto deviceInfo = csrPayload->get(2)->asMap(); |
| 889 | ASSERT_TRUE(deviceInfo); |
| 890 | |
| 891 | auto vbState = deviceInfo->get("vb_state")->asTstr(); |
| 892 | auto bootloaderState = deviceInfo->get("bootloader_state")->asTstr(); |
| 893 | auto vbmetaDigest = deviceInfo->get("vbmeta_digest")->asBstr(); |
| 894 | auto systemPatchLevel = deviceInfo->get("system_patch_level")->asUint(); |
| 895 | auto vendorPatchLevel = deviceInfo->get("vendor_patch_level")->asUint(); |
| 896 | auto bootPatchLevel = deviceInfo->get("boot_patch_level")->asUint(); |
| 897 | auto securityLevel = deviceInfo->get("security_level")->asTstr(); |
| 898 | |
| 899 | ASSERT_TRUE(vbState); |
| 900 | ASSERT_TRUE(bootloaderState); |
| 901 | ASSERT_TRUE(vbmetaDigest); |
| 902 | ASSERT_TRUE(systemPatchLevel); |
| 903 | ASSERT_TRUE(vendorPatchLevel); |
| 904 | ASSERT_TRUE(bootPatchLevel); |
| 905 | ASSERT_TRUE(securityLevel); |
| 906 | |
| 907 | auto kmDeviceName = device_suffix(GetParam()); |
| 908 | |
| 909 | // Compare DeviceInfo against IDs attested by KeyMint. |
| 910 | ASSERT_TRUE((securityLevel->value() == "tee" && kmDeviceName == "default") || |
| 911 | (securityLevel->value() == "strongbox" && kmDeviceName == "strongbox")); |
| 912 | ASSERT_TRUE((vbState->value() == "green" && attestedVbState == VerifiedBoot::VERIFIED) || |
| 913 | (vbState->value() == "yellow" && attestedVbState == VerifiedBoot::SELF_SIGNED) || |
| 914 | (vbState->value() == "orange" && attestedVbState == VerifiedBoot::UNVERIFIED)); |
| 915 | ASSERT_TRUE((bootloaderState->value() == "locked" && attestedBootloaderState) || |
| 916 | (bootloaderState->value() == "unlocked" && !attestedBootloaderState)); |
| 917 | ASSERT_EQ(vbmetaDigest->value(), attestedVbmetaDigest); |
| 918 | ASSERT_EQ(systemPatchLevel->value(), attestedSystemPatchLevel.value()); |
| 919 | ASSERT_EQ(vendorPatchLevel->value(), attestedVendorPatchLevel.value()); |
| 920 | ASSERT_EQ(bootPatchLevel->value(), attestedBootPatchLevel.value()); |
| 921 | } |
| 922 | |
Tri Vo | 0d6204e | 2022-09-29 16:15:34 -0700 | [diff] [blame] | 923 | INSTANTIATE_REM_PROV_AIDL_TEST(CertificateRequestV2Test); |
| 924 | |
Max Bires | a9b3bb9 | 2022-11-21 23:02:09 -0800 | [diff] [blame] | 925 | using VsrRequirementTest = VtsRemotelyProvisionedComponentTests; |
| 926 | |
| 927 | INSTANTIATE_REM_PROV_AIDL_TEST(VsrRequirementTest); |
| 928 | |
| 929 | TEST_P(VsrRequirementTest, VsrEnforcementTest) { |
| 930 | RpcHardwareInfo hwInfo; |
| 931 | ASSERT_TRUE(provisionable_->getHardwareInfo(&hwInfo).isOk()); |
| 932 | int vsr_api_level = get_vsr_api_level(); |
| 933 | if (vsr_api_level < 34) { |
| 934 | GTEST_SKIP() << "Applies only to VSR API level 34 or newer, this device is: " |
| 935 | << vsr_api_level; |
| 936 | } |
| 937 | EXPECT_GE(hwInfo.versionNumber, 3) |
| 938 | << "VSR 14+ requires IRemotelyProvisionedComponent v3 or newer."; |
| 939 | } |
| 940 | |
Shawn Willden | 274bb55 | 2020-09-30 22:39:22 -0600 | [diff] [blame] | 941 | } // namespace aidl::android::hardware::security::keymint::test |