blob: f69cf877ad45ae838fe3dfdf2093b1c71404cbd1 [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
29/**
30 * This tests that the key can be written, read, and removed. It does not test
31 * that the key survives a reboot. That needs a host-based test.
32 *
33 * atest VtsHalRebootEscrowV1_0TargetTest
34 */
35class RebootEscrowAidlTest : public testing::TestWithParam<std::string> {
36 public:
37 virtual void SetUp() override {
38 rebootescrow = android::waitForDeclaredService<IRebootEscrow>(String16(GetParam().c_str()));
39 ASSERT_NE(rebootescrow, nullptr);
40 }
41
42 sp<IRebootEscrow> rebootescrow;
43
44 std::vector<uint8_t> KEY_1{
45 0xA5, 0x00, 0xFF, 0x01, 0xA5, 0x5a, 0xAA, 0x55, 0x00, 0xD3, 0x2A,
46 0x8C, 0x2E, 0x83, 0x0E, 0x65, 0x9E, 0x8D, 0xC6, 0xAC, 0x1E, 0x83,
47 0x21, 0xB3, 0x95, 0x02, 0x89, 0x64, 0x64, 0x92, 0x12, 0x1F,
48 };
49 std::vector<uint8_t> KEY_2{
50 0xFF, 0x00, 0x00, 0xAA, 0x5A, 0x19, 0x20, 0x71, 0x9F, 0xFB, 0xDA,
51 0xB6, 0x2D, 0x06, 0xD5, 0x49, 0x7E, 0xEF, 0x63, 0xAC, 0x18, 0xFF,
52 0x5A, 0xA3, 0x40, 0xBB, 0x64, 0xFA, 0x67, 0xC1, 0x10, 0x18,
53 };
54 std::vector<uint8_t> EMPTY_KEY{
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 };
59};
60
61TEST_P(RebootEscrowAidlTest, StoreAndRetrieve_Success) {
62 ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
63
64 std::vector<uint8_t> actualKey;
65 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
66 EXPECT_EQ(actualKey, KEY_1);
67}
68
69TEST_P(RebootEscrowAidlTest, StoreAndRetrieve_SecondRetrieveSucceeds) {
70 ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
71
72 std::vector<uint8_t> actualKey;
73 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
74 EXPECT_EQ(actualKey, KEY_1);
75
76 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
77 EXPECT_EQ(actualKey, KEY_1);
78}
79
80TEST_P(RebootEscrowAidlTest, StoreTwiceOverwrites_Success) {
81 ASSERT_TRUE(rebootescrow->storeKey(KEY_1).isOk());
82 ASSERT_TRUE(rebootescrow->storeKey(KEY_2).isOk());
83
84 std::vector<uint8_t> actualKey;
85 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
86 EXPECT_EQ(actualKey, KEY_2);
87}
88
89TEST_P(RebootEscrowAidlTest, StoreEmpty_AfterGetEmptyKey_Success) {
90 rebootescrow->storeKey(KEY_1);
91 rebootescrow->storeKey(EMPTY_KEY);
92
93 std::vector<uint8_t> actualKey;
94 ASSERT_TRUE(rebootescrow->retrieveKey(&actualKey).isOk());
95 EXPECT_EQ(actualKey, EMPTY_KEY);
96}
97
98INSTANTIATE_TEST_SUITE_P(
99 RebootEscrow, RebootEscrowAidlTest,
100 testing::ValuesIn(android::getAidlHalInstanceNames(IRebootEscrow::descriptor)),
101 android::PrintInstanceNameToString);