Andrew Scull | 7093431 | 2018-01-03 11:51:54 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2018 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 <android/hardware/authsecret/1.0/IAuthSecret.h> |
| 18 | |
| 19 | #include <VtsHalHidlTargetTestBase.h> |
| 20 | |
| 21 | using ::android::hardware::hidl_vec; |
| 22 | using ::android::hardware::authsecret::V1_0::IAuthSecret; |
| 23 | using ::android::sp; |
| 24 | |
| 25 | /** |
| 26 | * There is no expected behaviour that can be tested so these tests check the |
| 27 | * HAL doesn't crash with different execution orders. |
| 28 | */ |
| 29 | struct AuthSecretHidlTest : public ::testing::VtsHalHidlTargetTestBase { |
| 30 | virtual void SetUp() override { |
| 31 | authsecret = ::testing::VtsHalHidlTargetTestBase::getService<IAuthSecret>(); |
| 32 | ASSERT_NE(authsecret, nullptr); |
| 33 | authsecret->factoryReset(); |
| 34 | } |
| 35 | |
| 36 | sp<IAuthSecret> authsecret; |
| 37 | }; |
| 38 | |
| 39 | /* Provision the primary user with a secret. */ |
| 40 | TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredential) { |
| 41 | hidl_vec<uint8_t> secret{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; |
| 42 | authsecret->primaryUserCredential(secret); |
| 43 | } |
| 44 | |
| 45 | /* Provision the primary user with a large secret. */ |
| 46 | TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialWithLargeSecret) { |
| 47 | hidl_vec<uint8_t> secret{89, 233, 52, 29, 130, 210, 229, 170, 124, 102, 56, 238, 198, |
| 48 | 199, 246, 152, 185, 123, 155, 215, 29, 252, 30, 70, 118, 29, |
| 49 | 149, 36, 222, 203, 163, 7, 72, 56, 247, 19, 198, 76, 71, |
| 50 | 37, 120, 201, 220, 70, 150, 18, 23, 22, 236, 57, 184, 86, |
| 51 | 190, 122, 210, 207, 74, 51, 222, 157, 74, 196, 86, 208}; |
| 52 | authsecret->primaryUserCredential(secret); |
| 53 | } |
| 54 | |
| 55 | /* Provision the primary user with a secret and pass the secret again. */ |
| 56 | TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgain) { |
| 57 | hidl_vec<uint8_t> secret{64, 2, 3, 0, 5, 6, 7, 172, 9, 10, 11, 255, 13, 14, 15, 83}; |
| 58 | authsecret->primaryUserCredential(secret); |
| 59 | authsecret->primaryUserCredential(secret); |
| 60 | } |
| 61 | |
| 62 | /* Provision the primary user with a secret and pass the secret again repeatedly. */ |
| 63 | TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgainMultipleTimes) { |
| 64 | hidl_vec<uint8_t> secret{1, 2, 34, 4, 5, 6, 7, 8, 9, 105, 11, 12, 13, 184, 15, 16}; |
| 65 | authsecret->primaryUserCredential(secret); |
| 66 | constexpr int N = 5; |
| 67 | for (int i = 0; i < N; ++i) { |
| 68 | authsecret->primaryUserCredential(secret); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /* Factory reset before provisioning the primary user with a secret. */ |
| 73 | TEST_F(AuthSecretHidlTest, factoryResetWithoutProvisioningPrimaryUserCredential) { |
| 74 | authsecret->factoryReset(); |
| 75 | } |
| 76 | |
| 77 | /* Provision the primary user with a secret then factory reset. */ |
| 78 | TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndFactoryReset) { |
| 79 | hidl_vec<uint8_t> secret{1, 24, 124, 240, 5, 6, 7, 8, 9, 13, 11, 12, 189, 14, 195, 16}; |
| 80 | authsecret->primaryUserCredential(secret); |
| 81 | authsecret->factoryReset(); |
| 82 | } |
| 83 | |
| 84 | /* Provision the primary differently after factory reset. */ |
| 85 | TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialDifferentlyAfterFactoryReset) { |
| 86 | { |
| 87 | hidl_vec<uint8_t> secret1{19, 0, 65, 20, 65, 12, 7, 8, 9, 13, 29, 12, 189, 32, 195, 16}; |
| 88 | authsecret->primaryUserCredential(secret1); |
| 89 | } |
| 90 | |
| 91 | authsecret->factoryReset(); |
| 92 | |
| 93 | { |
| 94 | hidl_vec<uint8_t> secret2{61, 93, 124, 240, 5, 0, 7, 201, 9, 129, 11, 12, 0, 14, 0, 16}; |
| 95 | authsecret->primaryUserCredential(secret2); |
| 96 | } |
| 97 | } |