1 /*
2 * Copyright 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 "IdentityCredentialStore"
18
19 #include <android-base/logging.h>
20
21 #include "IdentityCredential.h"
22 #include "IdentityCredentialStore.h"
23 #include "WritableIdentityCredential.h"
24
25 namespace aidl::android::hardware::identity {
26
getHardwareInformation(HardwareInformation * hardwareInformation)27 ndk::ScopedAStatus IdentityCredentialStore::getHardwareInformation(
28 HardwareInformation* hardwareInformation) {
29 HardwareInformation hw;
30 hw.credentialStoreName = "Identity Credential Reference Implementation";
31 hw.credentialStoreAuthorName = "Google";
32 hw.dataChunkSize = kGcmChunkSize;
33 hw.isDirectAccess = false;
34 hw.supportedDocTypes = {};
35 *hardwareInformation = hw;
36 return ndk::ScopedAStatus::ok();
37 }
38
createCredential(const string & docType,bool testCredential,shared_ptr<IWritableIdentityCredential> * outWritableCredential)39 ndk::ScopedAStatus IdentityCredentialStore::createCredential(
40 const string& docType, bool testCredential,
41 shared_ptr<IWritableIdentityCredential>* outWritableCredential) {
42 sp<SecureHardwareProvisioningProxy> hwProxy = hwProxyFactory_->createProvisioningProxy();
43 shared_ptr<WritableIdentityCredential> wc =
44 ndk::SharedRefBase::make<WritableIdentityCredential>(hwProxy, docType, testCredential);
45 if (!wc->initialize()) {
46 return ndk::ScopedAStatus(AStatus_fromServiceSpecificErrorWithMessage(
47 IIdentityCredentialStore::STATUS_FAILED,
48 "Error initializing WritableIdentityCredential"));
49 }
50 *outWritableCredential = wc;
51 return ndk::ScopedAStatus::ok();
52 }
53
getCredential(CipherSuite cipherSuite,const vector<uint8_t> & credentialData,shared_ptr<IIdentityCredential> * outCredential)54 ndk::ScopedAStatus IdentityCredentialStore::getCredential(
55 CipherSuite cipherSuite, const vector<uint8_t>& credentialData,
56 shared_ptr<IIdentityCredential>* outCredential) {
57 // We only support CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256 right now.
58 if (cipherSuite != CipherSuite::CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256) {
59 return ndk::ScopedAStatus(AStatus_fromServiceSpecificErrorWithMessage(
60 IIdentityCredentialStore::STATUS_CIPHER_SUITE_NOT_SUPPORTED,
61 "Unsupported cipher suite"));
62 }
63
64 sp<SecureHardwarePresentationProxy> hwProxy = hwProxyFactory_->createPresentationProxy();
65 shared_ptr<IdentityCredential> credential =
66 ndk::SharedRefBase::make<IdentityCredential>(hwProxyFactory_, hwProxy, credentialData);
67 auto ret = credential->initialize();
68 if (ret != IIdentityCredentialStore::STATUS_OK) {
69 return ndk::ScopedAStatus(AStatus_fromServiceSpecificErrorWithMessage(
70 int(ret), "Error initializing IdentityCredential"));
71 }
72 *outCredential = credential;
73 return ndk::ScopedAStatus::ok();
74 }
75
76 } // namespace aidl::android::hardware::identity
77