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) { |
| 42 | shared_ptr<WritableIdentityCredential> wc = |
| 43 | ndk::SharedRefBase::make<WritableIdentityCredential>(docType, testCredential); |
| 44 | if (!wc->initialize()) { |
| 45 | return ndk::ScopedAStatus(AStatus_fromServiceSpecificErrorWithMessage( |
| 46 | IIdentityCredentialStore::STATUS_FAILED, |
| 47 | "Error initializing WritableIdentityCredential")); |
| 48 | } |
| 49 | *outWritableCredential = wc; |
| 50 | return ndk::ScopedAStatus::ok(); |
| 51 | } |
| 52 | |
| 53 | ndk::ScopedAStatus IdentityCredentialStore::getCredential( |
Jooyung Han | 17be89b | 2020-02-21 21:17:06 +0900 | [diff] [blame^] | 54 | CipherSuite cipherSuite, const vector<uint8_t>& credentialData, |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 55 | shared_ptr<IIdentityCredential>* outCredential) { |
| 56 | // We only support CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256 right now. |
| 57 | if (cipherSuite != CipherSuite::CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256) { |
| 58 | return ndk::ScopedAStatus(AStatus_fromServiceSpecificErrorWithMessage( |
| 59 | IIdentityCredentialStore::STATUS_CIPHER_SUITE_NOT_SUPPORTED, |
| 60 | "Unsupported cipher suite")); |
| 61 | } |
| 62 | |
Jooyung Han | 17be89b | 2020-02-21 21:17:06 +0900 | [diff] [blame^] | 63 | shared_ptr<IdentityCredential> credential = |
| 64 | ndk::SharedRefBase::make<IdentityCredential>(credentialData); |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 65 | auto ret = credential->initialize(); |
| 66 | if (ret != IIdentityCredentialStore::STATUS_OK) { |
| 67 | return ndk::ScopedAStatus(AStatus_fromServiceSpecificErrorWithMessage( |
| 68 | int(ret), "Error initializing IdentityCredential")); |
| 69 | } |
| 70 | *outCredential = credential; |
| 71 | return ndk::ScopedAStatus::ok(); |
| 72 | } |
| 73 | |
| 74 | } // namespace aidl::android::hardware::identity |