blob: e6b5466096ca57e74532db2dcab1d35338ea3925 [file] [log] [blame]
David Zeuthen81603152020-02-11 22:04:24 -05001/*
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
25namespace aidl::android::hardware::identity {
26
27ndk::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
39ndk::ScopedAStatus IdentityCredentialStore::createCredential(
40 const string& docType, bool testCredential,
41 shared_ptr<IWritableIdentityCredential>* outWritableCredential) {
David Zeuthen630de2a2020-05-11 14:04:54 -040042 sp<SecureHardwareProvisioningProxy> hwProxy = hwProxyFactory_->createProvisioningProxy();
David Zeuthen81603152020-02-11 22:04:24 -050043 shared_ptr<WritableIdentityCredential> wc =
David Zeuthen630de2a2020-05-11 14:04:54 -040044 ndk::SharedRefBase::make<WritableIdentityCredential>(hwProxy, docType, testCredential);
David Zeuthen81603152020-02-11 22:04:24 -050045 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
54ndk::ScopedAStatus IdentityCredentialStore::getCredential(
Jooyung Han17be89b2020-02-21 21:17:06 +090055 CipherSuite cipherSuite, const vector<uint8_t>& credentialData,
David Zeuthen81603152020-02-11 22:04:24 -050056 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
David Zeuthen630de2a2020-05-11 14:04:54 -040064 sp<SecureHardwarePresentationProxy> hwProxy = hwProxyFactory_->createPresentationProxy();
Jooyung Han17be89b2020-02-21 21:17:06 +090065 shared_ptr<IdentityCredential> credential =
David Zeuthen49f2d252020-10-16 11:27:24 -040066 ndk::SharedRefBase::make<IdentityCredential>(hwProxyFactory_, hwProxy, credentialData);
David Zeuthen81603152020-02-11 22:04:24 -050067 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