blob: 28357a1a1ea82b528bec42d9f289889baf91b98f [file] [log] [blame]
Kenny Root4fba44c2019-11-17 20:28:38 -08001/*
2 * Copyright (C) 2019 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
17#include <aidl/Gtest.h>
18#include <aidl/Vintf.h>
19
20#include <android/hardware/rebootescrow/BnRebootEscrow.h>
21
22#include <binder/IServiceManager.h>
23#include <binder/ProcessState.h>
24
25using android::sp;
26using android::String16;
27using android::hardware::rebootescrow::IRebootEscrow;
28
Kenny Root2d5d1282020-01-21 11:57:38 -080029#define SKIP_UNSUPPORTED \
30 if (rebootescrow == nullptr) GTEST_SKIP() << "Not supported on this device"
31
Kenny Root4fba44c2019-11-17 20:28:38 -080032/**
33 * This tests that the key can be written, read, and removed. It does not test
34 * that the key survives a reboot. That needs a host-based test.
35 *
36 * atest VtsHalRebootEscrowV1_0TargetTest
37 */
38class RebootEscrowAidlTest : public testing::TestWithParam<std::string> {
39 public:
40 virtual void SetUp() override {
41 rebootescrow = android::waitForDeclaredService<IRebootEscrow>(String16(GetParam().c_str()));
Kenny Root4fba44c2019-11-17 20:28:38 -080042 }
43
44 sp<IRebootEscrow> rebootescrow;
45
46 std::vector<uint8_t> KEY_1{
47 0xA5, 0x00, 0xFF, 0x01, 0xA5, 0x5a, 0xAA, 0x55, 0x00, 0xD3, 0x2A,
48 0x8C, 0x2E, 0x83, 0x0E, 0x65, 0x9E, 0x8D, 0xC6, 0xAC, 0x1E, 0x83,
49 0x21, 0xB3, 0x95, 0x02, 0x89, 0x64, 0x64, 0x92, 0x12, 0x1F,
50 };
51 std::vector<uint8_t> KEY_2{
52 0xFF, 0x00, 0x00, 0xAA, 0x5A, 0x19, 0x20, 0x71, 0x9F, 0xFB, 0xDA,
53 0xB6, 0x2D, 0x06, 0xD5, 0x49, 0x7E, 0xEF, 0x63, 0xAC, 0x18, 0xFF,
54 0x5A, 0xA3, 0x40, 0xBB, 0x64, 0xFA, 0x67, 0xC1, 0x10, 0x18,
55 };
56 std::vector<uint8_t> EMPTY_KEY{
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60 };
61};
62
Kenny Root29e37e22020-06-22 10:26:45 -070063// This test assumes that it can retrieve keys immediately, but some
64// implementations use the TEE's EARLY_BOOT_ONLY keys. This means that the
65// earlyBootEnded() calls will need to be disabled to test this correctly.
66TEST_P(RebootEscrowAidlTest, DISABLED_StoreAndRetrieve_Success) {
Kenny Root2d5d1282020-01-21 11:57:38 -080067 SKIP_UNSUPPORTED;
68
Kenny Root4fba44c2019-11-17 20:28:38 -080069 ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
70
71 std::vector<uint8_t> actualKey;
72 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
73 EXPECT_EQ(actualKey, KEY_1);
74}
75
Kenny Root29e37e22020-06-22 10:26:45 -070076// This test assumes that it can retrieve keys immediately, but some
77// implementations use the TEE's EARLY_BOOT_ONLY keys. This means that the
78// earlyBootEnded() calls will need to be disabled to test this correctly.
79TEST_P(RebootEscrowAidlTest, DISABLED_StoreAndRetrieve_SecondRetrieveSucceeds) {
Kenny Root2d5d1282020-01-21 11:57:38 -080080 SKIP_UNSUPPORTED;
81
Kenny Root4fba44c2019-11-17 20:28:38 -080082 ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
83
84 std::vector<uint8_t> actualKey;
85 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
86 EXPECT_EQ(actualKey, KEY_1);
87
88 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
89 EXPECT_EQ(actualKey, KEY_1);
90}
91
Kenny Root29e37e22020-06-22 10:26:45 -070092// This test assumes that it can retrieve keys immediately, but some
93// implementations use the TEE's EARLY_BOOT_ONLY keys. This means that the
94// earlyBootEnded() calls will need to be disabled to test this correctly.
95TEST_P(RebootEscrowAidlTest, DISABLED_StoreTwiceOverwrites_Success) {
Kenny Root2d5d1282020-01-21 11:57:38 -080096 SKIP_UNSUPPORTED;
97
Kenny Root4fba44c2019-11-17 20:28:38 -080098 ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
99 ASSERT_TRUE(rebootescrow->storeKey(KEY_2).isOk());
100
101 std::vector<uint8_t> actualKey;
102 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
103 EXPECT_EQ(actualKey, KEY_2);
104}
105
Kenny Root29e37e22020-06-22 10:26:45 -0700106// This test assumes that it can retrieve keys immediately, but some
107// implementations use the TEE's EARLY_BOOT_ONLY keys. This means that the
108// earlyBootEnded() calls will need to be disabled to test this correctly.
109TEST_P(RebootEscrowAidlTest, DISABLED_StoreEmpty_AfterGetEmptyKey_Success) {
Kenny Root2d5d1282020-01-21 11:57:38 -0800110 SKIP_UNSUPPORTED;
111
Kenny Root4fba44c2019-11-17 20:28:38 -0800112 rebootescrow->storeKey(KEY_1);
113 rebootescrow->storeKey(EMPTY_KEY);
114
115 std::vector<uint8_t> actualKey;
116 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
117 EXPECT_EQ(actualKey, EMPTY_KEY);
118}
119
Kenny Root29e37e22020-06-22 10:26:45 -0700120TEST_P(RebootEscrowAidlTest, Store_Success) {
121 SKIP_UNSUPPORTED;
122
123 rebootescrow->storeKey(KEY_1);
124}
125
Dan Shiff985a82020-07-29 09:45:03 -0700126GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(RebootEscrowAidlTest);
Kenny Root4fba44c2019-11-17 20:28:38 -0800127INSTANTIATE_TEST_SUITE_P(
128 RebootEscrow, RebootEscrowAidlTest,
129 testing::ValuesIn(android::getAidlHalInstanceNames(IRebootEscrow::descriptor)),
130 android::PrintInstanceNameToString);