David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 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 | |
| 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 | |
| 39 | ndk::ScopedAStatus IdentityCredentialStore::createCredential( |
| 40 | const string& docType, bool testCredential, |
| 41 | shared_ptr<IWritableIdentityCredential>* outWritableCredential) { |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 42 | sp<SecureHardwareProvisioningProxy> hwProxy = hwProxyFactory_->createProvisioningProxy(); |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 43 | shared_ptr<WritableIdentityCredential> wc = |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 44 | ndk::SharedRefBase::make<WritableIdentityCredential>(hwProxy, docType, testCredential); |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 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 | |
| 54 | ndk::ScopedAStatus IdentityCredentialStore::getCredential( |
Jooyung Han | 17be89b | 2020-02-21 21:17:06 +0900 | [diff] [blame] | 55 | CipherSuite cipherSuite, const vector<uint8_t>& credentialData, |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 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 | |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 64 | sp<SecureHardwarePresentationProxy> hwProxy = hwProxyFactory_->createPresentationProxy(); |
Jooyung Han | 17be89b | 2020-02-21 21:17:06 +0900 | [diff] [blame] | 65 | shared_ptr<IdentityCredential> credential = |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 66 | ndk::SharedRefBase::make<IdentityCredential>(hwProxyFactory_, hwProxy, credentialData); |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 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 |