1 /*
2  * Copyright (C) 2022 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 #pragma once
18 
19 #include <memory>
20 
21 #include "common/libs/confui/confui.h"
22 
23 /** ConfUiUserSelectionMessage with a security flag
24  *
25  * Inputs generated by something that belong to (virtualized) TEE is regarded
26  * as secure. Otherwise (e.g. inputs generated by the guest calling
27  * deliverSecureInputEvent), it is regarded as insecure.
28  *
29  * The host marks the security field, and use it internally and exclusively.
30  *
31  */
32 namespace cuttlefish {
33 namespace confui {
34 class ConfUiSecureUserSelectionMessage : public ConfUiMessage {
35  public:
36   ConfUiSecureUserSelectionMessage(
37       std::unique_ptr<ConfUiUserSelectionMessage>&& msg, const bool secure);
38   ConfUiSecureUserSelectionMessage() = delete;
39   virtual ~ConfUiSecureUserSelectionMessage() = default;
ToString()40   std::string ToString() const override { return msg_->ToString(); }
GetType()41   ConfUiCmd GetType() const override { return msg_->GetType(); }
GetResponse()42   auto GetResponse() const { return msg_->GetResponse(); }
43   // SendOver is between guest and host, so it doesn't send the is_secure_
SendOver(SharedFD fd)44   bool SendOver(SharedFD fd) override { return msg_->SendOver(fd); }
IsSecure()45   bool IsSecure() const { return is_secure_; }
46   // SetSecure() might be needed later on but not now.
47 
48  private:
49   std::unique_ptr<ConfUiUserSelectionMessage> msg_;
50   bool is_secure_;
51 };
52 
53 class ConfUiSecureUserTouchMessage : public ConfUiMessage {
54  public:
55   ConfUiSecureUserTouchMessage(std::unique_ptr<ConfUiUserTouchMessage>&& msg,
56                                const bool secure);
57   virtual ~ConfUiSecureUserTouchMessage() = default;
ToString()58   std::string ToString() const override { return msg_->ToString(); }
GetType()59   ConfUiCmd GetType() const override { return msg_->GetType(); }
GetResponse()60   auto GetResponse() const { return msg_->GetResponse(); }
SendOver(SharedFD fd)61   bool SendOver(SharedFD fd) override { return msg_->SendOver(fd); }
GetLocation()62   std::pair<int, int> GetLocation() const { return msg_->GetLocation(); }
IsSecure()63   bool IsSecure() const { return is_secure_; }
64 
65  private:
66   std::unique_ptr<ConfUiUserTouchMessage> msg_;
67   bool is_secure_;
68 };
69 
70 std::unique_ptr<ConfUiSecureUserSelectionMessage> ToSecureSelectionMessage(
71     std::unique_ptr<ConfUiUserSelectionMessage>&& msg, const bool secure);
72 std::unique_ptr<ConfUiSecureUserTouchMessage> ToSecureTouchMessage(
73     std::unique_ptr<ConfUiUserTouchMessage>&& msg, const bool secure);
74 }  // end of namespace confui
75 }  // end of namespace cuttlefish
76