Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <stdint.h> | |
| 9 | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/callback.h" | |
|
Sergey Ulanov
2016/03/24 21:51:17
callback_forward.h please
joedow
2016/03/28 19:44:26
Done.
| |
| 13 | |
| 14 namespace remoting { | |
| 15 | |
| 16 // ----------------------------------------------------------------------------- | |
| 17 // Introduction | |
| 18 // ----------------------------------------------------------------------------- | |
| 19 // | |
| 20 // This file defines the message format and messages used to interact with the | |
| 21 // remote_security_key process which is used to forward security key requests | |
| 22 // to a remote client and return security key responses from the remote client. | |
| 23 | |
| 24 // ----------------------------------------------------------------------------- | |
| 25 // Message Format | |
| 26 // ----------------------------------------------------------------------------- | |
| 27 // | |
| 28 // {Header: uint32_t}{Control Code: uint8_t}{Payload: optional, variable length} | |
| 29 // | |
| 30 // Header: Defines the length of the message (Control Code + Payload). | |
| 31 // The header endianness is determined by the platform. | |
| 32 // Control Code: Contains a value representing the message type. | |
| 33 // Payload: An optional field of variable length. Data being represented in | |
| 34 // this field is dependent on the message type. | |
| 35 // The endianess of the payload is dependent on the message type. | |
| 36 // Multi-byte payloads which are part of the security key request and | |
| 37 // response messages are expected to be big endian. The bytes for | |
| 38 // these messages will be transmitted across the network as-is. | |
| 39 // The format for all other payloads is the endianness of the platform. | |
| 40 | |
| 41 // ----------------------------------------------------------------------------- | |
| 42 // Messages | |
| 43 // ----------------------------------------------------------------------------- | |
| 44 enum class RemoteSecurityKeyMessageType : uint8_t { | |
| 45 kUnitialized = 0, | |
| 46 | |
| 47 // Sent to the remote_security_key process to ask it to establish a | |
| 48 // connection to the Chromoting host if a security key enabled session | |
| 49 // exists for the current user. | |
| 50 // Payload length: 0 | |
| 51 kConnectToSecurityKeyEnabledSessionMsg = 1, | |
|
Sergey Ulanov
2016/03/24 21:51:17
Please use MACRO_STYLE for these names. Chromium s
joedow
2016/03/28 19:44:26
Done.
| |
| 52 | |
| 53 // Sent is sent by the remote_security_key process in response to a | |
| 54 // |kConnectToSecurityKeyEnabledSessionMsg| request. | |
| 55 // Payload length: 1 byte bool indicating connection state. | |
| 56 // True(1): A connection with the Chromoting Host is established and ready | |
| 57 // to receive security key requests to forward. | |
| 58 // False(0): No security key session was found. | |
| 59 kConnectToSecurityKeyEnabledSessionRsp = 2, | |
| 60 | |
| 61 // Sent by the remote_security_key proces when an error occurs while | |
| 62 // attempting to detect the existence of a Chromoting session or when | |
| 63 // establishing a connection to it. | |
| 64 // Payload length: variable. If > 0 bytes, the bytes represent an error | |
| 65 // string which is ascii encoded and does not include a null terminator. | |
| 66 kConnectToSecurityKeyEnabledSessionErr = 3, | |
| 67 | |
| 68 // Sent to the remote_security_key process to ask it to forward the | |
| 69 // security key request payload bytes to the remote machine. | |
| 70 // Payload length: > 0 bytes consisting of the security key message to | |
| 71 // forward to the remote machine using Length-Value format. | |
| 72 kRemoteSecurityKeyRequestMsg = 4, | |
| 73 | |
| 74 // Sent by the remote_security_key once a response has been received from | |
| 75 // the remote machine. | |
| 76 // Payload length: > 0 bytes consisting of the security key response from | |
| 77 // the remote machine using Length-Value format. | |
| 78 kRemoteSecurityKeyRequestRsp = 5, | |
| 79 | |
| 80 // Sent by the remote_security_key if an error occurs either in sending the | |
| 81 // request data to the remote host or when receiving the response. | |
| 82 // Payload length: variable. If > 0 bytes, the bytes represent an error | |
| 83 // string which is ascii encoded and does not include a null terminator. | |
| 84 kRemoteSecurityKeyRequestErr = 6, | |
| 85 | |
| 86 // Sent by the remote_security_key if it receives an unknown command. | |
| 87 // Payload length: 0 bytes. | |
| 88 kRemoteSecurityKeyUnknownMessageErrorMsg = 254, | |
| 89 | |
| 90 // Sent by the remote_security_key if an error occurs which does not conform | |
| 91 // to any existing category. No response to this message is expected. | |
| 92 // Payload length: variable. If > 0 bytes, the bytes represent an error | |
| 93 // string which is ascii encoded and does not include a null terminator. | |
| 94 kRemoteSecurityKeyUnknownErrorMsg = 255, | |
| 95 }; | |
| 96 | |
| 97 class SecurityKeyMessage final { | |
| 98 public: | |
| 99 SecurityKeyMessage(); | |
| 100 ~SecurityKeyMessage(); | |
| 101 // Used to pass remote security key message data between classes. | |
| 102 typedef base::Callback<void(scoped_ptr<SecurityKeyMessage> message)> Callback; | |
|
Sergey Ulanov
2016/03/24 21:51:17
Move this above the constructor: https://google.gi
Sergey Ulanov
2016/03/24 21:51:18
I don't think this callback should be part of this
joedow
2016/03/28 19:44:26
Acknowledged.
joedow
2016/03/28 19:44:26
The callback is used by the reader and handler (al
| |
| 103 | |
| 104 // The number of bytes used to represent the header. | |
| 105 static const int kHeaderSizeBytes; | |
|
Sergey Ulanov
2016/03/24 21:51:17
move this above constructor. Also add "= 4" here -
joedow
2016/03/28 19:44:26
Done.
| |
| 106 | |
| 107 // When given a header value (uint32_t), this method will return whether the | |
| 108 // length is within the allowable size range. | |
| 109 static bool IsValidMessageSize(uint32_t message_size); | |
| 110 | |
| 111 // Parses |message_data| and initializes the internal members. Returns true | |
| 112 // if |message_data| was parsed and the instance was initialized successfully. | |
| 113 bool ParseMessage(const std::string& message_data); | |
| 114 | |
| 115 RemoteSecurityKeyMessageType type() { return type_; } | |
| 116 | |
| 117 const std::string& payload() { return payload_; } | |
| 118 | |
| 119 private: | |
| 120 RemoteSecurityKeyMessageType type_ = | |
| 121 RemoteSecurityKeyMessageType::kUnitialized; | |
| 122 std::string payload_; | |
| 123 | |
| 124 DISALLOW_COPY_AND_ASSIGN(SecurityKeyMessage); | |
| 125 }; | |
| 126 | |
| 127 } // namespace remoting | |
| 128 | |
| 129 #endif // REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_ | |
| OLD | NEW |