blob: 9eb1e70751657635704719648329403348111ca1 [file] [log] [blame]
David Zeuthenc75ac312019-10-28 13:16:45 -04001/*
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 "IdentityCredentialStore.h"
20#include "IdentityCredential.h"
21#include "WritableIdentityCredential.h"
22
23#include <android-base/logging.h>
24
25namespace android {
26namespace hardware {
27namespace identity {
28namespace implementation {
29
30// Methods from ::android::hardware::identity::IIdentityCredentialStore follow.
31
32Return<void> IdentityCredentialStore::getHardwareInformation(getHardwareInformation_cb _hidl_cb) {
33 _hidl_cb(support::resultOK(), "IdentityCredential Reference Implementation", "Google",
34 kGcmChunkSize, false /* isDirectAccess */, {} /* supportedDocTypes */);
35 return Void();
36}
37
38Return<void> IdentityCredentialStore::createCredential(const hidl_string& docType,
39 bool testCredential,
40 createCredential_cb _hidl_cb) {
41 auto writable_credential = new WritableIdentityCredential(docType, testCredential);
42 if (!writable_credential->initialize()) {
43 _hidl_cb(support::result(ResultCode::FAILED,
44 "Error initializing WritableIdentityCredential"),
45 writable_credential);
46 return Void();
47 }
48 _hidl_cb(support::resultOK(), writable_credential);
49 return Void();
50}
51
52Return<void> IdentityCredentialStore::getCredential(const hidl_vec<uint8_t>& credentialData,
53 getCredential_cb _hidl_cb) {
54 auto credential = new IdentityCredential(credentialData);
55 // We only support CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256 right now.
56 auto ret = credential->initialize();
57 if (ret != ResultCode::OK) {
58 _hidl_cb(support::result(ret, "Error initializing IdentityCredential"), credential);
59 return Void();
60 }
61 _hidl_cb(support::resultOK(), credential);
62 return Void();
63}
64
65} // namespace implementation
66} // namespace identity
67} // namespace hardware
68} // namespace android