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

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

Issue 2575963002: Handle Security Key requests from outside the remoted session correctly (Closed)
Patch Set: Addressing CR Feedback Created 4 years 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/security_key_ipc_client.h" 5 #include "remoting/host/security_key/security_key_ipc_client.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 20 matching lines...) Expand all
31 bool SecurityKeyIpcClient::CheckForSecurityKeyIpcServerChannel() { 31 bool SecurityKeyIpcClient::CheckForSecurityKeyIpcServerChannel() {
32 DCHECK(thread_checker_.CalledOnValidThread()); 32 DCHECK(thread_checker_.CalledOnValidThread());
33 33
34 if (!channel_handle_.is_valid()) { 34 if (!channel_handle_.is_valid()) {
35 channel_handle_ = mojo::edk::CreateClientHandle(named_channel_handle_); 35 channel_handle_ = mojo::edk::CreateClientHandle(named_channel_handle_);
36 } 36 }
37 return channel_handle_.is_valid(); 37 return channel_handle_.is_valid();
38 } 38 }
39 39
40 void SecurityKeyIpcClient::EstablishIpcConnection( 40 void SecurityKeyIpcClient::EstablishIpcConnection(
41 const base::Closure& connection_ready_callback, 41 const ConnectedCallback& connected_callback,
42 const base::Closure& connection_error_callback) { 42 const base::Closure& connection_error_callback) {
43 DCHECK(thread_checker_.CalledOnValidThread()); 43 DCHECK(thread_checker_.CalledOnValidThread());
44 DCHECK(!connection_ready_callback.is_null()); 44 DCHECK(!connected_callback.is_null());
45 DCHECK(!connection_error_callback.is_null()); 45 DCHECK(!connection_error_callback.is_null());
46 DCHECK(!ipc_channel_); 46 DCHECK(!ipc_channel_);
47 47
48 connection_ready_callback_ = connection_ready_callback; 48 connected_callback_ = connected_callback;
49 connection_error_callback_ = connection_error_callback; 49 connection_error_callback_ = connection_error_callback;
50 50
51 ConnectToIpcChannel(); 51 ConnectToIpcChannel();
52 } 52 }
53 53
54 bool SecurityKeyIpcClient::SendSecurityKeyRequest( 54 bool SecurityKeyIpcClient::SendSecurityKeyRequest(
55 const std::string& request_payload, 55 const std::string& request_payload,
56 const ResponseCallback& response_callback) { 56 const ResponseCallback& response_callback) {
57 DCHECK(thread_checker_.CalledOnValidThread()); 57 DCHECK(thread_checker_.CalledOnValidThread());
58 DCHECK(!request_payload.empty()); 58 DCHECK(!request_payload.empty());
(...skipping 30 matching lines...) Expand all
89 expected_ipc_server_session_id_ = expected_session_id; 89 expected_ipc_server_session_id_ = expected_session_id;
90 } 90 }
91 91
92 bool SecurityKeyIpcClient::OnMessageReceived(const IPC::Message& message) { 92 bool SecurityKeyIpcClient::OnMessageReceived(const IPC::Message& message) {
93 DCHECK(thread_checker_.CalledOnValidThread()); 93 DCHECK(thread_checker_.CalledOnValidThread());
94 94
95 bool handled = true; 95 bool handled = true;
96 IPC_BEGIN_MESSAGE_MAP(SecurityKeyIpcClient, message) 96 IPC_BEGIN_MESSAGE_MAP(SecurityKeyIpcClient, message)
97 IPC_MESSAGE_HANDLER(ChromotingNetworkToRemoteSecurityKeyMsg_Response, 97 IPC_MESSAGE_HANDLER(ChromotingNetworkToRemoteSecurityKeyMsg_Response,
98 OnSecurityKeyResponse) 98 OnSecurityKeyResponse)
99 IPC_MESSAGE_HANDLER(ChromotingNetworkToRemoteSecurityKeyMsg_ConnectionReady,
100 OnConnectionReady)
101 IPC_MESSAGE_HANDLER(ChromotingNetworkToRemoteSecurityKeyMsg_InvalidSession,
102 OnInvalidSession)
99 IPC_MESSAGE_UNHANDLED(handled = false) 103 IPC_MESSAGE_UNHANDLED(handled = false)
100 IPC_END_MESSAGE_MAP() 104 IPC_END_MESSAGE_MAP()
101 105
102 CHECK(handled) << "Received unexpected IPC type: " << message.type(); 106 CHECK(handled) << "Received unexpected IPC type: " << message.type();
103 return handled; 107 return handled;
104 } 108 }
105 109
106 void SecurityKeyIpcClient::OnChannelConnected(int32_t peer_pid) { 110 void SecurityKeyIpcClient::OnChannelConnected(int32_t peer_pid) {
107 DCHECK(thread_checker_.CalledOnValidThread()); 111 DCHECK(thread_checker_.CalledOnValidThread());
108 112
109 #if defined(OS_WIN) 113 #if defined(OS_WIN)
110 DWORD peer_session_id; 114 DWORD peer_session_id;
111 if (!ProcessIdToSessionId(peer_pid, &peer_session_id)) { 115 if (!ProcessIdToSessionId(peer_pid, &peer_session_id)) {
112 PLOG(ERROR) << "ProcessIdToSessionId failed"; 116 PLOG(ERROR) << "ProcessIdToSessionId failed";
113 base::ResetAndReturn(&connection_error_callback_).Run(); 117 base::ResetAndReturn(&connection_error_callback_).Run();
114 return; 118 return;
115 } 119 }
116 120
117 if (peer_session_id != expected_ipc_server_session_id_) { 121 if (peer_session_id != expected_ipc_server_session_id_) {
118 LOG(ERROR) 122 LOG(ERROR)
119 << "Cannot establish connection with IPC server running in session: " 123 << "Cannot establish connection with IPC server running in session: "
120 << peer_session_id; 124 << peer_session_id;
121 base::ResetAndReturn(&connection_error_callback_).Run(); 125 base::ResetAndReturn(&connection_error_callback_).Run();
122 return; 126 return;
123 } 127 }
124 #endif // defined(OS_WIN) 128 #endif // defined(OS_WIN)
125
126 base::ResetAndReturn(&connection_ready_callback_).Run();
127 } 129 }
128 130
129 void SecurityKeyIpcClient::OnChannelError() { 131 void SecurityKeyIpcClient::OnChannelError() {
130 DCHECK(thread_checker_.CalledOnValidThread()); 132 DCHECK(thread_checker_.CalledOnValidThread());
131 133
132 if (!connection_error_callback_.is_null()) { 134 if (!connection_error_callback_.is_null()) {
133 base::ResetAndReturn(&connection_error_callback_).Run(); 135 base::ResetAndReturn(&connection_error_callback_).Run();
134 } 136 }
135 } 137 }
136 138
137 void SecurityKeyIpcClient::OnSecurityKeyResponse( 139 void SecurityKeyIpcClient::OnSecurityKeyResponse(
138 const std::string& response_data) { 140 const std::string& response_data) {
139 DCHECK(thread_checker_.CalledOnValidThread()); 141 DCHECK(thread_checker_.CalledOnValidThread());
140 DCHECK(!connection_error_callback_.is_null()); 142 DCHECK(!connection_error_callback_.is_null());
141 143
142 if (!response_data.empty()) { 144 if (!response_data.empty()) {
143 base::ResetAndReturn(&response_callback_).Run(response_data); 145 base::ResetAndReturn(&response_callback_).Run(response_data);
144 } else { 146 } else {
145 LOG(ERROR) << "Invalid response received"; 147 LOG(ERROR) << "Invalid response received";
146 base::ResetAndReturn(&connection_error_callback_).Run(); 148 base::ResetAndReturn(&connection_error_callback_).Run();
147 } 149 }
148 } 150 }
149 151
152 void SecurityKeyIpcClient::OnConnectionReady() {
153 DCHECK(thread_checker_.CalledOnValidThread());
154 DCHECK(!connected_callback_.is_null());
dcheng 2016/12/16 02:33:07 Just to double-check: is the server end (the one s
joedow 2016/12/16 03:36:22 The server in this context is our network process
dcheng 2016/12/16 09:12:03 It's hard for me to tell if the network service is
joedow 2016/12/16 16:20:18 The network process is a low-integrity process. I
155
156 base::ResetAndReturn(&connected_callback_).Run(/*connection_usable=*/true);
157 }
158
159 void SecurityKeyIpcClient::OnInvalidSession() {
160 DCHECK(thread_checker_.CalledOnValidThread());
161 DCHECK(!connected_callback_.is_null());
162
163 base::ResetAndReturn(&connected_callback_).Run(/*connection_usable=*/false);
164 }
165
150 void SecurityKeyIpcClient::ConnectToIpcChannel() { 166 void SecurityKeyIpcClient::ConnectToIpcChannel() {
151 DCHECK(thread_checker_.CalledOnValidThread()); 167 DCHECK(thread_checker_.CalledOnValidThread());
152 168
153 // Verify that any existing IPC connection has been closed. 169 // Verify that any existing IPC connection has been closed.
154 CloseIpcConnection(); 170 CloseIpcConnection();
155 171
156 if (!channel_handle_.is_valid() && !CheckForSecurityKeyIpcServerChannel()) { 172 if (!channel_handle_.is_valid() && !CheckForSecurityKeyIpcServerChannel()) {
157 if (!connection_error_callback_.is_null()) { 173 if (!connection_error_callback_.is_null()) {
158 base::ResetAndReturn(&connection_error_callback_).Run(); 174 base::ResetAndReturn(&connection_error_callback_).Run();
159 } 175 }
160 return; 176 return;
161 } 177 }
162 178
163 ipc_channel_ = IPC::Channel::CreateClient( 179 ipc_channel_ = IPC::Channel::CreateClient(
164 mojo::edk::ConnectToPeerProcess(std::move(channel_handle_)).release(), 180 mojo::edk::ConnectToPeerProcess(std::move(channel_handle_)).release(),
165 this); 181 this);
166 if (ipc_channel_->Connect()) { 182 if (ipc_channel_->Connect()) {
167 return; 183 return;
168 } 184 }
169 ipc_channel_.reset(); 185 ipc_channel_.reset();
170 186
171 if (!connection_error_callback_.is_null()) { 187 if (!connection_error_callback_.is_null()) {
172 base::ResetAndReturn(&connection_error_callback_).Run(); 188 base::ResetAndReturn(&connection_error_callback_).Run();
173 } 189 }
174 } 190 }
175 191
176 } // namespace remoting 192 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698