David Zeuthen | c75ac31 | 2019-10-28 13:16:45 -0400 | [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_WRITABLEIDENTITYCREDENTIAL_H |
| 18 | #define ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H |
| 19 | |
| 20 | #include <android/hardware/identity/1.0/IWritableIdentityCredential.h> |
| 21 | |
| 22 | #include <android/hardware/identity/support/IdentityCredentialSupport.h> |
| 23 | |
| 24 | #include <cppbor.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace identity { |
| 29 | namespace implementation { |
| 30 | |
| 31 | using ::std::string; |
| 32 | using ::std::vector; |
| 33 | |
| 34 | using ::android::hardware::hidl_string; |
| 35 | using ::android::hardware::hidl_vec; |
| 36 | using ::android::hardware::Return; |
| 37 | using ::android::hardware::Void; |
| 38 | using ::android::hardware::identity::V1_0::IWritableIdentityCredential; |
| 39 | using ::android::hardware::identity::V1_0::Result; |
| 40 | using ::android::hardware::identity::V1_0::ResultCode; |
| 41 | using ::android::hardware::identity::V1_0::SecureAccessControlProfile; |
| 42 | |
| 43 | class WritableIdentityCredential : public IWritableIdentityCredential { |
| 44 | public: |
| 45 | WritableIdentityCredential(const hidl_string& docType, bool testCredential) |
| 46 | : docType_(docType), testCredential_(testCredential) {} |
| 47 | |
| 48 | // Creates the Credential Key. Returns false on failure. Must be called |
| 49 | // right after construction. |
| 50 | bool initialize(); |
| 51 | |
| 52 | // Methods from ::android::hardware::identity::IWritableIdentityCredential |
| 53 | // follow. |
David Zeuthen | 87cb07b | 2020-01-30 16:15:50 -0500 | [diff] [blame] | 54 | Return<void> getAttestationCertificate(const hidl_vec<uint8_t>& attestationApplicationId, |
| 55 | const hidl_vec<uint8_t>& attestationChallenge, |
David Zeuthen | c75ac31 | 2019-10-28 13:16:45 -0400 | [diff] [blame] | 56 | getAttestationCertificate_cb _hidl_cb) override; |
| 57 | |
| 58 | Return<void> startPersonalization(uint16_t accessControlProfileCount, |
| 59 | const hidl_vec<uint16_t>& entryCounts, |
| 60 | startPersonalization_cb _hidl_cb) override; |
| 61 | |
| 62 | Return<void> addAccessControlProfile(uint16_t id, const hidl_vec<uint8_t>& readerCertificate, |
| 63 | bool userAuthenticationRequired, uint64_t timeoutMillis, |
| 64 | uint64_t secureUserId, |
| 65 | addAccessControlProfile_cb _hidl_cb) override; |
| 66 | |
| 67 | Return<void> beginAddEntry(const hidl_vec<uint16_t>& accessControlProfileIds, |
| 68 | const hidl_string& nameSpace, const hidl_string& name, |
| 69 | uint32_t entrySize, beginAddEntry_cb _hidl_cb) override; |
| 70 | |
| 71 | Return<void> addEntryValue(const hidl_vec<uint8_t>& content, |
| 72 | addEntryValue_cb _hidl_cb) override; |
| 73 | |
| 74 | Return<void> finishAddingEntries(finishAddingEntries_cb _hidl_cb) override; |
| 75 | |
| 76 | private: |
| 77 | string docType_; |
| 78 | bool testCredential_; |
| 79 | |
| 80 | // These are set in initialize(). |
| 81 | vector<uint8_t> storageKey_; |
| 82 | vector<uint8_t> credentialPrivKey_; |
| 83 | vector<uint8_t> credentialPubKey_; |
| 84 | |
| 85 | // These fields are initialized during startPersonalization() |
| 86 | size_t numAccessControlProfileRemaining_; |
| 87 | vector<uint16_t> remainingEntryCounts_; |
| 88 | cppbor::Array signedDataAccessControlProfiles_; |
| 89 | cppbor::Map signedDataNamespaces_; |
| 90 | cppbor::Array signedDataCurrentNamespace_; |
| 91 | |
| 92 | // These fields are initialized during beginAddEntry() |
| 93 | size_t entryRemainingBytes_; |
| 94 | vector<uint8_t> entryAdditionalData_; |
| 95 | string entryNameSpace_; |
| 96 | string entryName_; |
| 97 | vector<uint16_t> entryAccessControlProfileIds_; |
| 98 | vector<uint8_t> entryBytes_; |
| 99 | }; |
| 100 | |
| 101 | } // namespace implementation |
| 102 | } // namespace identity |
| 103 | } // namespace hardware |
| 104 | } // namespace android |
| 105 | |
| 106 | #endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H |