David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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 SYSTEM_SECURITY_WRITABLE_CREDENTIAL_H_ |
| 18 | #define SYSTEM_SECURITY_WRITABLE_CREDENTIAL_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include <android/security/identity/BnWritableCredential.h> |
| 24 | |
David Zeuthen | a6f9fba | 2020-02-11 22:08:27 -0500 | [diff] [blame] | 25 | #include <android/hardware/identity/IIdentityCredentialStore.h> |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace security { |
| 29 | namespace identity { |
| 30 | |
| 31 | using ::android::binder::Status; |
David Zeuthen | 472e6c8 | 2020-10-16 11:50:13 -0400 | [diff] [blame^] | 32 | using ::android::hardware::identity::HardwareInformation; |
David Zeuthen | a6f9fba | 2020-02-11 22:08:27 -0500 | [diff] [blame] | 33 | using ::android::hardware::identity::IWritableIdentityCredential; |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 34 | using ::std::string; |
| 35 | using ::std::vector; |
| 36 | |
| 37 | class WritableCredential : public BnWritableCredential { |
| 38 | public: |
| 39 | WritableCredential(const string& dataPath, const string& credentialName, const string& docType, |
David Zeuthen | 472e6c8 | 2020-10-16 11:50:13 -0400 | [diff] [blame^] | 40 | bool isUpdate, HardwareInformation hwInfo, |
| 41 | sp<IWritableIdentityCredential> halBinder, int halApiVersion); |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 42 | ~WritableCredential(); |
| 43 | |
David Zeuthen | 472e6c8 | 2020-10-16 11:50:13 -0400 | [diff] [blame^] | 44 | // Used when updating a credential |
| 45 | void setAttestationCertificate(const vector<uint8_t>& attestationCertificate); |
| 46 | void setAvailableAuthenticationKeys(int keyCount, int maxUsesPerKey); |
| 47 | void setCredentialUpdatedCallback(std::function<void()>&& onCredentialUpdatedCallback); |
| 48 | |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 49 | // IWritableCredential overrides |
| 50 | Status getCredentialKeyCertificateChain(const vector<uint8_t>& challenge, |
| 51 | vector<uint8_t>* _aidl_return) override; |
| 52 | |
| 53 | Status personalize(const vector<AccessControlProfileParcel>& accessControlProfiles, |
| 54 | const vector<EntryNamespaceParcel>& entryNamespaces, int64_t secureUserId, |
| 55 | vector<uint8_t>* _aidl_return) override; |
| 56 | |
| 57 | private: |
| 58 | string dataPath_; |
| 59 | string credentialName_; |
David Zeuthen | e2a78a4 | 2020-04-27 13:34:38 -0400 | [diff] [blame] | 60 | string docType_; |
David Zeuthen | 472e6c8 | 2020-10-16 11:50:13 -0400 | [diff] [blame^] | 61 | bool isUpdate_; |
| 62 | HardwareInformation hwInfo_; |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 63 | sp<IWritableIdentityCredential> halBinder_; |
David Zeuthen | 472e6c8 | 2020-10-16 11:50:13 -0400 | [diff] [blame^] | 64 | int halApiVersion_; |
| 65 | |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 66 | vector<uint8_t> attestationCertificate_; |
David Zeuthen | 472e6c8 | 2020-10-16 11:50:13 -0400 | [diff] [blame^] | 67 | int keyCount_ = 0; |
| 68 | int maxUsesPerKey_ = 1; |
| 69 | |
| 70 | std::function<void()> onCredentialUpdatedCallback_ = []() {}; |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 71 | |
David Zeuthen | e2a78a4 | 2020-04-27 13:34:38 -0400 | [diff] [blame] | 72 | ssize_t calcExpectedProofOfProvisioningSize( |
| 73 | const vector<AccessControlProfileParcel>& accessControlProfiles, |
| 74 | const vector<EntryNamespaceParcel>& entryNamespaces); |
| 75 | |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 76 | Status ensureAttestationCertificateExists(const vector<uint8_t>& challenge); |
| 77 | }; |
| 78 | |
| 79 | } // namespace identity |
| 80 | } // namespace security |
| 81 | } // namespace android |
| 82 | |
| 83 | #endif // SYSTEM_SECURITY_WRITABLE_CREDENTIAL_H_ |