blob: d9bd0d886a809599e26c19b053774fd609535ce5 [file] [log] [blame]
Shawn Willden274bb552020-09-30 22:39:22 -06001/*
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 Mooref1f62152022-09-13 12:00:30 -070017#include <memory>
Seth Moore2fc6f832022-09-13 16:10:11 -070018#include <string>
Shawn Willden274bb552020-09-30 22:39:22 -060019#define LOG_TAG "VtsRemotelyProvisionableComponentTests"
20
Seth Moore8f810b12022-12-12 16:51:01 -080021#include <aidl/android/hardware/security/keymint/BnRemotelyProvisionedComponent.h>
Shawn Willden274bb552020-09-30 22:39:22 -060022#include <aidl/android/hardware/security/keymint/IRemotelyProvisionedComponent.h>
23#include <aidl/android/hardware/security/keymint/SecurityLevel.h>
24#include <android/binder_manager.h>
Seth Moorefc86bf42021-12-09 14:07:04 -080025#include <binder/IServiceManager.h>
Tri Voec50ee12023-02-14 16:29:53 -080026#include <cppbor.h>
Shawn Willden274bb552020-09-30 22:39:22 -060027#include <cppbor_parse.h>
Shawn Willden274bb552020-09-30 22:39:22 -060028#include <gmock/gmock.h>
Max Bires9704ff62021-04-07 11:12:01 -070029#include <keymaster/cppcose/cppcose.h>
Shawn Willden274bb552020-09-30 22:39:22 -060030#include <keymaster/keymaster_configuration.h>
David Drysdalef0d516d2021-03-22 07:51:43 +000031#include <keymint_support/authorization_set.h>
32#include <openssl/ec.h>
33#include <openssl/ec_key.h>
34#include <openssl/x509.h>
Shawn Willden274bb552020-09-30 22:39:22 -060035#include <remote_prov/remote_prov_utils.h>
Max Bires757ed422022-09-07 16:20:31 -070036#include <optional>
Seth Moorefc86bf42021-12-09 14:07:04 -080037#include <set>
Sean Thomasafbab602024-11-07 23:14:05 +000038#include <string_view>
Seth Moore42c11332021-07-02 15:38:17 -070039#include <vector>
Shawn Willden274bb552020-09-30 22:39:22 -060040
David Drysdalef0d516d2021-03-22 07:51:43 +000041#include "KeyMintAidlTestBase.h"
42
Shawn Willden274bb552020-09-30 22:39:22 -060043namespace aidl::android::hardware::security::keymint::test {
44
45using ::std::string;
46using ::std::vector;
47
48namespace {
49
Seth Moorefc86bf42021-12-09 14:07:04 -080050constexpr int32_t VERSION_WITH_UNIQUE_ID_SUPPORT = 2;
Andrew Scullf2ae1932023-04-24 19:09:09 +000051
52constexpr int32_t VERSION_WITHOUT_EEK = 3;
Tri Vo0d6204e2022-09-29 16:15:34 -070053constexpr int32_t VERSION_WITHOUT_TEST_MODE = 3;
Andrew Scullf2ae1932023-04-24 19:09:09 +000054constexpr int32_t VERSION_WITH_CERTIFICATE_REQUEST_V2 = 3;
55constexpr int32_t VERSION_WITH_SUPPORTED_NUM_KEYS_IN_CSR = 3;
Seth Moorefc86bf42021-12-09 14:07:04 -080056
Tommy Chiufde3ad12023-03-17 05:58:28 +000057constexpr uint8_t MIN_CHALLENGE_SIZE = 0;
58constexpr uint8_t MAX_CHALLENGE_SIZE = 64;
Alice Wangf112ec92024-10-08 07:30:28 +000059
Andrew Scull21461522024-03-25 15:08:08 +000060const string KEYMINT_STRONGBOX_INSTANCE_NAME =
61 "android.hardware.security.keymint.IKeyMintDevice/strongbox";
Tommy Chiufde3ad12023-03-17 05:58:28 +000062
Shawn Willden274bb552020-09-30 22:39:22 -060063#define INSTANTIATE_REM_PROV_AIDL_TEST(name) \
Seth Moore6305e232021-07-27 14:20:17 -070064 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(name); \
Shawn Willden274bb552020-09-30 22:39:22 -060065 INSTANTIATE_TEST_SUITE_P( \
66 PerInstance, name, \
67 testing::ValuesIn(VtsRemotelyProvisionedComponentTests::build_params()), \
68 ::android::PrintInstanceNameToString)
69
Seth Moorefc86bf42021-12-09 14:07:04 -080070using ::android::sp;
Shawn Willden274bb552020-09-30 22:39:22 -060071using bytevec = std::vector<uint8_t>;
72using testing::MatchesRegex;
73using namespace remote_prov;
74using namespace keymaster;
75
76bytevec string_to_bytevec(const char* s) {
77 const uint8_t* p = reinterpret_cast<const uint8_t*>(s);
78 return bytevec(p, p + strlen(s));
79}
80
David Drysdalee99ed862021-03-15 16:43:06 +000081ErrMsgOr<MacedPublicKey> corrupt_maced_key(const MacedPublicKey& macedPubKey) {
82 auto [coseMac0, _, mac0ParseErr] = cppbor::parse(macedPubKey.macedKey);
83 if (!coseMac0 || coseMac0->asArray()->size() != kCoseMac0EntryCount) {
84 return "COSE Mac0 parse failed";
85 }
86 auto protParams = coseMac0->asArray()->get(kCoseMac0ProtectedParams)->asBstr();
87 auto unprotParams = coseMac0->asArray()->get(kCoseMac0UnprotectedParams)->asMap();
88 auto payload = coseMac0->asArray()->get(kCoseMac0Payload)->asBstr();
89 auto tag = coseMac0->asArray()->get(kCoseMac0Tag)->asBstr();
90 if (!protParams || !unprotParams || !payload || !tag) {
91 return "Invalid COSE_Sign1: missing content";
92 }
93 auto corruptMac0 = cppbor::Array();
94 corruptMac0.add(protParams->clone());
95 corruptMac0.add(unprotParams->clone());
96 corruptMac0.add(payload->clone());
97 vector<uint8_t> tagData = tag->value();
98 tagData[0] ^= 0x08;
99 tagData[tagData.size() - 1] ^= 0x80;
100 corruptMac0.add(cppbor::Bstr(tagData));
101
102 return MacedPublicKey{corruptMac0.encode()};
103}
104
David Drysdalecceca9f2021-03-12 15:49:47 +0000105ErrMsgOr<cppbor::Array> corrupt_sig(const cppbor::Array* coseSign1) {
106 if (coseSign1->size() != kCoseSign1EntryCount) {
107 return "Invalid COSE_Sign1, wrong entry count";
108 }
109 const cppbor::Bstr* protectedParams = coseSign1->get(kCoseSign1ProtectedParams)->asBstr();
110 const cppbor::Map* unprotectedParams = coseSign1->get(kCoseSign1UnprotectedParams)->asMap();
111 const cppbor::Bstr* payload = coseSign1->get(kCoseSign1Payload)->asBstr();
112 const cppbor::Bstr* signature = coseSign1->get(kCoseSign1Signature)->asBstr();
113 if (!protectedParams || !unprotectedParams || !payload || !signature) {
114 return "Invalid COSE_Sign1: missing content";
115 }
116
117 auto corruptSig = cppbor::Array();
118 corruptSig.add(protectedParams->clone());
119 corruptSig.add(unprotectedParams->clone());
120 corruptSig.add(payload->clone());
121 vector<uint8_t> sigData = signature->value();
122 sigData[0] ^= 0x08;
123 corruptSig.add(cppbor::Bstr(sigData));
124
125 return std::move(corruptSig);
126}
127
Seth Moore19acbe92021-06-23 15:15:52 -0700128ErrMsgOr<bytevec> corrupt_sig_chain(const bytevec& encodedEekChain, int which) {
129 auto [chain, _, parseErr] = cppbor::parse(encodedEekChain);
David Drysdalecceca9f2021-03-12 15:49:47 +0000130 if (!chain || !chain->asArray()) {
131 return "EekChain parse failed";
132 }
133
134 cppbor::Array* eekChain = chain->asArray();
135 if (which >= eekChain->size()) {
136 return "selected sig out of range";
137 }
138 auto corruptChain = cppbor::Array();
139
140 for (int ii = 0; ii < eekChain->size(); ++ii) {
141 if (ii == which) {
142 auto sig = corrupt_sig(eekChain->get(which)->asArray());
143 if (!sig) {
144 return "Failed to build corrupted signature" + sig.moveMessage();
145 }
146 corruptChain.add(sig.moveValue());
147 } else {
148 corruptChain.add(eekChain->get(ii)->clone());
149 }
150 }
Seth Moore19acbe92021-06-23 15:15:52 -0700151 return corruptChain.encode();
David Drysdalecceca9f2021-03-12 15:49:47 +0000152}
153
Sean Thomasa737a2d2024-11-20 17:25:53 +0000154template <class T>
155auto getHandle(const string& serviceName) {
156 ::ndk::SpAIBinder binder(AServiceManager_waitForService(serviceName.c_str()));
157 return T::fromBinder(binder);
158}
David Drysdale4d3c2982021-03-31 18:21:40 +0100159
Sean Thomasa737a2d2024-11-20 17:25:53 +0000160std::shared_ptr<IKeyMintDevice> matchingKeyMintDevice(const string& rpcName) {
161 auto rpcSuffix = deviceSuffix(rpcName);
162
163 vector<string> kmNames = ::android::getAidlHalInstanceNames(IKeyMintDevice::descriptor);
164 for (const string& kmName : kmNames) {
David Drysdale4d3c2982021-03-31 18:21:40 +0100165 // If the suffix of the KeyMint instance equals the suffix of the
166 // RemotelyProvisionedComponent instance, assume they match.
Sean Thomasa737a2d2024-11-20 17:25:53 +0000167 if (deviceSuffix(kmName) == rpcSuffix && AServiceManager_isDeclared(kmName.c_str())) {
168 getHandle<IKeyMintDevice>(kmName);
David Drysdale4d3c2982021-03-31 18:21:40 +0100169 }
170 }
Sean Thomasa737a2d2024-11-20 17:25:53 +0000171 return nullptr;
David Drysdale4d3c2982021-03-31 18:21:40 +0100172}
173
Shawn Willden274bb552020-09-30 22:39:22 -0600174} // namespace
175
176class VtsRemotelyProvisionedComponentTests : public testing::TestWithParam<std::string> {
177 public:
178 virtual void SetUp() override {
179 if (AServiceManager_isDeclared(GetParam().c_str())) {
Sean Thomasa737a2d2024-11-20 17:25:53 +0000180 provisionable_ = getHandle<IRemotelyProvisionedComponent>(GetParam());
Shawn Willden274bb552020-09-30 22:39:22 -0600181 }
182 ASSERT_NE(provisionable_, nullptr);
Alice Wang895f4b32023-11-14 07:38:18 +0000183 auto status = provisionable_->getHardwareInfo(&rpcHardwareInfo);
Alice Wangf112ec92024-10-08 07:30:28 +0000184 isRkpVmInstance_ = GetParam() == RKPVM_INSTANCE_NAME;
Karuna Wadheraca6d8cc2024-07-18 14:08:36 +0000185 if (isRkpVmInstance_) {
Alice Wang46ff2862024-05-14 07:07:05 +0000186 if (status.getExceptionCode() == EX_UNSUPPORTED_OPERATION) {
187 GTEST_SKIP() << "The RKP VM is not supported on this system.";
188 }
189 int apiLevel = get_vsr_api_level();
190 if (apiLevel < __ANDROID_API_V__) {
191 GTEST_SKIP() << "The RKP VM is supported only on V+ devices. Vendor API level: "
192 << apiLevel;
193 }
Alice Wang895f4b32023-11-14 07:38:18 +0000194 }
195 ASSERT_TRUE(status.isOk());
Shawn Willden274bb552020-09-30 22:39:22 -0600196 }
197
198 static vector<string> build_params() {
199 auto params = ::android::getAidlHalInstanceNames(IRemotelyProvisionedComponent::descriptor);
200 return params;
201 }
202
203 protected:
204 std::shared_ptr<IRemotelyProvisionedComponent> provisionable_;
subrahmanyamanfb213d62022-02-02 23:10:55 +0000205 RpcHardwareInfo rpcHardwareInfo;
Karuna Wadheraca6d8cc2024-07-18 14:08:36 +0000206 bool isRkpVmInstance_;
Shawn Willden274bb552020-09-30 22:39:22 -0600207};
208
Seth Moorefc86bf42021-12-09 14:07:04 -0800209/**
210 * Verify that every implementation reports a different unique id.
211 */
212TEST(NonParameterizedTests, eachRpcHasAUniqueId) {
213 std::set<std::string> uniqueIds;
214 for (auto hal : ::android::getAidlHalInstanceNames(IRemotelyProvisionedComponent::descriptor)) {
215 ASSERT_TRUE(AServiceManager_isDeclared(hal.c_str()));
Sean Thomasa737a2d2024-11-20 17:25:53 +0000216 auto rpc = getHandle<IRemotelyProvisionedComponent>(hal);
Seth Moorefc86bf42021-12-09 14:07:04 -0800217 ASSERT_NE(rpc, nullptr);
218
219 RpcHardwareInfo hwInfo;
Alice Wang895f4b32023-11-14 07:38:18 +0000220 auto status = rpc->getHardwareInfo(&hwInfo);
Alice Wangf112ec92024-10-08 07:30:28 +0000221 if (hal == RKPVM_INSTANCE_NAME && status.getExceptionCode() == EX_UNSUPPORTED_OPERATION) {
Alice Wang895f4b32023-11-14 07:38:18 +0000222 GTEST_SKIP() << "The RKP VM is not supported on this system.";
223 }
224 ASSERT_TRUE(status.isOk());
Seth Moorefc86bf42021-12-09 14:07:04 -0800225
Tri Vodd12c482022-10-12 22:41:28 +0000226 if (hwInfo.versionNumber >= VERSION_WITH_UNIQUE_ID_SUPPORT) {
Seth Moorefc86bf42021-12-09 14:07:04 -0800227 ASSERT_TRUE(hwInfo.uniqueId);
228 auto [_, wasInserted] = uniqueIds.insert(*hwInfo.uniqueId);
229 EXPECT_TRUE(wasInserted);
230 } else {
231 ASSERT_FALSE(hwInfo.uniqueId);
232 }
233 }
234}
235
Andrew Scull21461522024-03-25 15:08:08 +0000236/**
237 * Verify that the default implementation supports DICE if there is a StrongBox KeyMint instance
238 * on the device.
239 */
240// @VsrTest = 3.10-015
241TEST(NonParameterizedTests, requireDiceOnDefaultInstanceIfStrongboxPresent) {
242 int vsr_api_level = get_vsr_api_level();
243 if (vsr_api_level < 35) {
244 GTEST_SKIP() << "Applies only to VSR API level 35 or newer, this device is: "
245 << vsr_api_level;
246 }
247
248 if (!AServiceManager_isDeclared(KEYMINT_STRONGBOX_INSTANCE_NAME.c_str())) {
249 GTEST_SKIP() << "Strongbox is not present on this device.";
250 }
251
Sean Thomasa737a2d2024-11-20 17:25:53 +0000252 auto rpc = getHandle<IRemotelyProvisionedComponent>(DEFAULT_INSTANCE_NAME);
Andrew Scull21461522024-03-25 15:08:08 +0000253 ASSERT_NE(rpc, nullptr);
254
255 bytevec challenge = randomBytes(64);
256 bytevec csr;
257 auto status = rpc->generateCertificateRequestV2({} /* keysToSign */, challenge, &csr);
258 EXPECT_TRUE(status.isOk()) << status.getDescription();
259
Alice Wangf112ec92024-10-08 07:30:28 +0000260 auto result = isCsrWithProperDiceChain(csr, DEFAULT_INSTANCE_NAME);
Andrew Scull21461522024-03-25 15:08:08 +0000261 ASSERT_TRUE(result) << result.message();
262 ASSERT_TRUE(*result);
263}
264
Sean Thomasa737a2d2024-11-20 17:25:53 +0000265/**
266 * Verify that if a protected VM (also called `avf` or RKP VM) implementation exists, then the
267 * protected VM and the primary KeyMint (also called 'default') implementation's DICE certificate
268 * chain has the same root public key, i.e., the same UDS public key
269 */
270// @VsrTest = 7.1-003.001
271TEST(NonParameterizedTests, equalUdsPubInDiceCertChainForRkpVmAndPrimaryKeyMintInstances) {
272 int apiLevel = get_vsr_api_level();
273 if (apiLevel < 202504) {
274 if (!AServiceManager_isDeclared(RKPVM_INSTANCE_NAME.c_str())) {
275 GTEST_SKIP() << "The RKP VM (" << RKPVM_INSTANCE_NAME
276 << ") is not present on this device.";
277 }
278 } else {
279 ASSERT_TRUE(AServiceManager_isDeclared(RKPVM_INSTANCE_NAME.c_str()));
280 }
281
282 auto rkpVmRpc = getHandle<IRemotelyProvisionedComponent>(RKPVM_INSTANCE_NAME);
283 ASSERT_NE(rkpVmRpc, nullptr) << "The RKP VM (" << RKPVM_INSTANCE_NAME
284 << ") RPC is unavailable.";
285
286 RpcHardwareInfo hardwareInfo;
287 auto status = rkpVmRpc->getHardwareInfo(&hardwareInfo);
288 if (!status.isOk()) {
289 GTEST_SKIP() << "The RKP VM is not supported on this system.";
290 }
291
292 bytevec rkpVmChallenge = randomBytes(MAX_CHALLENGE_SIZE);
293 bytevec rkpVmCsr;
294 auto rkpVmStatus =
295 rkpVmRpc->generateCertificateRequestV2({} /* keysToSign */, rkpVmChallenge, &rkpVmCsr);
296 ASSERT_TRUE(rkpVmStatus.isOk()) << rkpVmStatus.getDescription();
297
298 auto primaryKeyMintRpc = getHandle<IRemotelyProvisionedComponent>(DEFAULT_INSTANCE_NAME);
299 ASSERT_NE(primaryKeyMintRpc, nullptr)
300 << "The Primary KeyMint (" << DEFAULT_INSTANCE_NAME << ") RPC is unavailable.";
301
302 bytevec primaryKeyMintChallenge = randomBytes(MAX_CHALLENGE_SIZE);
303 bytevec primaryKeyMintCsr;
304 auto primaryKeyMintStatus = primaryKeyMintRpc->generateCertificateRequestV2(
305 {} /* keysToSign */, primaryKeyMintChallenge, &primaryKeyMintCsr);
306 ASSERT_TRUE(primaryKeyMintStatus.isOk()) << primaryKeyMintStatus.getDescription();
307
308 auto equal = compareRootPublicKeysInDiceChains(rkpVmCsr, RKPVM_INSTANCE_NAME, primaryKeyMintCsr,
309 DEFAULT_INSTANCE_NAME);
310 ASSERT_TRUE(equal) << equal.message();
311 ASSERT_TRUE(*equal) << "Primary KeyMint and RKP VM RPCs have different UDS public keys";
312}
313
Seth Moorefc86bf42021-12-09 14:07:04 -0800314using GetHardwareInfoTests = VtsRemotelyProvisionedComponentTests;
315
316INSTANTIATE_REM_PROV_AIDL_TEST(GetHardwareInfoTests);
317
318/**
319 * Verify that a valid curve is reported by the implementation.
320 */
321TEST_P(GetHardwareInfoTests, supportsValidCurve) {
322 RpcHardwareInfo hwInfo;
323 ASSERT_TRUE(provisionable_->getHardwareInfo(&hwInfo).isOk());
324
Andrew Scullf2ae1932023-04-24 19:09:09 +0000325 if (rpcHardwareInfo.versionNumber >= VERSION_WITHOUT_EEK) {
326 ASSERT_EQ(hwInfo.supportedEekCurve, RpcHardwareInfo::CURVE_NONE)
327 << "Invalid curve: " << hwInfo.supportedEekCurve;
328 return;
Hasini Gunasinghe666b2712023-01-05 21:35:51 +0000329 }
Andrew Scullf2ae1932023-04-24 19:09:09 +0000330
331 const std::set<int> validCurves = {RpcHardwareInfo::CURVE_P256, RpcHardwareInfo::CURVE_25519};
Seth Moorefc86bf42021-12-09 14:07:04 -0800332 ASSERT_EQ(validCurves.count(hwInfo.supportedEekCurve), 1)
333 << "Invalid curve: " << hwInfo.supportedEekCurve;
334}
335
336/**
337 * Verify that the unique id is within the length limits as described in RpcHardwareInfo.aidl.
338 */
339TEST_P(GetHardwareInfoTests, uniqueId) {
Tri Vodd12c482022-10-12 22:41:28 +0000340 if (rpcHardwareInfo.versionNumber < VERSION_WITH_UNIQUE_ID_SUPPORT) {
Seth Moorefc86bf42021-12-09 14:07:04 -0800341 return;
342 }
343
344 RpcHardwareInfo hwInfo;
345 ASSERT_TRUE(provisionable_->getHardwareInfo(&hwInfo).isOk());
346 ASSERT_TRUE(hwInfo.uniqueId);
347 EXPECT_GE(hwInfo.uniqueId->size(), 1);
348 EXPECT_LE(hwInfo.uniqueId->size(), 32);
349}
350
Tri Vo9cab73c2022-10-28 13:40:24 -0700351/**
352 * Verify implementation supports at least MIN_SUPPORTED_NUM_KEYS_IN_CSR keys in a CSR.
353 */
354TEST_P(GetHardwareInfoTests, supportedNumKeysInCsr) {
Andrew Scullf2ae1932023-04-24 19:09:09 +0000355 if (rpcHardwareInfo.versionNumber < VERSION_WITH_SUPPORTED_NUM_KEYS_IN_CSR) {
Tri Vo9cab73c2022-10-28 13:40:24 -0700356 return;
357 }
358
359 RpcHardwareInfo hwInfo;
360 ASSERT_TRUE(provisionable_->getHardwareInfo(&hwInfo).isOk());
361 ASSERT_GE(hwInfo.supportedNumKeysInCsr, RpcHardwareInfo::MIN_SUPPORTED_NUM_KEYS_IN_CSR);
362}
363
Shawn Willden274bb552020-09-30 22:39:22 -0600364using GenerateKeyTests = VtsRemotelyProvisionedComponentTests;
365
366INSTANTIATE_REM_PROV_AIDL_TEST(GenerateKeyTests);
367
368/**
David Drysdalef0d516d2021-03-22 07:51:43 +0000369 * Generate and validate a production-mode key. MAC tag can't be verified, but
370 * the private key blob should be usable in KeyMint operations.
Shawn Willden274bb552020-09-30 22:39:22 -0600371 */
Max Bires126869a2021-02-21 18:32:59 -0800372TEST_P(GenerateKeyTests, generateEcdsaP256Key_prodMode) {
Shawn Willden274bb552020-09-30 22:39:22 -0600373 MacedPublicKey macedPubKey;
374 bytevec privateKeyBlob;
375 bool testMode = false;
376 auto status = provisionable_->generateEcdsaP256KeyPair(testMode, &macedPubKey, &privateKeyBlob);
377 ASSERT_TRUE(status.isOk());
David Drysdalef0d516d2021-03-22 07:51:43 +0000378 vector<uint8_t> coseKeyData;
Tri Vob0b8acc2022-11-30 16:22:23 -0800379 check_maced_pubkey(macedPubKey, testMode, &coseKeyData);
David Drysdale4d3c2982021-03-31 18:21:40 +0100380}
381
382/**
383 * Generate and validate a production-mode key, then use it as a KeyMint attestation key.
384 */
385TEST_P(GenerateKeyTests, generateAndUseEcdsaP256Key_prodMode) {
386 // See if there is a matching IKeyMintDevice for this IRemotelyProvisionedComponent.
Sean Thomasa737a2d2024-11-20 17:25:53 +0000387 auto keyMint = matchingKeyMintDevice(GetParam());
388 if (!keyMint) {
David Drysdale4d3c2982021-03-31 18:21:40 +0100389 GTEST_SKIP() << "Skipping key use test as no matching KeyMint device found";
390 return;
391 }
392 KeyMintHardwareInfo info;
393 ASSERT_TRUE(keyMint->getHardwareInfo(&info).isOk());
394
395 MacedPublicKey macedPubKey;
396 bytevec privateKeyBlob;
397 bool testMode = false;
398 auto status = provisionable_->generateEcdsaP256KeyPair(testMode, &macedPubKey, &privateKeyBlob);
399 ASSERT_TRUE(status.isOk());
400 vector<uint8_t> coseKeyData;
Tri Vob0b8acc2022-11-30 16:22:23 -0800401 check_maced_pubkey(macedPubKey, testMode, &coseKeyData);
David Drysdale4d3c2982021-03-31 18:21:40 +0100402
David Drysdalef0d516d2021-03-22 07:51:43 +0000403 AttestationKey attestKey;
404 attestKey.keyBlob = std::move(privateKeyBlob);
405 attestKey.issuerSubjectName = make_name_from_str("Android Keystore Key");
Shawn Willden274bb552020-09-30 22:39:22 -0600406
David Drysdalef0d516d2021-03-22 07:51:43 +0000407 // Generate an ECDSA key that is attested by the generated P256 keypair.
408 AuthorizationSet keyDesc = AuthorizationSetBuilder()
409 .Authorization(TAG_NO_AUTH_REQUIRED)
David Drysdale915ce252021-10-14 15:17:36 +0100410 .EcdsaSigningKey(EcCurve::P_256)
David Drysdalef0d516d2021-03-22 07:51:43 +0000411 .AttestationChallenge("foo")
412 .AttestationApplicationId("bar")
413 .Digest(Digest::NONE)
414 .SetDefaultValidity();
415 KeyCreationResult creationResult;
416 auto result = keyMint->generateKey(keyDesc.vector_data(), attestKey, &creationResult);
417 ASSERT_TRUE(result.isOk());
418 vector<uint8_t> attested_key_blob = std::move(creationResult.keyBlob);
419 vector<KeyCharacteristics> attested_key_characteristics =
420 std::move(creationResult.keyCharacteristics);
421 vector<Certificate> attested_key_cert_chain = std::move(creationResult.certificateChain);
422 EXPECT_EQ(attested_key_cert_chain.size(), 1);
423
David Drysdale7dff4fc2021-12-10 10:10:52 +0000424 int32_t aidl_version = 0;
425 ASSERT_TRUE(keyMint->getInterfaceVersion(&aidl_version).isOk());
David Drysdalef0d516d2021-03-22 07:51:43 +0000426 AuthorizationSet hw_enforced = HwEnforcedAuthorizations(attested_key_characteristics);
427 AuthorizationSet sw_enforced = SwEnforcedAuthorizations(attested_key_characteristics);
David Drysdale7dff4fc2021-12-10 10:10:52 +0000428 EXPECT_TRUE(verify_attestation_record(aidl_version, "foo", "bar", sw_enforced, hw_enforced,
David Drysdalef0d516d2021-03-22 07:51:43 +0000429 info.securityLevel,
430 attested_key_cert_chain[0].encodedCertificate));
431
432 // Attestation by itself is not valid (last entry is not self-signed).
433 EXPECT_FALSE(ChainSignaturesAreValid(attested_key_cert_chain));
434
435 // The signature over the attested key should correspond to the P256 public key.
436 X509_Ptr key_cert(parse_cert_blob(attested_key_cert_chain[0].encodedCertificate));
437 ASSERT_TRUE(key_cert.get());
438 EVP_PKEY_Ptr signing_pubkey;
439 p256_pub_key(coseKeyData, &signing_pubkey);
440 ASSERT_TRUE(signing_pubkey.get());
441
442 ASSERT_TRUE(X509_verify(key_cert.get(), signing_pubkey.get()))
443 << "Verification of attested certificate failed "
444 << "OpenSSL error string: " << ERR_error_string(ERR_get_error(), NULL);
Shawn Willden274bb552020-09-30 22:39:22 -0600445}
446
447/**
448 * Generate and validate a test-mode key.
449 */
Max Bires126869a2021-02-21 18:32:59 -0800450TEST_P(GenerateKeyTests, generateEcdsaP256Key_testMode) {
Shawn Willden274bb552020-09-30 22:39:22 -0600451 MacedPublicKey macedPubKey;
452 bytevec privateKeyBlob;
453 bool testMode = true;
454 auto status = provisionable_->generateEcdsaP256KeyPair(testMode, &macedPubKey, &privateKeyBlob);
Andrew Scullf2ae1932023-04-24 19:09:09 +0000455
456 if (rpcHardwareInfo.versionNumber >= VERSION_WITHOUT_TEST_MODE) {
457 ASSERT_FALSE(status.isOk());
458 EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_REMOVED);
459 return;
460 }
461
Shawn Willden274bb552020-09-30 22:39:22 -0600462 ASSERT_TRUE(status.isOk());
Tri Vob0b8acc2022-11-30 16:22:23 -0800463 check_maced_pubkey(macedPubKey, testMode, nullptr);
Shawn Willden274bb552020-09-30 22:39:22 -0600464}
465
Sean Thomasf2946ab2024-11-27 18:09:46 +0000466/**
467 * Generate and validate at most 2**16 production-mode keys. This aims to catch issues that do not
468 * deterministically show up. In practice, this will test far fewer keys, but a certain number are
469 * tested at a minimum.
470 */
471TEST_P(GenerateKeyTests, generateManyEcdsaP256KeysInProdMode) {
472 const auto start = std::chrono::steady_clock::now();
473 const auto time_bound = std::chrono::seconds(5);
474 const auto upper_bound = 1 << 16;
475 const auto lower_bound = 1 << 8;
476 for (auto iteration = 0; iteration < upper_bound; iteration++) {
477 MacedPublicKey macedPubKey;
478 bytevec privateKeyBlob;
479 bool testMode = false;
480 auto status =
481 provisionable_->generateEcdsaP256KeyPair(testMode, &macedPubKey, &privateKeyBlob);
482 ASSERT_TRUE(status.isOk());
483 vector<uint8_t> coseKeyData;
484 check_maced_pubkey(macedPubKey, testMode, &coseKeyData);
485 const auto current_time = std::chrono::steady_clock::now() - start;
486 if (iteration >= lower_bound && current_time >= time_bound) {
487 break;
488 }
489 }
490}
491
Tri Vo0d6204e2022-09-29 16:15:34 -0700492class CertificateRequestTestBase : public VtsRemotelyProvisionedComponentTests {
Shawn Willden274bb552020-09-30 22:39:22 -0600493 protected:
Tri Vo0d6204e2022-09-29 16:15:34 -0700494 CertificateRequestTestBase()
495 : eekId_(string_to_bytevec("eekid")), challenge_(randomBytes(64)) {}
David Drysdalecceca9f2021-03-12 15:49:47 +0000496
Seth Moore19acbe92021-06-23 15:15:52 -0700497 void generateTestEekChain(size_t eekLength) {
subrahmanyamanfb213d62022-02-02 23:10:55 +0000498 auto chain = generateEekChain(rpcHardwareInfo.supportedEekCurve, eekLength, eekId_);
David Drysdale08696a72022-03-10 10:43:25 +0000499 ASSERT_TRUE(chain) << chain.message();
Seth Moore19acbe92021-06-23 15:15:52 -0700500 if (chain) testEekChain_ = chain.moveValue();
501 testEekLength_ = eekLength;
Shawn Willden274bb552020-09-30 22:39:22 -0600502 }
503
504 void generateKeys(bool testMode, size_t numKeys) {
505 keysToSign_ = std::vector<MacedPublicKey>(numKeys);
506 cborKeysToSign_ = cppbor::Array();
507
508 for (auto& key : keysToSign_) {
509 bytevec privateKeyBlob;
510 auto status = provisionable_->generateEcdsaP256KeyPair(testMode, &key, &privateKeyBlob);
Frederick Mayle9891be02023-11-03 14:39:24 -0700511 ASSERT_TRUE(status.isOk()) << status.getDescription();
Shawn Willden274bb552020-09-30 22:39:22 -0600512
David Drysdalec8400772021-03-11 12:35:11 +0000513 vector<uint8_t> payload_value;
Tri Vob0b8acc2022-11-30 16:22:23 -0800514 check_maced_pubkey(key, testMode, &payload_value);
David Drysdalec8400772021-03-11 12:35:11 +0000515 cborKeysToSign_.add(cppbor::EncodedItem(payload_value));
Shawn Willden274bb552020-09-30 22:39:22 -0600516 }
517 }
518
519 bytevec eekId_;
Seth Moore19acbe92021-06-23 15:15:52 -0700520 size_t testEekLength_;
521 EekChain testEekChain_;
David Drysdalec8400772021-03-11 12:35:11 +0000522 bytevec challenge_;
Shawn Willden274bb552020-09-30 22:39:22 -0600523 std::vector<MacedPublicKey> keysToSign_;
524 cppbor::Array cborKeysToSign_;
525};
526
Tri Vo0d6204e2022-09-29 16:15:34 -0700527class CertificateRequestTest : public CertificateRequestTestBase {
528 protected:
529 void SetUp() override {
530 CertificateRequestTestBase::SetUp();
Andrew Scull1bcb6022022-12-27 10:43:27 +0000531 ASSERT_FALSE(HasFatalFailure());
Tri Vo0d6204e2022-09-29 16:15:34 -0700532
Andrew Scullf2ae1932023-04-24 19:09:09 +0000533 if (rpcHardwareInfo.versionNumber >= VERSION_WITH_CERTIFICATE_REQUEST_V2) {
Andrew Scull95b31312023-03-27 19:16:07 +0000534 GTEST_SKIP() << "This test case only applies to RKP v1 and v2. "
535 << "RKP version discovered: " << rpcHardwareInfo.versionNumber;
Tri Vo0d6204e2022-09-29 16:15:34 -0700536 }
537 }
538};
539
Shawn Willden274bb552020-09-30 22:39:22 -0600540/**
541 * Generate an empty certificate request in test mode, and decrypt and verify the structure and
542 * content.
543 */
Max Bires126869a2021-02-21 18:32:59 -0800544TEST_P(CertificateRequestTest, EmptyRequest_testMode) {
Shawn Willden274bb552020-09-30 22:39:22 -0600545 bool testMode = true;
David Drysdalecceca9f2021-03-12 15:49:47 +0000546 for (size_t eekLength : {2, 3, 7}) {
547 SCOPED_TRACE(testing::Message() << "EEK of length " << eekLength);
Seth Moore19acbe92021-06-23 15:15:52 -0700548 generateTestEekChain(eekLength);
Shawn Willden274bb552020-09-30 22:39:22 -0600549
David Drysdalecceca9f2021-03-12 15:49:47 +0000550 bytevec keysToSignMac;
551 DeviceInfo deviceInfo;
552 ProtectedData protectedData;
553 auto status = provisionable_->generateCertificateRequest(
Seth Moore19acbe92021-06-23 15:15:52 -0700554 testMode, {} /* keysToSign */, testEekChain_.chain, challenge_, &deviceInfo,
David Drysdalecceca9f2021-03-12 15:49:47 +0000555 &protectedData, &keysToSignMac);
Frederick Mayle9891be02023-11-03 14:39:24 -0700556 ASSERT_TRUE(status.isOk()) << status.getDescription();
David Drysdalecceca9f2021-03-12 15:49:47 +0000557
Sean Thomas2d2385b2024-11-07 23:56:03 +0000558 auto result = verifyProductionProtectedData(deviceInfo, cppbor::Array(), keysToSignMac,
559 protectedData, testEekChain_, eekId_,
560 rpcHardwareInfo, GetParam(), challenge_);
Seth Moore2fc6f832022-09-13 16:10:11 -0700561 ASSERT_TRUE(result) << result.message();
David Drysdalecceca9f2021-03-12 15:49:47 +0000562 }
Shawn Willden274bb552020-09-30 22:39:22 -0600563}
564
565/**
Seth Moore42c11332021-07-02 15:38:17 -0700566 * Ensure that test mode outputs a unique BCC root key every time we request a
567 * certificate request. Else, it's possible that the test mode API could be used
568 * to fingerprint devices. Only the GEEK should be allowed to decrypt the same
569 * device public key multiple times.
570 */
571TEST_P(CertificateRequestTest, NewKeyPerCallInTestMode) {
572 constexpr bool testMode = true;
Seth Moore42c11332021-07-02 15:38:17 -0700573
574 bytevec keysToSignMac;
575 DeviceInfo deviceInfo;
576 ProtectedData protectedData;
subrahmanyamanfb213d62022-02-02 23:10:55 +0000577 generateTestEekChain(3);
Seth Moore42c11332021-07-02 15:38:17 -0700578 auto status = provisionable_->generateCertificateRequest(
Seth Moore19acbe92021-06-23 15:15:52 -0700579 testMode, {} /* keysToSign */, testEekChain_.chain, challenge_, &deviceInfo,
580 &protectedData, &keysToSignMac);
Frederick Mayle9891be02023-11-03 14:39:24 -0700581 ASSERT_TRUE(status.isOk()) << status.getDescription();
Seth Moore42c11332021-07-02 15:38:17 -0700582
Alice Wangf112ec92024-10-08 07:30:28 +0000583 auto firstBcc = verifyProductionProtectedData(deviceInfo, /*keysToSign=*/cppbor::Array(),
584 keysToSignMac, protectedData, testEekChain_,
Sean Thomas2d2385b2024-11-07 23:56:03 +0000585 eekId_, rpcHardwareInfo, GetParam(), challenge_);
Seth Moore2fc6f832022-09-13 16:10:11 -0700586 ASSERT_TRUE(firstBcc) << firstBcc.message();
Seth Moore42c11332021-07-02 15:38:17 -0700587
Seth Moore19acbe92021-06-23 15:15:52 -0700588 status = provisionable_->generateCertificateRequest(
589 testMode, {} /* keysToSign */, testEekChain_.chain, challenge_, &deviceInfo,
590 &protectedData, &keysToSignMac);
Frederick Mayle9891be02023-11-03 14:39:24 -0700591 ASSERT_TRUE(status.isOk()) << status.getDescription();
Seth Moore42c11332021-07-02 15:38:17 -0700592
Alice Wangf112ec92024-10-08 07:30:28 +0000593 auto secondBcc = verifyProductionProtectedData(deviceInfo, /*keysToSign=*/cppbor::Array(),
594 keysToSignMac, protectedData, testEekChain_,
Sean Thomas2d2385b2024-11-07 23:56:03 +0000595 eekId_, rpcHardwareInfo, GetParam(), challenge_);
Seth Moore2fc6f832022-09-13 16:10:11 -0700596 ASSERT_TRUE(secondBcc) << secondBcc.message();
Seth Moore42c11332021-07-02 15:38:17 -0700597
598 // Verify that none of the keys in the first BCC are repeated in the second one.
Seth Moore2fc6f832022-09-13 16:10:11 -0700599 for (const auto& i : *firstBcc) {
600 for (auto& j : *secondBcc) {
Seth Moore42c11332021-07-02 15:38:17 -0700601 ASSERT_THAT(i.pubKey, testing::Not(testing::ElementsAreArray(j.pubKey)))
602 << "Found a repeated pubkey in two generateCertificateRequest test mode calls";
603 }
604 }
605}
606
607/**
Seth Moore19acbe92021-06-23 15:15:52 -0700608 * Generate an empty certificate request in prod mode. This test must be run explicitly, and
609 * is not run by default. Not all devices are GMS devices, and therefore they do not all
610 * trust the Google EEK root.
Shawn Willden274bb552020-09-30 22:39:22 -0600611 */
Seth Moore19acbe92021-06-23 15:15:52 -0700612TEST_P(CertificateRequestTest, DISABLED_EmptyRequest_prodMode) {
Shawn Willden274bb552020-09-30 22:39:22 -0600613 bool testMode = false;
David Drysdalecceca9f2021-03-12 15:49:47 +0000614
Seth Moore19acbe92021-06-23 15:15:52 -0700615 bytevec keysToSignMac;
616 DeviceInfo deviceInfo;
617 ProtectedData protectedData;
618 auto status = provisionable_->generateCertificateRequest(
subrahmanyamanfb213d62022-02-02 23:10:55 +0000619 testMode, {} /* keysToSign */, getProdEekChain(rpcHardwareInfo.supportedEekCurve),
620 challenge_, &deviceInfo, &protectedData, &keysToSignMac);
Seth Moore19acbe92021-06-23 15:15:52 -0700621 EXPECT_TRUE(status.isOk());
Shawn Willden274bb552020-09-30 22:39:22 -0600622}
623
624/**
625 * Generate a non-empty certificate request in test mode. Decrypt, parse and validate the contents.
626 */
Max Bires126869a2021-02-21 18:32:59 -0800627TEST_P(CertificateRequestTest, NonEmptyRequest_testMode) {
Shawn Willden274bb552020-09-30 22:39:22 -0600628 bool testMode = true;
629 generateKeys(testMode, 4 /* numKeys */);
630
David Drysdalecceca9f2021-03-12 15:49:47 +0000631 for (size_t eekLength : {2, 3, 7}) {
632 SCOPED_TRACE(testing::Message() << "EEK of length " << eekLength);
Seth Moore19acbe92021-06-23 15:15:52 -0700633 generateTestEekChain(eekLength);
Shawn Willden274bb552020-09-30 22:39:22 -0600634
David Drysdalecceca9f2021-03-12 15:49:47 +0000635 bytevec keysToSignMac;
636 DeviceInfo deviceInfo;
637 ProtectedData protectedData;
638 auto status = provisionable_->generateCertificateRequest(
Seth Moore19acbe92021-06-23 15:15:52 -0700639 testMode, keysToSign_, testEekChain_.chain, challenge_, &deviceInfo, &protectedData,
David Drysdalecceca9f2021-03-12 15:49:47 +0000640 &keysToSignMac);
Frederick Mayle9891be02023-11-03 14:39:24 -0700641 ASSERT_TRUE(status.isOk()) << status.getDescription();
David Drysdalecceca9f2021-03-12 15:49:47 +0000642
Sean Thomas2d2385b2024-11-07 23:56:03 +0000643 auto result = verifyProductionProtectedData(deviceInfo, cborKeysToSign_, keysToSignMac,
644 protectedData, testEekChain_, eekId_,
645 rpcHardwareInfo, GetParam(), challenge_);
Seth Moore2fc6f832022-09-13 16:10:11 -0700646 ASSERT_TRUE(result) << result.message();
David Drysdalecceca9f2021-03-12 15:49:47 +0000647 }
Shawn Willden274bb552020-09-30 22:39:22 -0600648}
649
650/**
Seth Moore19acbe92021-06-23 15:15:52 -0700651 * Generate a non-empty certificate request in prod mode. This test must be run explicitly, and
652 * is not run by default. Not all devices are GMS devices, and therefore they do not all
653 * trust the Google EEK root.
Shawn Willden274bb552020-09-30 22:39:22 -0600654 */
Seth Moore19acbe92021-06-23 15:15:52 -0700655TEST_P(CertificateRequestTest, DISABLED_NonEmptyRequest_prodMode) {
Shawn Willden274bb552020-09-30 22:39:22 -0600656 bool testMode = false;
657 generateKeys(testMode, 4 /* numKeys */);
658
Seth Moore19acbe92021-06-23 15:15:52 -0700659 bytevec keysToSignMac;
660 DeviceInfo deviceInfo;
661 ProtectedData protectedData;
662 auto status = provisionable_->generateCertificateRequest(
subrahmanyamanfb213d62022-02-02 23:10:55 +0000663 testMode, keysToSign_, getProdEekChain(rpcHardwareInfo.supportedEekCurve), challenge_,
664 &deviceInfo, &protectedData, &keysToSignMac);
Seth Moore19acbe92021-06-23 15:15:52 -0700665 EXPECT_TRUE(status.isOk());
David Drysdalecceca9f2021-03-12 15:49:47 +0000666}
667
668/**
David Drysdalee99ed862021-03-15 16:43:06 +0000669 * Generate a non-empty certificate request in test mode, but with the MAC corrupted on the keypair.
670 */
671TEST_P(CertificateRequestTest, NonEmptyRequestCorruptMac_testMode) {
672 bool testMode = true;
673 generateKeys(testMode, 1 /* numKeys */);
David Drysdale08696a72022-03-10 10:43:25 +0000674 auto result = corrupt_maced_key(keysToSign_[0]);
675 ASSERT_TRUE(result) << result.moveMessage();
676 MacedPublicKey keyWithCorruptMac = result.moveValue();
David Drysdalee99ed862021-03-15 16:43:06 +0000677
678 bytevec keysToSignMac;
679 DeviceInfo deviceInfo;
680 ProtectedData protectedData;
subrahmanyamanfb213d62022-02-02 23:10:55 +0000681 generateTestEekChain(3);
David Drysdalee99ed862021-03-15 16:43:06 +0000682 auto status = provisionable_->generateCertificateRequest(
Seth Moore19acbe92021-06-23 15:15:52 -0700683 testMode, {keyWithCorruptMac}, testEekChain_.chain, challenge_, &deviceInfo,
684 &protectedData, &keysToSignMac);
Frederick Mayle9891be02023-11-03 14:39:24 -0700685 ASSERT_FALSE(status.isOk()) << status.getDescription();
David Drysdalee99ed862021-03-15 16:43:06 +0000686 EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_INVALID_MAC);
687}
688
689/**
690 * Generate a non-empty certificate request in prod mode, but with the MAC corrupted on the keypair.
691 */
692TEST_P(CertificateRequestTest, NonEmptyRequestCorruptMac_prodMode) {
Seth Moore19acbe92021-06-23 15:15:52 -0700693 bool testMode = false;
David Drysdalee99ed862021-03-15 16:43:06 +0000694 generateKeys(testMode, 1 /* numKeys */);
David Drysdale08696a72022-03-10 10:43:25 +0000695 auto result = corrupt_maced_key(keysToSign_[0]);
696 ASSERT_TRUE(result) << result.moveMessage();
697 MacedPublicKey keyWithCorruptMac = result.moveValue();
David Drysdalee99ed862021-03-15 16:43:06 +0000698
699 bytevec keysToSignMac;
700 DeviceInfo deviceInfo;
701 ProtectedData protectedData;
702 auto status = provisionable_->generateCertificateRequest(
subrahmanyamanfb213d62022-02-02 23:10:55 +0000703 testMode, {keyWithCorruptMac}, getProdEekChain(rpcHardwareInfo.supportedEekCurve),
704 challenge_, &deviceInfo, &protectedData, &keysToSignMac);
Frederick Mayle9891be02023-11-03 14:39:24 -0700705 ASSERT_FALSE(status.isOk()) << status.getDescription();
Seth Moore19acbe92021-06-23 15:15:52 -0700706 EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_INVALID_MAC);
David Drysdalee99ed862021-03-15 16:43:06 +0000707}
708
709/**
David Drysdalecceca9f2021-03-12 15:49:47 +0000710 * Generate a non-empty certificate request in prod mode that has a corrupt EEK chain.
711 * Confirm that the request is rejected.
David Drysdalecceca9f2021-03-12 15:49:47 +0000712 */
713TEST_P(CertificateRequestTest, NonEmptyCorruptEekRequest_prodMode) {
714 bool testMode = false;
715 generateKeys(testMode, 4 /* numKeys */);
716
subrahmanyamanfb213d62022-02-02 23:10:55 +0000717 auto prodEekChain = getProdEekChain(rpcHardwareInfo.supportedEekCurve);
Seth Moore19acbe92021-06-23 15:15:52 -0700718 auto [parsedChain, _, parseErr] = cppbor::parse(prodEekChain);
719 ASSERT_NE(parsedChain, nullptr) << parseErr;
720 ASSERT_NE(parsedChain->asArray(), nullptr);
721
722 for (int ii = 0; ii < parsedChain->asArray()->size(); ++ii) {
723 auto chain = corrupt_sig_chain(prodEekChain, ii);
David Drysdalecceca9f2021-03-12 15:49:47 +0000724 ASSERT_TRUE(chain) << chain.message();
David Drysdalecceca9f2021-03-12 15:49:47 +0000725
726 bytevec keysToSignMac;
727 DeviceInfo deviceInfo;
728 ProtectedData protectedData;
Seth Moore19acbe92021-06-23 15:15:52 -0700729 auto status = provisionable_->generateCertificateRequest(testMode, keysToSign_, *chain,
730 challenge_, &deviceInfo,
731 &protectedData, &keysToSignMac);
David Drysdalecceca9f2021-03-12 15:49:47 +0000732 ASSERT_FALSE(status.isOk());
733 ASSERT_EQ(status.getServiceSpecificError(),
734 BnRemotelyProvisionedComponent::STATUS_INVALID_EEK);
735 }
736}
737
738/**
739 * Generate a non-empty certificate request in prod mode that has an incomplete EEK chain.
740 * Confirm that the request is rejected.
David Drysdalecceca9f2021-03-12 15:49:47 +0000741 */
742TEST_P(CertificateRequestTest, NonEmptyIncompleteEekRequest_prodMode) {
743 bool testMode = false;
744 generateKeys(testMode, 4 /* numKeys */);
745
746 // Build an EEK chain that omits the first self-signed cert.
747 auto truncatedChain = cppbor::Array();
subrahmanyamanfb213d62022-02-02 23:10:55 +0000748 auto [chain, _, parseErr] = cppbor::parse(getProdEekChain(rpcHardwareInfo.supportedEekCurve));
David Drysdalecceca9f2021-03-12 15:49:47 +0000749 ASSERT_TRUE(chain);
750 auto eekChain = chain->asArray();
751 ASSERT_NE(eekChain, nullptr);
752 for (size_t ii = 1; ii < eekChain->size(); ii++) {
753 truncatedChain.add(eekChain->get(ii)->clone());
754 }
755
Shawn Willden274bb552020-09-30 22:39:22 -0600756 bytevec keysToSignMac;
Max Biresfdbb9042021-03-23 12:43:38 -0700757 DeviceInfo deviceInfo;
Shawn Willden274bb552020-09-30 22:39:22 -0600758 ProtectedData protectedData;
David Drysdalecceca9f2021-03-12 15:49:47 +0000759 auto status = provisionable_->generateCertificateRequest(
760 testMode, keysToSign_, truncatedChain.encode(), challenge_, &deviceInfo, &protectedData,
761 &keysToSignMac);
Shawn Willden274bb552020-09-30 22:39:22 -0600762 ASSERT_FALSE(status.isOk());
763 ASSERT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_INVALID_EEK);
764}
765
766/**
767 * Generate a non-empty certificate request in test mode, with prod keys. Must fail with
768 * STATUS_PRODUCTION_KEY_IN_TEST_REQUEST.
769 */
Max Bires126869a2021-02-21 18:32:59 -0800770TEST_P(CertificateRequestTest, NonEmptyRequest_prodKeyInTestCert) {
Shawn Willden274bb552020-09-30 22:39:22 -0600771 generateKeys(false /* testMode */, 2 /* numKeys */);
772
773 bytevec keysToSignMac;
Max Biresfdbb9042021-03-23 12:43:38 -0700774 DeviceInfo deviceInfo;
Shawn Willden274bb552020-09-30 22:39:22 -0600775 ProtectedData protectedData;
subrahmanyamanfb213d62022-02-02 23:10:55 +0000776 generateTestEekChain(3);
Max Biresfdbb9042021-03-23 12:43:38 -0700777 auto status = provisionable_->generateCertificateRequest(
Seth Moore19acbe92021-06-23 15:15:52 -0700778 true /* testMode */, keysToSign_, testEekChain_.chain, challenge_, &deviceInfo,
Max Biresfdbb9042021-03-23 12:43:38 -0700779 &protectedData, &keysToSignMac);
Shawn Willden274bb552020-09-30 22:39:22 -0600780 ASSERT_FALSE(status.isOk());
781 ASSERT_EQ(status.getServiceSpecificError(),
782 BnRemotelyProvisionedComponent::STATUS_PRODUCTION_KEY_IN_TEST_REQUEST);
783}
784
785/**
786 * Generate a non-empty certificate request in prod mode, with test keys. Must fail with
787 * STATUS_TEST_KEY_IN_PRODUCTION_REQUEST.
788 */
Max Bires126869a2021-02-21 18:32:59 -0800789TEST_P(CertificateRequestTest, NonEmptyRequest_testKeyInProdCert) {
Shawn Willden274bb552020-09-30 22:39:22 -0600790 generateKeys(true /* testMode */, 2 /* numKeys */);
791
792 bytevec keysToSignMac;
Max Biresfdbb9042021-03-23 12:43:38 -0700793 DeviceInfo deviceInfo;
Shawn Willden274bb552020-09-30 22:39:22 -0600794 ProtectedData protectedData;
subrahmanyamanfb213d62022-02-02 23:10:55 +0000795 generateTestEekChain(3);
Shawn Willden274bb552020-09-30 22:39:22 -0600796 auto status = provisionable_->generateCertificateRequest(
Seth Moore19acbe92021-06-23 15:15:52 -0700797 false /* testMode */, keysToSign_, testEekChain_.chain, challenge_, &deviceInfo,
David Drysdalec8400772021-03-11 12:35:11 +0000798 &protectedData, &keysToSignMac);
Shawn Willden274bb552020-09-30 22:39:22 -0600799 ASSERT_FALSE(status.isOk());
800 ASSERT_EQ(status.getServiceSpecificError(),
801 BnRemotelyProvisionedComponent::STATUS_TEST_KEY_IN_PRODUCTION_REQUEST);
802}
803
804INSTANTIATE_REM_PROV_AIDL_TEST(CertificateRequestTest);
805
Tri Vo0d6204e2022-09-29 16:15:34 -0700806class CertificateRequestV2Test : public CertificateRequestTestBase {
807 void SetUp() override {
808 CertificateRequestTestBase::SetUp();
Andrew Scull1bcb6022022-12-27 10:43:27 +0000809 ASSERT_FALSE(HasFatalFailure());
Tri Vo0d6204e2022-09-29 16:15:34 -0700810
Andrew Scullf2ae1932023-04-24 19:09:09 +0000811 if (rpcHardwareInfo.versionNumber < VERSION_WITH_CERTIFICATE_REQUEST_V2) {
Tri Vo0d6204e2022-09-29 16:15:34 -0700812 GTEST_SKIP() << "This test case only applies to RKP v3 and above. "
813 << "RKP version discovered: " << rpcHardwareInfo.versionNumber;
814 }
815 }
816};
817
818/**
Tommy Chiufde3ad12023-03-17 05:58:28 +0000819 * Generate an empty certificate request with all possible length of challenge, and decrypt and
820 * verify the structure and content.
Tri Vo0d6204e2022-09-29 16:15:34 -0700821 */
Seth Mooreac1639f2023-04-27 11:14:11 -0700822// @VsrTest = 3.10-015
Tri Vo0d6204e2022-09-29 16:15:34 -0700823TEST_P(CertificateRequestV2Test, EmptyRequest) {
824 bytevec csr;
825
Tommy Chiufde3ad12023-03-17 05:58:28 +0000826 for (auto size = MIN_CHALLENGE_SIZE; size <= MAX_CHALLENGE_SIZE; size++) {
827 SCOPED_TRACE(testing::Message() << "challenge[" << size << "]");
828 auto challenge = randomBytes(size);
829 auto status =
830 provisionable_->generateCertificateRequestV2({} /* keysToSign */, challenge, &csr);
Frederick Mayle9891be02023-11-03 14:39:24 -0700831 ASSERT_TRUE(status.isOk()) << status.getDescription();
Tri Vo0d6204e2022-09-29 16:15:34 -0700832
Sean Thomas2d2385b2024-11-07 23:56:03 +0000833 auto result = verifyProductionCsr(cppbor::Array(), csr, rpcHardwareInfo, GetParam(),
Alice Wangf112ec92024-10-08 07:30:28 +0000834 challenge, isRkpVmInstance_);
Tommy Chiufde3ad12023-03-17 05:58:28 +0000835 ASSERT_TRUE(result) << result.message();
836 }
Tri Vo0d6204e2022-09-29 16:15:34 -0700837}
838
839/**
Tommy Chiufde3ad12023-03-17 05:58:28 +0000840 * Generate a non-empty certificate request with all possible length of challenge. Decrypt, parse
841 * and validate the contents.
Tri Vo0d6204e2022-09-29 16:15:34 -0700842 */
Seth Mooreac1639f2023-04-27 11:14:11 -0700843// @VsrTest = 3.10-015
Tri Vo0d6204e2022-09-29 16:15:34 -0700844TEST_P(CertificateRequestV2Test, NonEmptyRequest) {
845 generateKeys(false /* testMode */, 1 /* numKeys */);
846
847 bytevec csr;
848
Tommy Chiufde3ad12023-03-17 05:58:28 +0000849 for (auto size = MIN_CHALLENGE_SIZE; size <= MAX_CHALLENGE_SIZE; size++) {
850 SCOPED_TRACE(testing::Message() << "challenge[" << size << "]");
851 auto challenge = randomBytes(size);
852 auto status = provisionable_->generateCertificateRequestV2(keysToSign_, challenge, &csr);
Frederick Mayle9891be02023-11-03 14:39:24 -0700853 ASSERT_TRUE(status.isOk()) << status.getDescription();
Tri Vo0d6204e2022-09-29 16:15:34 -0700854
Sean Thomas2d2385b2024-11-07 23:56:03 +0000855 auto result = verifyProductionCsr(cborKeysToSign_, csr, rpcHardwareInfo, GetParam(),
Alice Wangf112ec92024-10-08 07:30:28 +0000856 challenge, isRkpVmInstance_);
Tommy Chiufde3ad12023-03-17 05:58:28 +0000857 ASSERT_TRUE(result) << result.message();
858 }
859}
860
861/**
862 * Generate an empty certificate request with invalid size of challenge
863 */
864TEST_P(CertificateRequestV2Test, EmptyRequestWithInvalidChallengeFail) {
865 bytevec csr;
866
867 auto status = provisionable_->generateCertificateRequestV2(
868 /* keysToSign */ {}, randomBytes(MAX_CHALLENGE_SIZE + 1), &csr);
Frederick Mayle9891be02023-11-03 14:39:24 -0700869 EXPECT_FALSE(status.isOk()) << status.getDescription();
Tommy Chiufde3ad12023-03-17 05:58:28 +0000870 EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_FAILED);
Tri Vo0d6204e2022-09-29 16:15:34 -0700871}
872
873/**
Andrew Scullfb49ad22022-11-09 21:02:48 +0000874 * Generate a non-empty certificate request. Make sure contents are reproducible but allow for the
875 * signature to be different since algorithms including ECDSA P-256 can include a random value.
Tri Vo0d6204e2022-09-29 16:15:34 -0700876 */
Seth Mooreac1639f2023-04-27 11:14:11 -0700877// @VsrTest = 3.10-015
Tri Vo0d6204e2022-09-29 16:15:34 -0700878TEST_P(CertificateRequestV2Test, NonEmptyRequestReproducible) {
879 generateKeys(false /* testMode */, 1 /* numKeys */);
880
881 bytevec csr;
882
883 auto status = provisionable_->generateCertificateRequestV2(keysToSign_, challenge_, &csr);
Frederick Mayle9891be02023-11-03 14:39:24 -0700884 ASSERT_TRUE(status.isOk()) << status.getDescription();
Tri Vo0d6204e2022-09-29 16:15:34 -0700885
Sean Thomas2d2385b2024-11-07 23:56:03 +0000886 auto firstCsr = verifyProductionCsr(cborKeysToSign_, csr, rpcHardwareInfo, GetParam(),
Alice Wangf112ec92024-10-08 07:30:28 +0000887 challenge_, isRkpVmInstance_);
Andrew Scullfb49ad22022-11-09 21:02:48 +0000888 ASSERT_TRUE(firstCsr) << firstCsr.message();
Tri Vo0d6204e2022-09-29 16:15:34 -0700889
890 status = provisionable_->generateCertificateRequestV2(keysToSign_, challenge_, &csr);
Frederick Mayle9891be02023-11-03 14:39:24 -0700891 ASSERT_TRUE(status.isOk()) << status.getDescription();
Tri Vo0d6204e2022-09-29 16:15:34 -0700892
Sean Thomas2d2385b2024-11-07 23:56:03 +0000893 auto secondCsr = verifyProductionCsr(cborKeysToSign_, csr, rpcHardwareInfo, GetParam(),
Alice Wangf112ec92024-10-08 07:30:28 +0000894 challenge_, isRkpVmInstance_);
Andrew Scullfb49ad22022-11-09 21:02:48 +0000895 ASSERT_TRUE(secondCsr) << secondCsr.message();
Tri Vo0d6204e2022-09-29 16:15:34 -0700896
Andrew Scullfb49ad22022-11-09 21:02:48 +0000897 ASSERT_EQ(**firstCsr, **secondCsr);
Tri Vo0d6204e2022-09-29 16:15:34 -0700898}
899
900/**
901 * Generate a non-empty certificate request with multiple keys.
902 */
Seth Mooreac1639f2023-04-27 11:14:11 -0700903// @VsrTest = 3.10-015
Tri Vo0d6204e2022-09-29 16:15:34 -0700904TEST_P(CertificateRequestV2Test, NonEmptyRequestMultipleKeys) {
Tri Vo9cab73c2022-10-28 13:40:24 -0700905 generateKeys(false /* testMode */, rpcHardwareInfo.supportedNumKeysInCsr /* numKeys */);
Tri Vo0d6204e2022-09-29 16:15:34 -0700906
907 bytevec csr;
908
909 auto status = provisionable_->generateCertificateRequestV2(keysToSign_, challenge_, &csr);
Frederick Mayle9891be02023-11-03 14:39:24 -0700910 ASSERT_TRUE(status.isOk()) << status.getDescription();
Tri Vo0d6204e2022-09-29 16:15:34 -0700911
Sean Thomas2d2385b2024-11-07 23:56:03 +0000912 auto result = verifyProductionCsr(cborKeysToSign_, csr, rpcHardwareInfo, GetParam(), challenge_,
913 isRkpVmInstance_);
Tri Vo0d6204e2022-09-29 16:15:34 -0700914 ASSERT_TRUE(result) << result.message();
915}
916
917/**
918 * Generate a non-empty certificate request, but with the MAC corrupted on the keypair.
919 */
920TEST_P(CertificateRequestV2Test, NonEmptyRequestCorruptMac) {
921 generateKeys(false /* testMode */, 1 /* numKeys */);
922 auto result = corrupt_maced_key(keysToSign_[0]);
923 ASSERT_TRUE(result) << result.moveMessage();
924 MacedPublicKey keyWithCorruptMac = result.moveValue();
925
926 bytevec csr;
927 auto status =
928 provisionable_->generateCertificateRequestV2({keyWithCorruptMac}, challenge_, &csr);
Frederick Mayle9891be02023-11-03 14:39:24 -0700929 ASSERT_FALSE(status.isOk()) << status.getDescription();
Tri Vo0d6204e2022-09-29 16:15:34 -0700930 EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_INVALID_MAC);
931}
932
933/**
Andrew Scullf2ae1932023-04-24 19:09:09 +0000934 * Call generateCertificateRequest(). Make sure it's removed.
Tri Vo0d6204e2022-09-29 16:15:34 -0700935 */
Andrew Scullf2ae1932023-04-24 19:09:09 +0000936TEST_P(CertificateRequestV2Test, CertificateRequestV1Removed_prodMode) {
937 bytevec keysToSignMac;
938 DeviceInfo deviceInfo;
939 ProtectedData protectedData;
940 auto status = provisionable_->generateCertificateRequest(
941 false /* testMode */, {} /* keysToSign */, {} /* EEK chain */, challenge_, &deviceInfo,
942 &protectedData, &keysToSignMac);
Frederick Mayle9891be02023-11-03 14:39:24 -0700943 ASSERT_FALSE(status.isOk()) << status.getDescription();
Andrew Scullf2ae1932023-04-24 19:09:09 +0000944 EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_REMOVED);
Tri Vo0d6204e2022-09-29 16:15:34 -0700945}
946
Andrew Scull95b31312023-03-27 19:16:07 +0000947/**
Andrew Scullf2ae1932023-04-24 19:09:09 +0000948 * Call generateCertificateRequest() in test mode. Make sure it's removed.
Andrew Scull95b31312023-03-27 19:16:07 +0000949 */
Andrew Scullf2ae1932023-04-24 19:09:09 +0000950TEST_P(CertificateRequestV2Test, CertificateRequestV1Removed_testMode) {
Andrew Scull95b31312023-03-27 19:16:07 +0000951 bytevec keysToSignMac;
952 DeviceInfo deviceInfo;
953 ProtectedData protectedData;
954 auto status = provisionable_->generateCertificateRequest(
955 true /* testMode */, {} /* keysToSign */, {} /* EEK chain */, challenge_, &deviceInfo,
956 &protectedData, &keysToSignMac);
Frederick Mayle9891be02023-11-03 14:39:24 -0700957 ASSERT_FALSE(status.isOk()) << status.getDescription();
Andrew Scull95b31312023-03-27 19:16:07 +0000958 EXPECT_EQ(status.getServiceSpecificError(), BnRemotelyProvisionedComponent::STATUS_REMOVED);
959}
960
Tri Voec50ee12023-02-14 16:29:53 -0800961void parse_root_of_trust(const vector<uint8_t>& attestation_cert,
962 vector<uint8_t>* verified_boot_key, VerifiedBoot* verified_boot_state,
963 bool* device_locked, vector<uint8_t>* verified_boot_hash) {
964 X509_Ptr cert(parse_cert_blob(attestation_cert));
965 ASSERT_TRUE(cert.get());
966
967 ASN1_OCTET_STRING* attest_rec = get_attestation_record(cert.get());
968 ASSERT_TRUE(attest_rec);
969
970 auto error = parse_root_of_trust(attest_rec->data, attest_rec->length, verified_boot_key,
971 verified_boot_state, device_locked, verified_boot_hash);
972 ASSERT_EQ(error, ErrorCode::OK);
973}
974
975/**
976 * Generate a CSR and verify DeviceInfo against IDs attested by KeyMint.
977 */
Seth Mooreac1639f2023-04-27 11:14:11 -0700978// @VsrTest = 3.10-015
Tri Voec50ee12023-02-14 16:29:53 -0800979TEST_P(CertificateRequestV2Test, DeviceInfo) {
980 // See if there is a matching IKeyMintDevice for this IRemotelyProvisionedComponent.
Sean Thomasa737a2d2024-11-20 17:25:53 +0000981 std::shared_ptr<IKeyMintDevice> keyMint = matchingKeyMintDevice(GetParam());
982 if (!keyMint) {
Tri Voec50ee12023-02-14 16:29:53 -0800983 GTEST_SKIP() << "Skipping key use test as no matching KeyMint device found";
984 return;
985 }
986 KeyMintHardwareInfo info;
987 ASSERT_TRUE(keyMint->getHardwareInfo(&info).isOk());
988
989 // Get IDs attested by KeyMint.
990 MacedPublicKey macedPubKey;
991 bytevec privateKeyBlob;
992 auto irpcStatus =
993 provisionable_->generateEcdsaP256KeyPair(false, &macedPubKey, &privateKeyBlob);
994 ASSERT_TRUE(irpcStatus.isOk());
995
996 AttestationKey attestKey;
997 attestKey.keyBlob = std::move(privateKeyBlob);
998 attestKey.issuerSubjectName = make_name_from_str("Android Keystore Key");
999
1000 // Generate an ECDSA key that is attested by the generated P256 keypair.
1001 AuthorizationSet keyDesc = AuthorizationSetBuilder()
1002 .Authorization(TAG_NO_AUTH_REQUIRED)
1003 .EcdsaSigningKey(EcCurve::P_256)
1004 .AttestationChallenge("foo")
1005 .AttestationApplicationId("bar")
1006 .Digest(Digest::NONE)
1007 .SetDefaultValidity();
1008 KeyCreationResult creationResult;
1009 auto kmStatus = keyMint->generateKey(keyDesc.vector_data(), attestKey, &creationResult);
1010 ASSERT_TRUE(kmStatus.isOk());
1011
1012 vector<KeyCharacteristics> key_characteristics = std::move(creationResult.keyCharacteristics);
1013 vector<Certificate> key_cert_chain = std::move(creationResult.certificateChain);
1014 // We didn't provision the attestation key.
1015 ASSERT_EQ(key_cert_chain.size(), 1);
1016
1017 // Parse attested patch levels.
1018 auto auths = HwEnforcedAuthorizations(key_characteristics);
1019
1020 auto attestedSystemPatchLevel = auths.GetTagValue(TAG_OS_PATCHLEVEL);
1021 auto attestedVendorPatchLevel = auths.GetTagValue(TAG_VENDOR_PATCHLEVEL);
1022 auto attestedBootPatchLevel = auths.GetTagValue(TAG_BOOT_PATCHLEVEL);
1023
1024 ASSERT_TRUE(attestedSystemPatchLevel.has_value());
1025 ASSERT_TRUE(attestedVendorPatchLevel.has_value());
1026 ASSERT_TRUE(attestedBootPatchLevel.has_value());
1027
1028 // Parse attested AVB values.
1029 vector<uint8_t> key;
1030 VerifiedBoot attestedVbState;
1031 bool attestedBootloaderState;
1032 vector<uint8_t> attestedVbmetaDigest;
1033 parse_root_of_trust(key_cert_chain[0].encodedCertificate, &key, &attestedVbState,
1034 &attestedBootloaderState, &attestedVbmetaDigest);
1035
1036 // Get IDs from DeviceInfo.
1037 bytevec csr;
1038 irpcStatus =
1039 provisionable_->generateCertificateRequestV2({} /* keysToSign */, challenge_, &csr);
Frederick Mayle9891be02023-11-03 14:39:24 -07001040 ASSERT_TRUE(irpcStatus.isOk()) << irpcStatus.getDescription();
Tri Voec50ee12023-02-14 16:29:53 -08001041
Alice Wangf112ec92024-10-08 07:30:28 +00001042 auto result =
Sean Thomas2d2385b2024-11-07 23:56:03 +00001043 verifyProductionCsr(cppbor::Array(), csr, rpcHardwareInfo, GetParam(), challenge_);
Tri Voec50ee12023-02-14 16:29:53 -08001044 ASSERT_TRUE(result) << result.message();
1045
1046 std::unique_ptr<cppbor::Array> csrPayload = std::move(*result);
1047 ASSERT_TRUE(csrPayload);
Sean Thomasb85a71d2024-11-12 20:29:21 +00001048 ASSERT_TRUE(csrPayload->size() > 2);
Tri Voec50ee12023-02-14 16:29:53 -08001049
1050 auto deviceInfo = csrPayload->get(2)->asMap();
1051 ASSERT_TRUE(deviceInfo);
1052
1053 auto vbState = deviceInfo->get("vb_state")->asTstr();
1054 auto bootloaderState = deviceInfo->get("bootloader_state")->asTstr();
1055 auto vbmetaDigest = deviceInfo->get("vbmeta_digest")->asBstr();
1056 auto systemPatchLevel = deviceInfo->get("system_patch_level")->asUint();
1057 auto vendorPatchLevel = deviceInfo->get("vendor_patch_level")->asUint();
1058 auto bootPatchLevel = deviceInfo->get("boot_patch_level")->asUint();
1059 auto securityLevel = deviceInfo->get("security_level")->asTstr();
1060
1061 ASSERT_TRUE(vbState);
1062 ASSERT_TRUE(bootloaderState);
1063 ASSERT_TRUE(vbmetaDigest);
1064 ASSERT_TRUE(systemPatchLevel);
1065 ASSERT_TRUE(vendorPatchLevel);
1066 ASSERT_TRUE(bootPatchLevel);
1067 ASSERT_TRUE(securityLevel);
1068
Sean Thomasafbab602024-11-07 23:14:05 +00001069 auto kmDeviceName = deviceSuffix(GetParam());
Tri Voec50ee12023-02-14 16:29:53 -08001070
1071 // Compare DeviceInfo against IDs attested by KeyMint.
1072 ASSERT_TRUE((securityLevel->value() == "tee" && kmDeviceName == "default") ||
1073 (securityLevel->value() == "strongbox" && kmDeviceName == "strongbox"));
1074 ASSERT_TRUE((vbState->value() == "green" && attestedVbState == VerifiedBoot::VERIFIED) ||
1075 (vbState->value() == "yellow" && attestedVbState == VerifiedBoot::SELF_SIGNED) ||
1076 (vbState->value() == "orange" && attestedVbState == VerifiedBoot::UNVERIFIED));
1077 ASSERT_TRUE((bootloaderState->value() == "locked" && attestedBootloaderState) ||
1078 (bootloaderState->value() == "unlocked" && !attestedBootloaderState));
1079 ASSERT_EQ(vbmetaDigest->value(), attestedVbmetaDigest);
1080 ASSERT_EQ(systemPatchLevel->value(), attestedSystemPatchLevel.value());
1081 ASSERT_EQ(vendorPatchLevel->value(), attestedVendorPatchLevel.value());
1082 ASSERT_EQ(bootPatchLevel->value(), attestedBootPatchLevel.value());
1083}
1084
Tri Vo0d6204e2022-09-29 16:15:34 -07001085INSTANTIATE_REM_PROV_AIDL_TEST(CertificateRequestV2Test);
1086
Max Biresa9b3bb92022-11-21 23:02:09 -08001087using VsrRequirementTest = VtsRemotelyProvisionedComponentTests;
1088
1089INSTANTIATE_REM_PROV_AIDL_TEST(VsrRequirementTest);
1090
1091TEST_P(VsrRequirementTest, VsrEnforcementTest) {
1092 RpcHardwareInfo hwInfo;
1093 ASSERT_TRUE(provisionable_->getHardwareInfo(&hwInfo).isOk());
1094 int vsr_api_level = get_vsr_api_level();
1095 if (vsr_api_level < 34) {
1096 GTEST_SKIP() << "Applies only to VSR API level 34 or newer, this device is: "
1097 << vsr_api_level;
1098 }
1099 EXPECT_GE(hwInfo.versionNumber, 3)
1100 << "VSR 14+ requires IRemotelyProvisionedComponent v3 or newer.";
1101}
1102
Shawn Willden274bb552020-09-30 22:39:22 -06001103} // namespace aidl::android::hardware::security::keymint::test