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 | |
David Zeuthen | 28edb10 | 2020-04-28 18:54:55 -0400 | [diff] [blame^] | 46 | ndk::ScopedAStatus setExpectedProofOfProvisioningSize( |
| 47 | int32_t expectedProofOfProvisioningSize) override; |
| 48 | |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 49 | ndk::ScopedAStatus startPersonalization(int32_t accessControlProfileCount, |
| 50 | const vector<int32_t>& entryCounts) override; |
| 51 | |
| 52 | ndk::ScopedAStatus addAccessControlProfile( |
| 53 | int32_t id, const Certificate& readerCertificate, bool userAuthenticationRequired, |
| 54 | int64_t timeoutMillis, int64_t secureUserId, |
| 55 | SecureAccessControlProfile* outSecureAccessControlProfile) override; |
| 56 | |
| 57 | ndk::ScopedAStatus beginAddEntry(const vector<int32_t>& accessControlProfileIds, |
| 58 | const string& nameSpace, const string& name, |
| 59 | int32_t entrySize) override; |
| 60 | |
Jooyung Han | 17be89b | 2020-02-21 21:17:06 +0900 | [diff] [blame] | 61 | ndk::ScopedAStatus addEntryValue(const vector<uint8_t>& content, |
| 62 | vector<uint8_t>* outEncryptedContent) override; |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 63 | |
| 64 | ndk::ScopedAStatus finishAddingEntries( |
Jooyung Han | 17be89b | 2020-02-21 21:17:06 +0900 | [diff] [blame] | 65 | vector<uint8_t>* outCredentialData, |
| 66 | vector<uint8_t>* outProofOfProvisioningSignature) override; |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 67 | |
David Zeuthen | 28edb10 | 2020-04-28 18:54:55 -0400 | [diff] [blame^] | 68 | private: |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 69 | string docType_; |
| 70 | bool testCredential_; |
| 71 | |
Selene Huang | 459cb80 | 2020-01-08 22:59:02 -0800 | [diff] [blame] | 72 | // This is set in initialize(). |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 73 | vector<uint8_t> storageKey_; |
Selene Huang | 92b61d6 | 2020-03-04 02:24:16 -0800 | [diff] [blame] | 74 | bool startPersonalizationCalled_; |
| 75 | bool firstEntry_; |
Selene Huang | 459cb80 | 2020-01-08 22:59:02 -0800 | [diff] [blame] | 76 | |
| 77 | // These are set in getAttestationCertificate(). |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 78 | vector<uint8_t> credentialPrivKey_; |
| 79 | vector<uint8_t> credentialPubKey_; |
Selene Huang | 459cb80 | 2020-01-08 22:59:02 -0800 | [diff] [blame] | 80 | vector<vector<uint8_t>> certificateChain_; |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 81 | |
| 82 | // These fields are initialized during startPersonalization() |
| 83 | size_t numAccessControlProfileRemaining_; |
| 84 | vector<int32_t> remainingEntryCounts_; |
| 85 | cppbor::Array signedDataAccessControlProfiles_; |
| 86 | cppbor::Map signedDataNamespaces_; |
| 87 | cppbor::Array signedDataCurrentNamespace_; |
David Zeuthen | 28edb10 | 2020-04-28 18:54:55 -0400 | [diff] [blame^] | 88 | size_t expectedProofOfProvisioningSize_; |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 89 | |
Selene Huang | 92b61d6 | 2020-03-04 02:24:16 -0800 | [diff] [blame] | 90 | // This field is initialized in addAccessControlProfile |
| 91 | set<int32_t> accessControlProfileIds_; |
| 92 | |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 93 | // These fields are initialized during beginAddEntry() |
| 94 | size_t entryRemainingBytes_; |
| 95 | vector<uint8_t> entryAdditionalData_; |
| 96 | string entryNameSpace_; |
| 97 | string entryName_; |
| 98 | vector<int32_t> entryAccessControlProfileIds_; |
| 99 | vector<uint8_t> entryBytes_; |
Selene Huang | 92b61d6 | 2020-03-04 02:24:16 -0800 | [diff] [blame] | 100 | set<string> allNameSpaces_; |
David Zeuthen | 8160315 | 2020-02-11 22:04:24 -0500 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | } // namespace aidl::android::hardware::identity |
| 104 | |
| 105 | #endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H |