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