/* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "VtsAttestationTests" #include #include #include #include #include #include #include #include #include #include #include #include #include "VtsAttestationParserSupport.h" #include "VtsIdentityTestUtils.h" namespace android::hardware::identity { using std::endl; using std::map; using std::optional; using std::string; using std::vector; using ::android::sp; using ::android::String16; using ::android::binder::Status; using test_utils::AttestationCertificateParser; using test_utils::setupWritableCredential; using test_utils::validateAttestationCertificate; // This file verifies the Identity Credential VTS Attestation Certificate // generated. class VtsAttestationTests : public testing::TestWithParam { public: virtual void SetUp() override { credentialStore_ = android::waitForDeclaredService( String16(GetParam().c_str())); ASSERT_NE(credentialStore_, nullptr); } sp credentialStore_; }; TEST_P(VtsAttestationTests, verifyAttestationWithNonemptyChallengeEmptyId) { Status result; HardwareInformation hwInfo; ASSERT_TRUE(credentialStore_->getHardwareInformation(&hwInfo).isOk()); sp writableCredential; ASSERT_TRUE(setupWritableCredential(writableCredential, credentialStore_)); string challenge = "NotSoRandomChallenge"; vector attestationChallenge(challenge.begin(), challenge.end()); vector attestationCertificate; vector attestationApplicationId = {}; result = writableCredential->getAttestationCertificate( attestationApplicationId, attestationChallenge, &attestationCertificate); ASSERT_TRUE(result.isOk()) << result.exceptionCode() << "; " << result.exceptionMessage() << endl; EXPECT_TRUE(validateAttestationCertificate(attestationCertificate, attestationChallenge, attestationApplicationId, hwInfo)); } TEST_P(VtsAttestationTests, verifyAttestationWithNonemptyChallengeNonemptyId) { Status result; HardwareInformation hwInfo; ASSERT_TRUE(credentialStore_->getHardwareInformation(&hwInfo).isOk()); sp writableCredential; ASSERT_TRUE(setupWritableCredential(writableCredential, credentialStore_)); string challenge = "NotSoRandomChallenge1NotSoRandomChallenge1NotSoRandomChallenge1"; vector attestationChallenge(challenge.begin(), challenge.end()); vector attestationCertificate; string applicationId = "Attestation Verification"; vector attestationApplicationId = {applicationId.begin(), applicationId.end()}; result = writableCredential->getAttestationCertificate( attestationApplicationId, attestationChallenge, &attestationCertificate); ASSERT_TRUE(result.isOk()) << result.exceptionCode() << "; " << result.exceptionMessage() << endl; EXPECT_TRUE(validateAttestationCertificate(attestationCertificate, attestationChallenge, attestationApplicationId, hwInfo)); } TEST_P(VtsAttestationTests, verifyAttestationWithVeryShortChallengeAndId) { Status result; HardwareInformation hwInfo; ASSERT_TRUE(credentialStore_->getHardwareInformation(&hwInfo).isOk()); sp writableCredential; ASSERT_TRUE(setupWritableCredential(writableCredential, credentialStore_)); string challenge = "c"; vector attestationChallenge(challenge.begin(), challenge.end()); vector attestationCertificate; string applicationId = "i"; vector attestationApplicationId = {applicationId.begin(), applicationId.end()}; result = writableCredential->getAttestationCertificate( attestationApplicationId, attestationChallenge, &attestationCertificate); ASSERT_TRUE(result.isOk()) << result.exceptionCode() << "; " << result.exceptionMessage() << endl; EXPECT_TRUE(validateAttestationCertificate(attestationCertificate, attestationChallenge, attestationApplicationId, hwInfo)); } GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VtsAttestationTests); INSTANTIATE_TEST_SUITE_P( Identity, VtsAttestationTests, testing::ValuesIn(android::getAidlHalInstanceNames(IIdentityCredentialStore::descriptor)), android::PrintInstanceNameToString); } // namespace android::hardware::identity