blob: cd8cc3eaa1aaf26be4d5b7601510910d3dc4e907 [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
63TEST_P(RebootEscrowAidlTest, StoreAndRetrieve_Success) {
Kenny Root2d5d1282020-01-21 11:57:38 -080064 SKIP_UNSUPPORTED;
65
Kenny Root4fba44c2019-11-17 20:28:38 -080066 ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
67
68 std::vector<uint8_t> actualKey;
69 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
70 EXPECT_EQ(actualKey, KEY_1);
71}
72
73TEST_P(RebootEscrowAidlTest, StoreAndRetrieve_SecondRetrieveSucceeds) {
Kenny Root2d5d1282020-01-21 11:57:38 -080074 SKIP_UNSUPPORTED;
75
Kenny Root4fba44c2019-11-17 20:28:38 -080076 ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
77
78 std::vector<uint8_t> actualKey;
79 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
80 EXPECT_EQ(actualKey, KEY_1);
81
82 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
83 EXPECT_EQ(actualKey, KEY_1);
84}
85
86TEST_P(RebootEscrowAidlTest, StoreTwiceOverwrites_Success) {
Kenny Root2d5d1282020-01-21 11:57:38 -080087 SKIP_UNSUPPORTED;
88
Kenny Root4fba44c2019-11-17 20:28:38 -080089 ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
90 ASSERT_TRUE(rebootescrow->storeKey(KEY_2).isOk());
91
92 std::vector<uint8_t> actualKey;
93 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
94 EXPECT_EQ(actualKey, KEY_2);
95}
96
97TEST_P(RebootEscrowAidlTest, StoreEmpty_AfterGetEmptyKey_Success) {
Kenny Root2d5d1282020-01-21 11:57:38 -080098 SKIP_UNSUPPORTED;
99
Kenny Root4fba44c2019-11-17 20:28:38 -0800100 rebootescrow->storeKey(KEY_1);
101 rebootescrow->storeKey(EMPTY_KEY);
102
103 std::vector<uint8_t> actualKey;
104 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
105 EXPECT_EQ(actualKey, EMPTY_KEY);
106}
107
108INSTANTIATE_TEST_SUITE_P(
109 RebootEscrow, RebootEscrowAidlTest,
110 testing::ValuesIn(android::getAidlHalInstanceNames(IRebootEscrow::descriptor)),
111 android::PrintInstanceNameToString);