David Zeuthen | c6eb7cd | 2017-11-27 11:33:55 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 KEYSTORE_CONFIRMATION_MANAGER_H_ |
| 18 | #define KEYSTORE_CONFIRMATION_MANAGER_H_ |
| 19 | |
| 20 | #include <android/hardware/confirmationui/1.0/IConfirmationUI.h> |
| 21 | #include <android/hardware/confirmationui/1.0/types.h> |
| 22 | #include <binder/Binder.h> |
| 23 | #include <binder/IBinder.h> |
| 24 | #include <binder/Status.h> |
| 25 | #include <keystore/keymaster_types.h> |
| 26 | #include <map> |
| 27 | #include <mutex> |
| 28 | #include <utils/LruCache.h> |
| 29 | #include <utils/StrongPointer.h> |
| 30 | #include <vector> |
| 31 | |
| 32 | namespace keystore { |
| 33 | |
| 34 | using android::binder::Status; |
| 35 | using android::hardware::confirmationui::V1_0::IConfirmationResultCallback; |
| 36 | using ConfirmationResponseCode = android::hardware::confirmationui::V1_0::ResponseCode; |
| 37 | |
| 38 | class ConfirmationManager; |
| 39 | |
| 40 | class ConfirmationManager : public android::hardware::hidl_death_recipient, |
| 41 | public IConfirmationResultCallback { |
| 42 | public: |
| 43 | explicit ConfirmationManager(android::IBinder::DeathRecipient* deathRecipient); |
| 44 | |
| 45 | // Calls into the confirmationui HAL to start a new prompt. |
| 46 | // |
| 47 | // Returns OperationPending if another application is already |
| 48 | // showing a confirmation. Otherwise returns the return code from |
| 49 | // the HAL. |
| 50 | Status presentConfirmationPrompt(const android::sp<android::IBinder>& listener, |
| 51 | const android::String16& promptText, |
| 52 | const hidl_vec<uint8_t>& extraData, |
| 53 | const android::String16& locale, int uiOptionsAsFlags, |
| 54 | int32_t* aidl_return); |
| 55 | |
| 56 | // Calls into the confirmationui HAL to cancel displaying a |
| 57 | // prompt. |
| 58 | // |
| 59 | // Returns OperatingPending if another application is showing a |
| 60 | // confirmation. Otherwise returns the return code from the HAL. |
| 61 | Status cancelConfirmationPrompt(const android::sp<android::IBinder>& listener, |
| 62 | int32_t* aidl_return); |
| 63 | |
| 64 | // Gets the latest confirmation token received from the ConfirmationUI HAL. |
| 65 | hidl_vec<uint8_t> getLatestConfirmationToken(); |
| 66 | |
| 67 | // Called by KeyStoreService when a client binder has died. |
| 68 | void binderDied(const android::wp<android::IBinder>& who); |
| 69 | |
| 70 | // hidl_death_recipient overrides: |
| 71 | virtual void serviceDied(uint64_t cookie, |
| 72 | const android::wp<android::hidl::base::V1_0::IBase>& who) override; |
| 73 | |
| 74 | // IConfirmationResultCallback overrides: |
| 75 | android::hardware::Return<void> result(ConfirmationResponseCode responseCode, |
| 76 | const hidl_vec<uint8_t>& dataThatWasConfirmed, |
| 77 | const hidl_vec<uint8_t>& confirmationToken) override; |
| 78 | |
| 79 | private: |
| 80 | friend class ConfirmationResultCallback; |
| 81 | |
| 82 | void finalizeTransaction(ConfirmationResponseCode responseCode, |
| 83 | hidl_vec<uint8_t> dataThatWasConfirmed, bool callAbortOnHal); |
| 84 | |
| 85 | // This mutex protects all data below it. |
| 86 | std::mutex mMutex; |
| 87 | |
| 88 | // The mCurrentListener and mCurrentConfirmationUI fields are set |
| 89 | // if and only if a prompt is currently showing. |
| 90 | android::sp<android::IBinder> mCurrentListener; |
| 91 | android::sp<android::hardware::confirmationui::V1_0::IConfirmationUI> mCurrentConfirmationUI; |
| 92 | android::IBinder::DeathRecipient* mDeathRecipient; |
| 93 | hidl_vec<uint8_t> mLatestConfirmationToken; |
| 94 | }; |
| 95 | |
| 96 | } // namespace keystore |
| 97 | |
| 98 | #endif // KEYSTORE_CONFIRMATION_MANAGER_H_ |