OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromoting_host.h" | 5 #include "remoting/host/chromoting_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "remoting/protocol/input_stub.h" | 24 #include "remoting/protocol/input_stub.h" |
25 #include "remoting/protocol/jingle_session_manager.h" | 25 #include "remoting/protocol/jingle_session_manager.h" |
26 #include "remoting/protocol/libjingle_transport_factory.h" | 26 #include "remoting/protocol/libjingle_transport_factory.h" |
27 #include "remoting/protocol/session_config.h" | 27 #include "remoting/protocol/session_config.h" |
28 | 28 |
29 using remoting::protocol::ConnectionToClient; | 29 using remoting::protocol::ConnectionToClient; |
30 using remoting::protocol::InputStub; | 30 using remoting::protocol::InputStub; |
31 | 31 |
32 namespace remoting { | 32 namespace remoting { |
33 | 33 |
34 namespace { | |
35 | |
36 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { | |
37 // Number of initial errors (in sequence) to ignore before applying | |
38 // exponential back-off rules. | |
39 0, | |
40 | |
41 // Initial delay for exponential back-off in ms. | |
42 2000, | |
43 | |
44 // Factor by which the waiting time will be multiplied. | |
45 2, | |
46 | |
47 // Fuzzing percentage. ex: 10% will spread requests randomly | |
48 // between 90%-100% of the calculated time. | |
49 0, | |
50 | |
51 // Maximum amount of time we are willing to delay our request in ms. | |
52 -1, | |
53 | |
54 // Time to keep an entry from being discarded even when it | |
55 // has no significant state, -1 to never discard. | |
56 -1, | |
57 }; | |
58 | |
59 } // namespace | |
60 | |
34 ChromotingHost::ChromotingHost( | 61 ChromotingHost::ChromotingHost( |
35 ChromotingHostContext* context, | 62 ChromotingHostContext* context, |
36 SignalStrategy* signal_strategy, | 63 SignalStrategy* signal_strategy, |
37 DesktopEnvironment* environment, | 64 DesktopEnvironment* environment, |
38 const protocol::NetworkSettings& network_settings) | 65 const protocol::NetworkSettings& network_settings) |
39 : context_(context), | 66 : context_(context), |
40 desktop_environment_(environment), | 67 desktop_environment_(environment), |
41 network_settings_(network_settings), | 68 network_settings_(network_settings), |
42 signal_strategy_(signal_strategy), | 69 signal_strategy_(signal_strategy), |
43 stopping_recorders_(0), | 70 stopping_recorders_(0), |
44 state_(kInitial), | 71 state_(kInitial), |
45 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), | 72 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), |
73 login_backoff_(&kDefaultBackoffPolicy), | |
46 authenticating_client_(false), | 74 authenticating_client_(false), |
47 reject_authenticating_client_(false) { | 75 reject_authenticating_client_(false) { |
48 DCHECK(context_); | 76 DCHECK(context_); |
49 DCHECK(signal_strategy); | 77 DCHECK(signal_strategy); |
50 DCHECK(desktop_environment_); | 78 DCHECK(desktop_environment_); |
51 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 79 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
52 desktop_environment_->set_host(this); | 80 desktop_environment_->set_host(this); |
53 } | 81 } |
54 | 82 |
55 ChromotingHost::~ChromotingHost() { | 83 ChromotingHost::~ChromotingHost() { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 scoped_ptr<protocol::AuthenticatorFactory> authenticator_factory) { | 158 scoped_ptr<protocol::AuthenticatorFactory> authenticator_factory) { |
131 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 159 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
132 session_manager_->set_authenticator_factory(authenticator_factory.Pass()); | 160 session_manager_->set_authenticator_factory(authenticator_factory.Pass()); |
133 } | 161 } |
134 | 162 |
135 //////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////// |
136 // protocol::ClientSession::EventHandler implementation. | 164 // protocol::ClientSession::EventHandler implementation. |
137 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { | 165 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { |
138 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 166 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
139 | 167 |
140 // TODO(sergeyu): Update BackoffEntry here. | 168 login_backoff_.Reset(); |
141 } | 169 } |
142 | 170 |
143 void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { | 171 void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { |
144 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 172 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
145 | 173 |
146 // Disconnect all other clients. | 174 // Disconnect all other clients. |
147 // Iterate over a copy of the list of clients, to avoid mutating the list | 175 // Iterate over a copy of the list of clients, to avoid mutating the list |
148 // while iterating over it. | 176 // while iterating over it. |
149 ClientList clients_copy(clients_); | 177 ClientList clients_copy(clients_); |
150 for (ClientList::const_iterator other_client = clients_copy.begin(); | 178 for (ClientList::const_iterator other_client = clients_copy.begin(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 void ChromotingHost::OnIncomingSession( | 272 void ChromotingHost::OnIncomingSession( |
245 protocol::Session* session, | 273 protocol::Session* session, |
246 protocol::SessionManager::IncomingSessionResponse* response) { | 274 protocol::SessionManager::IncomingSessionResponse* response) { |
247 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 275 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
248 | 276 |
249 if (state_ != kStarted) { | 277 if (state_ != kStarted) { |
250 *response = protocol::SessionManager::DECLINE; | 278 *response = protocol::SessionManager::DECLINE; |
251 return; | 279 return; |
252 } | 280 } |
253 | 281 |
282 if (login_backoff_.ShouldRejectRequest()) { | |
283 *response = protocol::SessionManager::DISABLED; | |
284 return; | |
285 } | |
286 | |
287 // Backoff incoming connections until the new connection is | |
288 // authenticated. Is is neccessary to prevent the attack when | |
289 // multiple connections are initiated at the same time and all of | |
290 // them try to authenticate simultaneously. | |
Wez
2012/03/27 16:23:56
nit: Suggest rewording:
"We treat each incoming co
Sergey Ulanov
2012/03/27 18:00:52
Done.
| |
291 login_backoff_.InformOfRequest(false); | |
292 | |
254 protocol::SessionConfig config; | 293 protocol::SessionConfig config; |
255 if (!protocol_config_->Select(session->candidate_config(), &config)) { | 294 if (!protocol_config_->Select(session->candidate_config(), &config)) { |
256 LOG(WARNING) << "Rejecting connection from " << session->jid() | 295 LOG(WARNING) << "Rejecting connection from " << session->jid() |
257 << " because no compatible configuration has been found."; | 296 << " because no compatible configuration has been found."; |
258 *response = protocol::SessionManager::INCOMPATIBLE; | 297 *response = protocol::SessionManager::INCOMPATIBLE; |
259 return; | 298 return; |
260 } | 299 } |
261 | 300 |
262 session->set_config(config); | 301 session->set_config(config); |
263 | 302 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 OnShutdown()); | 409 OnShutdown()); |
371 | 410 |
372 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 411 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
373 it != shutdown_tasks_.end(); ++it) { | 412 it != shutdown_tasks_.end(); ++it) { |
374 it->Run(); | 413 it->Run(); |
375 } | 414 } |
376 shutdown_tasks_.clear(); | 415 shutdown_tasks_.clear(); |
377 } | 416 } |
378 | 417 |
379 } // namespace remoting | 418 } // namespace remoting |
OLD | NEW |