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

Side by Side Diff: remoting/host/security_key/remote_security_key_ipc_server_impl.cc

Issue 2085353004: Update GnubbyAuthHandler to use the current session ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host_extension
Patch Set: Updating a comment Created 4 years, 5 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/security_key/remote_security_key_ipc_server_impl.h" 5 #include "remoting/host/security_key/remote_security_key_ipc_server_impl.h"
6 6
7 #include <cstdint>
7 #include <memory> 8 #include <memory>
8 #include <string> 9 #include <string>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/location.h"
12 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
14 #include "ipc/ipc_channel.h" 17 #include "ipc/ipc_channel.h"
15 #include "ipc/ipc_message.h" 18 #include "ipc/ipc_message.h"
16 #include "ipc/ipc_message_macros.h" 19 #include "ipc/ipc_message_macros.h"
17 #include "remoting/base/logging.h" 20 #include "remoting/base/logging.h"
18 #include "remoting/host/chromoting_messages.h" 21 #include "remoting/host/chromoting_messages.h"
19 22
20 #if defined(OS_WIN) 23 #if defined(OS_WIN)
21 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
22 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
23 #include "base/win/win_util.h" 26 #include "base/win/win_util.h"
24 #include "remoting/host/ipc_util.h" 27 #include "remoting/host/ipc_util.h"
25 #endif // defined(OS_WIN) 28 #endif // defined(OS_WIN)
26 29
27 namespace { 30 namespace {
28 31
29 // Returns the command code (the first byte of the data) if it exists, or -1 if 32 // Returns the command code (the first byte of the data) if it exists, or -1 if
30 // the data is empty. 33 // the data is empty.
31 unsigned int GetCommandCode(const std::string& data) { 34 unsigned int GetCommandCode(const std::string& data) {
32 return data.empty() ? -1 : static_cast<unsigned int>(data[0]); 35 return data.empty() ? -1 : static_cast<unsigned int>(data[0]);
33 } 36 }
34 37
35 } // namespace 38 } // namespace
36 39
37 namespace remoting { 40 namespace remoting {
38 41
39 RemoteSecurityKeyIpcServerImpl::RemoteSecurityKeyIpcServerImpl( 42 RemoteSecurityKeyIpcServerImpl::RemoteSecurityKeyIpcServerImpl(
40 int connection_id, 43 int connection_id,
44 uint32_t peer_session_id,
41 base::TimeDelta initial_connect_timeout, 45 base::TimeDelta initial_connect_timeout,
42 const GnubbyAuthHandler::SendMessageCallback& message_callback, 46 const GnubbyAuthHandler::SendMessageCallback& message_callback,
43 const base::Closure& done_callback) 47 const base::Closure& done_callback)
44 : connection_id_(connection_id), 48 : connection_id_(connection_id),
49 peer_session_id_(peer_session_id),
45 initial_connect_timeout_(initial_connect_timeout), 50 initial_connect_timeout_(initial_connect_timeout),
46 done_callback_(done_callback), 51 done_callback_(done_callback),
47 message_callback_(message_callback) { 52 message_callback_(message_callback),
53 weak_factory_(this) {
48 DCHECK_GT(connection_id_, 0); 54 DCHECK_GT(connection_id_, 0);
49 DCHECK(!done_callback_.is_null()); 55 DCHECK(!done_callback_.is_null());
50 DCHECK(!message_callback_.is_null()); 56 DCHECK(!message_callback_.is_null());
51 } 57 }
52 58
53 RemoteSecurityKeyIpcServerImpl::~RemoteSecurityKeyIpcServerImpl() {} 59 RemoteSecurityKeyIpcServerImpl::~RemoteSecurityKeyIpcServerImpl() {}
54 60
55 bool RemoteSecurityKeyIpcServerImpl::CreateChannel( 61 bool RemoteSecurityKeyIpcServerImpl::CreateChannel(
56 const std::string& channel_name, 62 const std::string& channel_name,
57 base::TimeDelta request_timeout) { 63 base::TimeDelta request_timeout) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 base::Unretained(this))); 114 base::Unretained(this)));
109 115
110 return ipc_channel_->Send( 116 return ipc_channel_->Send(
111 new ChromotingNetworkToRemoteSecurityKeyMsg_Response(response)); 117 new ChromotingNetworkToRemoteSecurityKeyMsg_Response(response));
112 } 118 }
113 119
114 bool RemoteSecurityKeyIpcServerImpl::OnMessageReceived( 120 bool RemoteSecurityKeyIpcServerImpl::OnMessageReceived(
115 const IPC::Message& message) { 121 const IPC::Message& message) {
116 DCHECK(thread_checker_.CalledOnValidThread()); 122 DCHECK(thread_checker_.CalledOnValidThread());
117 123
124 if (connection_close_pending_) {
125 LOG(WARNING) << "IPC Message ignored because channel is being closed.";
126 return false;
127 }
128
118 bool handled = true; 129 bool handled = true;
119 IPC_BEGIN_MESSAGE_MAP(RemoteSecurityKeyIpcServerImpl, message) 130 IPC_BEGIN_MESSAGE_MAP(RemoteSecurityKeyIpcServerImpl, message)
120 IPC_MESSAGE_HANDLER(ChromotingRemoteSecurityKeyToNetworkMsg_Request, 131 IPC_MESSAGE_HANDLER(ChromotingRemoteSecurityKeyToNetworkMsg_Request,
121 OnSecurityKeyRequest) 132 OnSecurityKeyRequest)
122 IPC_MESSAGE_UNHANDLED(handled = false) 133 IPC_MESSAGE_UNHANDLED(handled = false)
123 IPC_END_MESSAGE_MAP() 134 IPC_END_MESSAGE_MAP()
124 135
125 CHECK(handled) << "Received unexpected IPC type: " << message.type(); 136 CHECK(handled) << "Received unexpected IPC type: " << message.type();
126 return handled; 137 return handled;
127 } 138 }
128 139
129 void RemoteSecurityKeyIpcServerImpl::OnChannelConnected(int32_t peer_pid) { 140 void RemoteSecurityKeyIpcServerImpl::OnChannelConnected(int32_t peer_pid) {
130 DCHECK(thread_checker_.CalledOnValidThread()); 141 DCHECK(thread_checker_.CalledOnValidThread());
142
143 #if defined(OS_WIN)
144 DWORD peer_session_id;
145 if (!ProcessIdToSessionId(peer_pid, &peer_session_id)) {
146 PLOG(ERROR) << "ProcessIdToSessionId() failed";
147 connection_close_pending_ = true;
148 } else if (peer_session_id != peer_session_id_) {
149 LOG(ERROR) << "Ignoring connection attempt from outside remoted session.";
150 connection_close_pending_ = true;
151 }
152 if (connection_close_pending_) {
153 base::ThreadTaskRunnerHandle::Get()->PostTask(
154 FROM_HERE, base::Bind(&RemoteSecurityKeyIpcServerImpl::OnChannelError,
155 weak_factory_.GetWeakPtr()));
156 return;
157 }
158 #else // !defined(OS_WIN)
159 CHECK_EQ(peer_session_id_, UINT32_MAX);
160 #endif // !defined(OS_WIN)
161
131 // Reset the timer to give the client a chance to send the request. 162 // Reset the timer to give the client a chance to send the request.
132 timer_.Start(FROM_HERE, initial_connect_timeout_, 163 timer_.Start(FROM_HERE, initial_connect_timeout_,
133 base::Bind(&RemoteSecurityKeyIpcServerImpl::OnChannelError, 164 base::Bind(&RemoteSecurityKeyIpcServerImpl::OnChannelError,
134 base::Unretained(this))); 165 base::Unretained(this)));
135 } 166 }
136 167
137 void RemoteSecurityKeyIpcServerImpl::OnChannelError() { 168 void RemoteSecurityKeyIpcServerImpl::OnChannelError() {
138 DCHECK(thread_checker_.CalledOnValidThread()); 169 DCHECK(thread_checker_.CalledOnValidThread());
170 if (ipc_channel_) {
171 ipc_channel_->Close();
172 connection_close_pending_ = false;
173 }
139 174
140 if (!done_callback_.is_null()) { 175 if (!done_callback_.is_null()) {
141 // Note: This callback may result in this object being torn down. 176 // Note: This callback may result in this object being torn down.
142 base::ResetAndReturn(&done_callback_).Run(); 177 base::ResetAndReturn(&done_callback_).Run();
143 } 178 }
144 } 179 }
145 180
146 void RemoteSecurityKeyIpcServerImpl::OnSecurityKeyRequest( 181 void RemoteSecurityKeyIpcServerImpl::OnSecurityKeyRequest(
147 const std::string& request_data) { 182 const std::string& request_data) {
148 DCHECK(thread_checker_.CalledOnValidThread()); 183 DCHECK(thread_checker_.CalledOnValidThread());
149 184
150 // Reset the timer to give the client a chance to send the response. 185 // Reset the timer to give the client a chance to send the response.
151 timer_.Start(FROM_HERE, security_key_request_timeout_, 186 timer_.Start(FROM_HERE, security_key_request_timeout_,
152 base::Bind(&RemoteSecurityKeyIpcServerImpl::OnChannelError, 187 base::Bind(&RemoteSecurityKeyIpcServerImpl::OnChannelError,
153 base::Unretained(this))); 188 base::Unretained(this)));
154 189
155 HOST_LOG << "Received gnubby request: " << GetCommandCode(request_data); 190 HOST_LOG << "Received gnubby request: " << GetCommandCode(request_data);
156 message_callback_.Run(connection_id_, request_data); 191 message_callback_.Run(connection_id_, request_data);
157 } 192 }
158 193
159 } // namespace remoting 194 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698