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 | #ifndef ANDROID_HARDWARE_IDENTITY_IDENTITYCREDENTIAL_H |
| 18 | #define ANDROID_HARDWARE_IDENTITY_IDENTITYCREDENTIAL_H |
| 19 | |
| 20 | #include <aidl/android/hardware/identity/BnIdentityCredential.h> |
| 21 | #include <aidl/android/hardware/keymaster/HardwareAuthToken.h> |
| 22 | #include <android/hardware/identity/support/IdentityCredentialSupport.h> |
| 23 | |
| 24 | #include <map> |
| 25 | #include <set> |
| 26 | #include <string> |
| 27 | #include <vector> |
| 28 | |
| 29 | #include <cppbor/cppbor.h> |
| 30 | |
| 31 | namespace aidl::android::hardware::identity { |
| 32 | |
| 33 | using ::aidl::android::hardware::keymaster::HardwareAuthToken; |
| 34 | using ::std::map; |
| 35 | using ::std::string; |
| 36 | using ::std::vector; |
| 37 | |
| 38 | using MapStringToVectorOfStrings = map<string, vector<string>>; |
| 39 | |
| 40 | class IdentityCredential : public BnIdentityCredential { |
| 41 | public: |
| 42 | IdentityCredential(const vector<uint8_t>& credentialData) |
| 43 | : credentialData_(credentialData), numStartRetrievalCalls_(0), authChallenge_(0) {} |
| 44 | |
| 45 | // Parses and decrypts credentialData_, return a status code from |
| 46 | // IIdentityCredentialStore. Must be called right after construction. |
| 47 | int initialize(); |
| 48 | |
| 49 | // Methods from IIdentityCredential follow. |
| 50 | ndk::ScopedAStatus deleteCredential(vector<int8_t>* outProofOfDeletionSignature) override; |
| 51 | ndk::ScopedAStatus createEphemeralKeyPair(vector<int8_t>* outKeyPair) override; |
| 52 | ndk::ScopedAStatus setReaderEphemeralPublicKey(const vector<int8_t>& publicKey) override; |
| 53 | ndk::ScopedAStatus createAuthChallenge(int64_t* outChallenge) override; |
| 54 | ndk::ScopedAStatus startRetrieval( |
| 55 | const vector<SecureAccessControlProfile>& accessControlProfiles, |
| 56 | const HardwareAuthToken& authToken, const vector<int8_t>& itemsRequest, |
David Zeuthen | e35797f | 2020-02-27 14:25:54 -0500 | [diff] [blame] | 57 | const vector<int8_t>& signingKeyBlob, const vector<int8_t>& sessionTranscript, |
| 58 | const vector<int8_t>& readerSignature, const vector<int32_t>& requestCounts) override; |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 59 | ndk::ScopedAStatus startRetrieveEntryValue( |
| 60 | const string& nameSpace, const string& name, int32_t entrySize, |
| 61 | const vector<int32_t>& accessControlProfileIds) override; |
| 62 | ndk::ScopedAStatus retrieveEntryValue(const vector<int8_t>& encryptedContent, |
| 63 | vector<int8_t>* outContent) override; |
David Zeuthen | e35797f | 2020-02-27 14:25:54 -0500 | [diff] [blame] | 64 | ndk::ScopedAStatus finishRetrieval(vector<int8_t>* outMac, |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 65 | vector<int8_t>* outDeviceNameSpaces) override; |
| 66 | ndk::ScopedAStatus generateSigningKeyPair(vector<int8_t>* outSigningKeyBlob, |
| 67 | Certificate* outSigningKeyCertificate) override; |
| 68 | |
| 69 | private: |
| 70 | // Set by constructor |
| 71 | vector<uint8_t> credentialData_; |
| 72 | int numStartRetrievalCalls_; |
| 73 | |
| 74 | // Set by initialize() |
| 75 | string docType_; |
| 76 | bool testCredential_; |
| 77 | vector<uint8_t> storageKey_; |
| 78 | vector<uint8_t> credentialPrivKey_; |
| 79 | |
| 80 | // Set by createEphemeralKeyPair() |
| 81 | vector<uint8_t> ephemeralPublicKey_; |
| 82 | |
| 83 | // Set by setReaderEphemeralPublicKey() |
| 84 | vector<uint8_t> readerPublicKey_; |
| 85 | |
| 86 | // Set by createAuthChallenge() |
| 87 | uint64_t authChallenge_; |
| 88 | |
| 89 | // Set at startRetrieval() time. |
| 90 | map<int32_t, int> profileIdToAccessCheckResult_; |
David Zeuthen | e35797f | 2020-02-27 14:25:54 -0500 | [diff] [blame] | 91 | vector<uint8_t> signingKeyBlob_; |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 92 | vector<uint8_t> sessionTranscript_; |
| 93 | std::unique_ptr<cppbor::Item> sessionTranscriptItem_; |
| 94 | vector<uint8_t> itemsRequest_; |
| 95 | vector<int32_t> requestCountsRemaining_; |
| 96 | MapStringToVectorOfStrings requestedNameSpacesAndNames_; |
| 97 | cppbor::Map deviceNameSpacesMap_; |
| 98 | cppbor::Map currentNameSpaceDeviceNameSpacesMap_; |
| 99 | |
| 100 | // Set at startRetrieveEntryValue() time. |
| 101 | string currentNameSpace_; |
| 102 | string currentName_; |
| 103 | size_t entryRemainingBytes_; |
| 104 | vector<uint8_t> entryValue_; |
| 105 | vector<uint8_t> entryAdditionalData_; |
| 106 | }; |
| 107 | |
| 108 | } // namespace aidl::android::hardware::identity |
| 109 | |
| 110 | #endif // ANDROID_HARDWARE_IDENTITY_IDENTITYCREDENTIAL_H |