• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
ConfUiSecureUserSelectionMessage(const ConfUiUserSelectionMessage & msg,const bool secure)36   ConfUiSecureUserSelectionMessage(const ConfUiUserSelectionMessage& msg,
37                                    const bool secure)
38       : ConfUiMessage(msg.GetSessionId()), msg_(msg), is_secure_(secure) {}
39   ConfUiSecureUserSelectionMessage() = delete;
40   virtual ~ConfUiSecureUserSelectionMessage() = default;
ToString()41   std::string ToString() const override { return msg_.ToString(); }
GetType()42   ConfUiCmd GetType() const override { return msg_.GetType(); }
GetResponse()43   auto GetResponse() const { return msg_.GetResponse(); }
44   // SendOver is between guest and host, so it doesn't send the is_secure_
SendOver(SharedFD fd)45   bool SendOver(SharedFD fd) override { return msg_.SendOver(fd); }
IsSecure()46   bool IsSecure() const { return is_secure_; }
47   // SetSecure() might be needed later on but not now.
48 
49  private:
50   ConfUiUserSelectionMessage msg_;
51   bool is_secure_;
52 };
53 
54 class ConfUiSecureUserTouchMessage : public ConfUiMessage {
55  public:
ConfUiSecureUserTouchMessage(const ConfUiUserTouchMessage & msg,const bool secure)56   ConfUiSecureUserTouchMessage(const ConfUiUserTouchMessage& msg,
57                                const bool secure)
58       : ConfUiMessage(msg.GetSessionId()), msg_(msg), is_secure_(secure) {}
59   virtual ~ConfUiSecureUserTouchMessage() = default;
ToString()60   std::string ToString() const override { return msg_.ToString(); }
GetType()61   ConfUiCmd GetType() const override { return msg_.GetType(); }
GetResponse()62   auto GetResponse() const { return msg_.GetResponse(); }
SendOver(SharedFD fd)63   bool SendOver(SharedFD fd) override { return msg_.SendOver(fd); }
GetLocation()64   std::pair<int, int> GetLocation() { return msg_.GetLocation(); }
IsSecure()65   bool IsSecure() const { return is_secure_; }
66 
67  private:
68   ConfUiUserTouchMessage msg_;
69   bool is_secure_;
70 };
71 
72 std::unique_ptr<ConfUiSecureUserSelectionMessage> ToSecureSelectionMessage(
73     const ConfUiUserSelectionMessage& msg, const bool secure);
74 std::unique_ptr<ConfUiSecureUserTouchMessage> ToSecureTouchMessage(
75     const ConfUiUserTouchMessage& msg, const bool secure);
76 }  // end of namespace confui
77 }  // end of namespace cuttlefish
78