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_WRITABLEIDENTITYCREDENTIAL_H |
| 18 | #define ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H |
| 19 | |
| 20 | #include <aidl/android/hardware/identity/BnWritableIdentityCredential.h> |
| 21 | #include <android/hardware/identity/support/IdentityCredentialSupport.h> |
| 22 | |
| 23 | #include <cppbor.h> |
| 24 | |
| 25 | namespace aidl::android::hardware::identity { |
| 26 | |
| 27 | using ::std::string; |
| 28 | using ::std::vector; |
| 29 | |
| 30 | class WritableIdentityCredential : public BnWritableIdentityCredential { |
| 31 | public: |
| 32 | WritableIdentityCredential(const string& docType, bool testCredential) |
| 33 | : docType_(docType), testCredential_(testCredential) {} |
| 34 | |
| 35 | // Creates the Credential Key. Returns false on failure. Must be called |
| 36 | // right after construction. |
| 37 | bool initialize(); |
| 38 | |
| 39 | // Methods from IWritableIdentityCredential follow. |
| 40 | ndk::ScopedAStatus getAttestationCertificate(const vector<int8_t>& attestationApplicationId, |
| 41 | const vector<int8_t>& attestationChallenge, |
| 42 | vector<Certificate>* outCertificateChain) override; |
| 43 | |
| 44 | ndk::ScopedAStatus startPersonalization(int32_t accessControlProfileCount, |
| 45 | const vector<int32_t>& entryCounts) override; |
| 46 | |
| 47 | ndk::ScopedAStatus addAccessControlProfile( |
| 48 | int32_t id, const Certificate& readerCertificate, bool userAuthenticationRequired, |
| 49 | int64_t timeoutMillis, int64_t secureUserId, |
| 50 | SecureAccessControlProfile* outSecureAccessControlProfile) override; |
| 51 | |
| 52 | ndk::ScopedAStatus beginAddEntry(const vector<int32_t>& accessControlProfileIds, |
| 53 | const string& nameSpace, const string& name, |
| 54 | int32_t entrySize) override; |
| 55 | |
| 56 | ndk::ScopedAStatus addEntryValue(const vector<int8_t>& content, |
| 57 | vector<int8_t>* outEncryptedContent) override; |
| 58 | |
| 59 | ndk::ScopedAStatus finishAddingEntries( |
| 60 | vector<int8_t>* outCredentialData, |
| 61 | vector<int8_t>* outProofOfProvisioningSignature) override; |
| 62 | |
| 63 | // private: |
| 64 | string docType_; |
| 65 | bool testCredential_; |
| 66 | |
Selene Huang | 459cb80 | 2020-01-08 22:59:02 -0800 | [diff] [blame] | 67 | // This is set in initialize(). |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 68 | vector<uint8_t> storageKey_; |
Selene Huang | 459cb80 | 2020-01-08 22:59:02 -0800 | [diff] [blame] | 69 | |
| 70 | // These are set in getAttestationCertificate(). |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 71 | vector<uint8_t> credentialPrivKey_; |
| 72 | vector<uint8_t> credentialPubKey_; |
Selene Huang | 459cb80 | 2020-01-08 22:59:02 -0800 | [diff] [blame] | 73 | vector<vector<uint8_t>> certificateChain_; |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 74 | |
| 75 | // These fields are initialized during startPersonalization() |
| 76 | size_t numAccessControlProfileRemaining_; |
| 77 | vector<int32_t> remainingEntryCounts_; |
| 78 | cppbor::Array signedDataAccessControlProfiles_; |
| 79 | cppbor::Map signedDataNamespaces_; |
| 80 | cppbor::Array signedDataCurrentNamespace_; |
| 81 | |
| 82 | // These fields are initialized during beginAddEntry() |
| 83 | size_t entryRemainingBytes_; |
| 84 | vector<uint8_t> entryAdditionalData_; |
| 85 | string entryNameSpace_; |
| 86 | string entryName_; |
| 87 | vector<int32_t> entryAccessControlProfileIds_; |
| 88 | vector<uint8_t> entryBytes_; |
| 89 | }; |
| 90 | |
| 91 | } // namespace aidl::android::hardware::identity |
| 92 | |
| 93 | #endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H |