34abaaefcb
- The docs said that IdentityCredential.createEphemeralKey() returned data encoded PKCS#8 which is wrong. It's supposed to be in DER format which is also what the VTS tests and credstore expects. - Clarify that createEphemeralKeyPair(), setReaderEphemeralPublicKey(), and createAuthChallenge() are all optional. - Avoid passing an invalid profile ID in the IdentityCredentialTests. verifyOneProfileAndEntryPass test. - Update requirements for which tags must be present in the attestation for CredentialKey as well as the requirements on expiration date and the issuer name. Update default implementation to satisfy these requirements. Update VTS tests to carefully verify these requrements are met. - Clarify requirements for X.509 cert for AuthenticationKey. Add VTS test to verify. - Mandate that TAG_IDENTITY_CREDENTIAL_KEY must not be set for test credentials. Add VTS test to verify this. - Make default implementation pretend to be implemented in a trusted environment and streamline VTS tests to not special-case for the default implementation. - Switch to using the attestation extension parser from the KM 4.1 support library instead of the one from system/keymaster. The latter one did not support the latest attestation extension and thus would fail for pretty much anything that wasn't the default HAL impl. - Fix a couple of bugs in keymaster::V4_1::parse_attestation_record(): - Report root_of_trust.security_level - Add support for Tag::IDENTITY_CREDENTIAL_KEY - Fix how EMacKey is calculated. - Add test vectors to verify how EMacKey and DeviceMac is calculated. Test: atest VtsHalIdentityTargetTest Test: atest android.security.identity.cts Bug: 171745570 Change-Id: I2f8bd772de078556733f769cec2021918d1d7de6
114 lines
4.2 KiB
C++
114 lines
4.2 KiB
C++
/*
|
|
* 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 <aidl/Gtest.h>
|
|
#include <aidl/Vintf.h>
|
|
#include <android-base/logging.h>
|
|
#include <android/hardware/identity/IIdentityCredentialStore.h>
|
|
#include <android/hardware/identity/support/IdentityCredentialSupport.h>
|
|
#include <binder/IServiceManager.h>
|
|
#include <binder/ProcessState.h>
|
|
#include <cppbor.h>
|
|
#include <cppbor_parse.h>
|
|
#include <gtest/gtest.h>
|
|
#include <future>
|
|
#include <map>
|
|
|
|
#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::setupWritableCredential;
|
|
using test_utils::validateAttestationCertificate;
|
|
|
|
// This file verifies the Identity Credential VTS Attestation Certificate
|
|
// generated.
|
|
class VtsAttestationTests : public testing::TestWithParam<std::string> {
|
|
public:
|
|
virtual void SetUp() override {
|
|
credentialStore_ = android::waitForDeclaredService<IIdentityCredentialStore>(
|
|
String16(GetParam().c_str()));
|
|
ASSERT_NE(credentialStore_, nullptr);
|
|
}
|
|
|
|
sp<IIdentityCredentialStore> credentialStore_;
|
|
};
|
|
|
|
TEST_P(VtsAttestationTests, verifyAttestationWithNonemptyChallengeNonemptyId) {
|
|
Status result;
|
|
|
|
sp<IWritableIdentityCredential> writableCredential;
|
|
ASSERT_TRUE(setupWritableCredential(writableCredential, credentialStore_,
|
|
false /* testCredential */));
|
|
|
|
string challenge = "NotSoRandomChallenge1NotSoRandomChallenge1NotSoRandomChallenge1";
|
|
vector<uint8_t> attestationChallenge(challenge.begin(), challenge.end());
|
|
vector<Certificate> attestationCertificate;
|
|
string applicationId = "Attestation Verification";
|
|
vector<uint8_t> attestationApplicationId = {applicationId.begin(), applicationId.end()};
|
|
|
|
result = writableCredential->getAttestationCertificate(
|
|
attestationApplicationId, attestationChallenge, &attestationCertificate);
|
|
|
|
ASSERT_TRUE(result.isOk()) << result.exceptionCode() << "; " << result.exceptionMessage()
|
|
<< endl;
|
|
|
|
validateAttestationCertificate(attestationCertificate, attestationChallenge,
|
|
attestationApplicationId, false);
|
|
}
|
|
|
|
TEST_P(VtsAttestationTests, verifyAttestationWithVeryShortChallengeAndId) {
|
|
Status result;
|
|
|
|
sp<IWritableIdentityCredential> writableCredential;
|
|
ASSERT_TRUE(setupWritableCredential(writableCredential, credentialStore_,
|
|
false /* testCredential */));
|
|
|
|
string challenge = "c";
|
|
vector<uint8_t> attestationChallenge(challenge.begin(), challenge.end());
|
|
vector<Certificate> attestationCertificate;
|
|
string applicationId = "i";
|
|
vector<uint8_t> attestationApplicationId = {applicationId.begin(), applicationId.end()};
|
|
|
|
result = writableCredential->getAttestationCertificate(
|
|
attestationApplicationId, attestationChallenge, &attestationCertificate);
|
|
|
|
ASSERT_TRUE(result.isOk()) << result.exceptionCode() << "; " << result.exceptionMessage()
|
|
<< endl;
|
|
|
|
validateAttestationCertificate(attestationCertificate, attestationChallenge,
|
|
attestationApplicationId, false);
|
|
}
|
|
|
|
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VtsAttestationTests);
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
Identity, VtsAttestationTests,
|
|
testing::ValuesIn(android::getAidlHalInstanceNames(IIdentityCredentialStore::descriptor)),
|
|
android::PrintInstanceNameToString);
|
|
|
|
} // namespace android::hardware::identity
|