blob: 46b623cb77706609363501b3663c85cb6ba62b93 [file] [log] [blame]
David Zeuthenc6eb7cd2017-11-27 11:33:55 -05001/*
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
Janis Danisevskis064ce852018-03-12 16:49:16 -070032#include "confirmationui_rate_limiting.h"
33
David Zeuthenc6eb7cd2017-11-27 11:33:55 -050034namespace keystore {
35
36using android::binder::Status;
37using android::hardware::confirmationui::V1_0::IConfirmationResultCallback;
38using ConfirmationResponseCode = android::hardware::confirmationui::V1_0::ResponseCode;
39
40class ConfirmationManager;
41
42class ConfirmationManager : public android::hardware::hidl_death_recipient,
43 public IConfirmationResultCallback {
44 public:
45 explicit ConfirmationManager(android::IBinder::DeathRecipient* deathRecipient);
46
47 // Calls into the confirmationui HAL to start a new prompt.
48 //
49 // Returns OperationPending if another application is already
50 // showing a confirmation. Otherwise returns the return code from
51 // the HAL.
52 Status presentConfirmationPrompt(const android::sp<android::IBinder>& listener,
53 const android::String16& promptText,
54 const hidl_vec<uint8_t>& extraData,
55 const android::String16& locale, int uiOptionsAsFlags,
56 int32_t* aidl_return);
57
58 // Calls into the confirmationui HAL to cancel displaying a
59 // prompt.
60 //
61 // Returns OperatingPending if another application is showing a
62 // confirmation. Otherwise returns the return code from the HAL.
63 Status cancelConfirmationPrompt(const android::sp<android::IBinder>& listener,
64 int32_t* aidl_return);
65
David Zeuthen1a492312018-02-26 11:00:30 -050066 // Checks if the confirmationUI HAL is available.
67 Status isConfirmationPromptSupported(bool* aidl_return);
68
David Zeuthenc6eb7cd2017-11-27 11:33:55 -050069 // Gets the latest confirmation token received from the ConfirmationUI HAL.
70 hidl_vec<uint8_t> getLatestConfirmationToken();
71
72 // Called by KeyStoreService when a client binder has died.
73 void binderDied(const android::wp<android::IBinder>& who);
74
75 // hidl_death_recipient overrides:
76 virtual void serviceDied(uint64_t cookie,
77 const android::wp<android::hidl::base::V1_0::IBase>& who) override;
78
79 // IConfirmationResultCallback overrides:
80 android::hardware::Return<void> result(ConfirmationResponseCode responseCode,
81 const hidl_vec<uint8_t>& dataThatWasConfirmed,
82 const hidl_vec<uint8_t>& confirmationToken) override;
83
84 private:
85 friend class ConfirmationResultCallback;
86
87 void finalizeTransaction(ConfirmationResponseCode responseCode,
88 hidl_vec<uint8_t> dataThatWasConfirmed, bool callAbortOnHal);
89
90 // This mutex protects all data below it.
91 std::mutex mMutex;
92
93 // The mCurrentListener and mCurrentConfirmationUI fields are set
94 // if and only if a prompt is currently showing.
95 android::sp<android::IBinder> mCurrentListener;
96 android::sp<android::hardware::confirmationui::V1_0::IConfirmationUI> mCurrentConfirmationUI;
97 android::IBinder::DeathRecipient* mDeathRecipient;
98 hidl_vec<uint8_t> mLatestConfirmationToken;
Janis Danisevskis064ce852018-03-12 16:49:16 -070099 RateLimiting<> mRateLimiting;
David Zeuthenc6eb7cd2017-11-27 11:33:55 -0500100};
101
102} // namespace keystore
103
104#endif // KEYSTORE_CONFIRMATION_MANAGER_H_