blob: 7caa2599afb9fa48455942a06179e5ec6e68a6d7 [file] [log] [blame]
Selene Huangcab019a2020-03-11 04:37:48 -07001/*
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#define LOG_TAG "VtsAttestationTests"
18
19#include <aidl/Gtest.h>
20#include <aidl/Vintf.h>
21#include <android-base/logging.h>
22#include <android/hardware/identity/IIdentityCredentialStore.h>
23#include <android/hardware/identity/support/IdentityCredentialSupport.h>
24#include <binder/IServiceManager.h>
25#include <binder/ProcessState.h>
26#include <cppbor.h>
27#include <cppbor_parse.h>
28#include <gtest/gtest.h>
29#include <future>
30#include <map>
31
David Zeuthen49f2d252020-10-16 11:27:24 -040032#include "Util.h"
Selene Huangcab019a2020-03-11 04:37:48 -070033
34namespace android::hardware::identity {
35
36using std::endl;
37using std::map;
38using std::optional;
39using std::string;
40using std::vector;
41
42using ::android::sp;
43using ::android::String16;
44using ::android::binder::Status;
45
Selene Huangcab019a2020-03-11 04:37:48 -070046using test_utils::setupWritableCredential;
47using test_utils::validateAttestationCertificate;
48
49// This file verifies the Identity Credential VTS Attestation Certificate
50// generated.
51class VtsAttestationTests : public testing::TestWithParam<std::string> {
52 public:
53 virtual void SetUp() override {
54 credentialStore_ = android::waitForDeclaredService<IIdentityCredentialStore>(
55 String16(GetParam().c_str()));
56 ASSERT_NE(credentialStore_, nullptr);
57 }
58
59 sp<IIdentityCredentialStore> credentialStore_;
60};
61
Selene Huangcab019a2020-03-11 04:37:48 -070062TEST_P(VtsAttestationTests, verifyAttestationWithNonemptyChallengeNonemptyId) {
63 Status result;
64
Selene Huangcab019a2020-03-11 04:37:48 -070065 sp<IWritableIdentityCredential> writableCredential;
David Zeuthen34abaae2020-10-26 20:26:36 -040066 ASSERT_TRUE(setupWritableCredential(writableCredential, credentialStore_,
67 false /* testCredential */));
Selene Huangcab019a2020-03-11 04:37:48 -070068
David Zeuthen834f3222022-01-27 13:43:10 -050069 // Must support at least 32 bytes.
70 string challenge = "0123456789abcdef0123456789abcdef";
Selene Huangcab019a2020-03-11 04:37:48 -070071 vector<uint8_t> attestationChallenge(challenge.begin(), challenge.end());
72 vector<Certificate> attestationCertificate;
73 string applicationId = "Attestation Verification";
74 vector<uint8_t> attestationApplicationId = {applicationId.begin(), applicationId.end()};
75
76 result = writableCredential->getAttestationCertificate(
77 attestationApplicationId, attestationChallenge, &attestationCertificate);
78
79 ASSERT_TRUE(result.isOk()) << result.exceptionCode() << "; " << result.exceptionMessage()
80 << endl;
81
David Zeuthen34abaae2020-10-26 20:26:36 -040082 validateAttestationCertificate(attestationCertificate, attestationChallenge,
83 attestationApplicationId, false);
Selene Huangcab019a2020-03-11 04:37:48 -070084}
85
86TEST_P(VtsAttestationTests, verifyAttestationWithVeryShortChallengeAndId) {
87 Status result;
88
Selene Huangcab019a2020-03-11 04:37:48 -070089 sp<IWritableIdentityCredential> writableCredential;
David Zeuthen34abaae2020-10-26 20:26:36 -040090 ASSERT_TRUE(setupWritableCredential(writableCredential, credentialStore_,
91 false /* testCredential */));
Selene Huangcab019a2020-03-11 04:37:48 -070092
93 string challenge = "c";
94 vector<uint8_t> attestationChallenge(challenge.begin(), challenge.end());
95 vector<Certificate> attestationCertificate;
96 string applicationId = "i";
97 vector<uint8_t> attestationApplicationId = {applicationId.begin(), applicationId.end()};
98
99 result = writableCredential->getAttestationCertificate(
100 attestationApplicationId, attestationChallenge, &attestationCertificate);
101
102 ASSERT_TRUE(result.isOk()) << result.exceptionCode() << "; " << result.exceptionMessage()
103 << endl;
104
David Zeuthen34abaae2020-10-26 20:26:36 -0400105 validateAttestationCertificate(attestationCertificate, attestationChallenge,
106 attestationApplicationId, false);
Selene Huangcab019a2020-03-11 04:37:48 -0700107}
108
Dan Shiba4d5322020-07-28 13:09:30 -0700109GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VtsAttestationTests);
Selene Huangcab019a2020-03-11 04:37:48 -0700110INSTANTIATE_TEST_SUITE_P(
111 Identity, VtsAttestationTests,
112 testing::ValuesIn(android::getAidlHalInstanceNames(IIdentityCredentialStore::descriptor)),
113 android::PrintInstanceNameToString);
114
115} // namespace android::hardware::identity