Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: remoting/host/security_key/security_key_message.h

Issue 1821393002: Adding the message definitions for the remote_security_key STDIO communication classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating enum translation function per feedback Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/host/security_key/security_key_message.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_
6 #define REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_
7
8 #include <cstdint>
9 #include <string>
10
11 #include "base/callback_forward.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14
15 namespace remoting {
16
17 // -----------------------------------------------------------------------------
18 // Introduction
19 // -----------------------------------------------------------------------------
20 //
21 // This file defines the message format and messages used to interact with the
22 // remote_security_key process which is used to forward security key requests
23 // to a remote client and return security key responses from the remote client.
24
25 // -----------------------------------------------------------------------------
26 // Message Format
27 // -----------------------------------------------------------------------------
28 //
29 // {Header: uint32_t}{Control Code: uint8_t}{Payload: optional, variable length}
30 //
31 // Header: Defines the length of the message (Control Code + Payload).
32 // The header endianness is determined by the platform.
33 // Control Code: Contains a value representing the message type.
34 // Payload: An optional field of variable length. Data being represented in
35 // this field is dependent on the message type.
36 // The endianess of the payload is dependent on the message type.
37 // Multi-byte payloads which are part of the security key request and
38 // response messages are expected to be big endian. The bytes for
39 // these messages will be transmitted across the network as-is.
40 // The format for all other payloads is the endianness of the platform.
41
42 // -----------------------------------------------------------------------------
43 // Messages
44 // -----------------------------------------------------------------------------
45 // NOTE: Make sure SecurityKeyMessage::MessageTypeFromValue is updated when new
46 // enum values are added/removed.
47 enum class RemoteSecurityKeyMessageType : uint8_t {
48 INVALID = 0,
49
50 // Sent to the remote_security_key process to ask it to establish a
51 // connection to the Chromoting host if a security key enabled session
52 // exists for the current user.
53 // Payload length: 0
54 CONNECT = 1,
55
56 // Sent is sent by the remote_security_key process in response to a
57 // |kConnectToSecurityKeyEnabledSessionMsg| request.
58 // Payload length: 1 byte bool indicating connection state.
59 // True(1): A connection with the Chromoting Host is established and ready
60 // to receive security key requests to forward.
61 // False(0): No security key session was found.
62 CONNECT_RESPONSE = 2,
63
64 // Sent by the remote_security_key proces when an error occurs while
65 // attempting to detect the existence of a Chromoting session or when
66 // establishing a connection to it.
67 // Payload length: variable. If > 0 bytes, the bytes represent an error
68 // string which is ascii encoded and does not include a null terminator.
69 CONNECT_ERROR = 3,
70
71 // Sent to the remote_security_key process to ask it to forward the
72 // security key request payload bytes to the remote machine.
73 // Payload length: > 0 bytes consisting of the security key message to
74 // forward to the remote machine using Length-Value format.
75 REQUEST = 4,
76
77 // Sent by the remote_security_key once a response has been received from
78 // the remote machine.
79 // Payload length: > 0 bytes consisting of the security key response from
80 // the remote machine using Length-Value format.
81 REQUEST_RESPONSE = 5,
82
83 // Sent by the remote_security_key if an error occurs either in sending the
84 // request data to the remote host or when receiving the response.
85 // Payload length: variable. If > 0 bytes, the bytes represent an error
86 // string which is ascii encoded and does not include a null terminator.
87 REQUEST_ERROR = 6,
88
89 // Sent by the remote_security_key if it receives an unknown command.
90 // Payload length: 0 bytes.
91 UNKNOWN_COMMAND = 254,
92
93 // Sent by the remote_security_key if an error occurs which does not conform
94 // to any existing category. No response to this message is expected.
95 // Payload length: variable. If > 0 bytes, the bytes represent an error
96 // string which is ascii encoded and does not include a null terminator.
97 UNKNOWN_ERROR = 255,
98 };
99
100 class SecurityKeyMessage final {
101 public:
102 // The number of bytes used to represent the header.
103 static const int kHeaderSizeBytes = 4;
104
105 SecurityKeyMessage();
106 ~SecurityKeyMessage();
107
108 // When given a header value (uint32_t), this method will return whether the
109 // length is within the allowable size range.
110 static bool IsValidMessageSize(uint32_t message_size);
111
112 // Returns a RemoteSecurityKeyMessageType enum value corresponding to the
113 // value passed in if it is valid, otherwise INVALID is returned.
114 static RemoteSecurityKeyMessageType MessageTypeFromValue(int value);
115
116 // Parses |message_data| and initializes the internal members. Returns true
117 // if |message_data| was parsed and the instance was initialized successfully.
118 bool ParseMessage(const std::string& message_data);
119
120 RemoteSecurityKeyMessageType type() { return type_; }
121
122 const std::string& payload() { return payload_; }
123
124 private:
125 RemoteSecurityKeyMessageType type_ = RemoteSecurityKeyMessageType::INVALID;
126 std::string payload_;
127
128 DISALLOW_COPY_AND_ASSIGN(SecurityKeyMessage);
129 };
130
131 // Used to pass remote security key message data between classes.
132 typedef base::Callback<void(scoped_ptr<SecurityKeyMessage> message)>
133 SecurityKeyMessageCallback;
134
135 } // namespace remoting
136
137 #endif // REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/host/security_key/security_key_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698