xref: /aosp_15_r20/hardware/interfaces/rebootescrow/aidl/vts/functional/VtsHalRebootEscrowTargetTest.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1*4d7e907cSAndroid Build Coastguard Worker /*
2*4d7e907cSAndroid Build Coastguard Worker  * Copyright (C) 2019 The Android Open Source Project
3*4d7e907cSAndroid Build Coastguard Worker  *
4*4d7e907cSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*4d7e907cSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*4d7e907cSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*4d7e907cSAndroid Build Coastguard Worker  *
8*4d7e907cSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*4d7e907cSAndroid Build Coastguard Worker  *
10*4d7e907cSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*4d7e907cSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*4d7e907cSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4d7e907cSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*4d7e907cSAndroid Build Coastguard Worker  * limitations under the License.
15*4d7e907cSAndroid Build Coastguard Worker  */
16*4d7e907cSAndroid Build Coastguard Worker 
17*4d7e907cSAndroid Build Coastguard Worker #include <aidl/Gtest.h>
18*4d7e907cSAndroid Build Coastguard Worker #include <aidl/Vintf.h>
19*4d7e907cSAndroid Build Coastguard Worker 
20*4d7e907cSAndroid Build Coastguard Worker #include <android/hardware/rebootescrow/BnRebootEscrow.h>
21*4d7e907cSAndroid Build Coastguard Worker 
22*4d7e907cSAndroid Build Coastguard Worker #include <binder/IServiceManager.h>
23*4d7e907cSAndroid Build Coastguard Worker #include <binder/ProcessState.h>
24*4d7e907cSAndroid Build Coastguard Worker 
25*4d7e907cSAndroid Build Coastguard Worker using android::sp;
26*4d7e907cSAndroid Build Coastguard Worker using android::String16;
27*4d7e907cSAndroid Build Coastguard Worker using android::hardware::rebootescrow::IRebootEscrow;
28*4d7e907cSAndroid Build Coastguard Worker 
29*4d7e907cSAndroid Build Coastguard Worker #define SKIP_UNSUPPORTED \
30*4d7e907cSAndroid Build Coastguard Worker     if (rebootescrow == nullptr) GTEST_SKIP() << "Not supported on this device"
31*4d7e907cSAndroid Build Coastguard Worker 
32*4d7e907cSAndroid Build Coastguard Worker /**
33*4d7e907cSAndroid Build Coastguard Worker  * This tests that the key can be written, read, and removed. It does not test
34*4d7e907cSAndroid Build Coastguard Worker  * that the key survives a reboot. That needs a host-based test.
35*4d7e907cSAndroid Build Coastguard Worker  *
36*4d7e907cSAndroid Build Coastguard Worker  * atest VtsHalRebootEscrowV1_0TargetTest
37*4d7e907cSAndroid Build Coastguard Worker  */
38*4d7e907cSAndroid Build Coastguard Worker class RebootEscrowAidlTest : public testing::TestWithParam<std::string> {
39*4d7e907cSAndroid Build Coastguard Worker   public:
SetUp()40*4d7e907cSAndroid Build Coastguard Worker     virtual void SetUp() override {
41*4d7e907cSAndroid Build Coastguard Worker         rebootescrow = android::waitForDeclaredService<IRebootEscrow>(String16(GetParam().c_str()));
42*4d7e907cSAndroid Build Coastguard Worker     }
43*4d7e907cSAndroid Build Coastguard Worker 
44*4d7e907cSAndroid Build Coastguard Worker     sp<IRebootEscrow> rebootescrow;
45*4d7e907cSAndroid Build Coastguard Worker 
46*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint8_t> KEY_1{
47*4d7e907cSAndroid Build Coastguard Worker             0xA5, 0x00, 0xFF, 0x01, 0xA5, 0x5a, 0xAA, 0x55, 0x00, 0xD3, 0x2A,
48*4d7e907cSAndroid Build Coastguard Worker             0x8C, 0x2E, 0x83, 0x0E, 0x65, 0x9E, 0x8D, 0xC6, 0xAC, 0x1E, 0x83,
49*4d7e907cSAndroid Build Coastguard Worker             0x21, 0xB3, 0x95, 0x02, 0x89, 0x64, 0x64, 0x92, 0x12, 0x1F,
50*4d7e907cSAndroid Build Coastguard Worker     };
51*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint8_t> KEY_2{
52*4d7e907cSAndroid Build Coastguard Worker             0xFF, 0x00, 0x00, 0xAA, 0x5A, 0x19, 0x20, 0x71, 0x9F, 0xFB, 0xDA,
53*4d7e907cSAndroid Build Coastguard Worker             0xB6, 0x2D, 0x06, 0xD5, 0x49, 0x7E, 0xEF, 0x63, 0xAC, 0x18, 0xFF,
54*4d7e907cSAndroid Build Coastguard Worker             0x5A, 0xA3, 0x40, 0xBB, 0x64, 0xFA, 0x67, 0xC1, 0x10, 0x18,
55*4d7e907cSAndroid Build Coastguard Worker     };
56*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint8_t> EMPTY_KEY{
57*4d7e907cSAndroid Build Coastguard Worker             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58*4d7e907cSAndroid Build Coastguard Worker             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59*4d7e907cSAndroid Build Coastguard Worker             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60*4d7e907cSAndroid Build Coastguard Worker     };
61*4d7e907cSAndroid Build Coastguard Worker };
62*4d7e907cSAndroid Build Coastguard Worker 
63*4d7e907cSAndroid Build Coastguard Worker // This test assumes that it can retrieve keys immediately, but some
64*4d7e907cSAndroid Build Coastguard Worker // implementations use the TEE's EARLY_BOOT_ONLY keys. This means that the
65*4d7e907cSAndroid Build Coastguard Worker // earlyBootEnded() calls will need to be disabled to test this correctly.
TEST_P(RebootEscrowAidlTest,DISABLED_StoreAndRetrieve_Success)66*4d7e907cSAndroid Build Coastguard Worker TEST_P(RebootEscrowAidlTest, DISABLED_StoreAndRetrieve_Success) {
67*4d7e907cSAndroid Build Coastguard Worker     SKIP_UNSUPPORTED;
68*4d7e907cSAndroid Build Coastguard Worker 
69*4d7e907cSAndroid Build Coastguard Worker     ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
70*4d7e907cSAndroid Build Coastguard Worker 
71*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint8_t> actualKey;
72*4d7e907cSAndroid Build Coastguard Worker     ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
73*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(actualKey, KEY_1);
74*4d7e907cSAndroid Build Coastguard Worker }
75*4d7e907cSAndroid Build Coastguard Worker 
76*4d7e907cSAndroid Build Coastguard Worker // This test assumes that it can retrieve keys immediately, but some
77*4d7e907cSAndroid Build Coastguard Worker // implementations use the TEE's EARLY_BOOT_ONLY keys. This means that the
78*4d7e907cSAndroid Build Coastguard Worker // earlyBootEnded() calls will need to be disabled to test this correctly.
TEST_P(RebootEscrowAidlTest,DISABLED_StoreAndRetrieve_SecondRetrieveSucceeds)79*4d7e907cSAndroid Build Coastguard Worker TEST_P(RebootEscrowAidlTest, DISABLED_StoreAndRetrieve_SecondRetrieveSucceeds) {
80*4d7e907cSAndroid Build Coastguard Worker     SKIP_UNSUPPORTED;
81*4d7e907cSAndroid Build Coastguard Worker 
82*4d7e907cSAndroid Build Coastguard Worker     ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
83*4d7e907cSAndroid Build Coastguard Worker 
84*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint8_t> actualKey;
85*4d7e907cSAndroid Build Coastguard Worker     ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
86*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(actualKey, KEY_1);
87*4d7e907cSAndroid Build Coastguard Worker 
88*4d7e907cSAndroid Build Coastguard Worker     ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
89*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(actualKey, KEY_1);
90*4d7e907cSAndroid Build Coastguard Worker }
91*4d7e907cSAndroid Build Coastguard Worker 
92*4d7e907cSAndroid Build Coastguard Worker // This test assumes that it can retrieve keys immediately, but some
93*4d7e907cSAndroid Build Coastguard Worker // implementations use the TEE's EARLY_BOOT_ONLY keys. This means that the
94*4d7e907cSAndroid Build Coastguard Worker // earlyBootEnded() calls will need to be disabled to test this correctly.
TEST_P(RebootEscrowAidlTest,DISABLED_StoreTwiceOverwrites_Success)95*4d7e907cSAndroid Build Coastguard Worker TEST_P(RebootEscrowAidlTest, DISABLED_StoreTwiceOverwrites_Success) {
96*4d7e907cSAndroid Build Coastguard Worker     SKIP_UNSUPPORTED;
97*4d7e907cSAndroid Build Coastguard Worker 
98*4d7e907cSAndroid Build Coastguard Worker     ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
99*4d7e907cSAndroid Build Coastguard Worker     ASSERT_TRUE(rebootescrow->storeKey(KEY_2).isOk());
100*4d7e907cSAndroid Build Coastguard Worker 
101*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint8_t> actualKey;
102*4d7e907cSAndroid Build Coastguard Worker     ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
103*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(actualKey, KEY_2);
104*4d7e907cSAndroid Build Coastguard Worker }
105*4d7e907cSAndroid Build Coastguard Worker 
106*4d7e907cSAndroid Build Coastguard Worker // This test assumes that it can retrieve keys immediately, but some
107*4d7e907cSAndroid Build Coastguard Worker // implementations use the TEE's EARLY_BOOT_ONLY keys. This means that the
108*4d7e907cSAndroid Build Coastguard Worker // earlyBootEnded() calls will need to be disabled to test this correctly.
TEST_P(RebootEscrowAidlTest,DISABLED_StoreEmpty_AfterGetEmptyKey_Success)109*4d7e907cSAndroid Build Coastguard Worker TEST_P(RebootEscrowAidlTest, DISABLED_StoreEmpty_AfterGetEmptyKey_Success) {
110*4d7e907cSAndroid Build Coastguard Worker     SKIP_UNSUPPORTED;
111*4d7e907cSAndroid Build Coastguard Worker 
112*4d7e907cSAndroid Build Coastguard Worker     rebootescrow->storeKey(KEY_1);
113*4d7e907cSAndroid Build Coastguard Worker     rebootescrow->storeKey(EMPTY_KEY);
114*4d7e907cSAndroid Build Coastguard Worker 
115*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint8_t> actualKey;
116*4d7e907cSAndroid Build Coastguard Worker     ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
117*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(actualKey, EMPTY_KEY);
118*4d7e907cSAndroid Build Coastguard Worker }
119*4d7e907cSAndroid Build Coastguard Worker 
TEST_P(RebootEscrowAidlTest,Store_Success)120*4d7e907cSAndroid Build Coastguard Worker TEST_P(RebootEscrowAidlTest, Store_Success) {
121*4d7e907cSAndroid Build Coastguard Worker     SKIP_UNSUPPORTED;
122*4d7e907cSAndroid Build Coastguard Worker 
123*4d7e907cSAndroid Build Coastguard Worker     rebootescrow->storeKey(KEY_1);
124*4d7e907cSAndroid Build Coastguard Worker }
125*4d7e907cSAndroid Build Coastguard Worker 
126*4d7e907cSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(RebootEscrowAidlTest);
127*4d7e907cSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
128*4d7e907cSAndroid Build Coastguard Worker         RebootEscrow, RebootEscrowAidlTest,
129*4d7e907cSAndroid Build Coastguard Worker         testing::ValuesIn(android::getAidlHalInstanceNames(IRebootEscrow::descriptor)),
130*4d7e907cSAndroid Build Coastguard Worker         android::PrintInstanceNameToString);
131