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

Side by Side Diff: chromeos/network/network_connection_handler.cc

Issue 16512003: Configure networks requiring a certificate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/network/network_connection_handler.h" 5 #include "chromeos/network/network_connection_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "chromeos/chromeos_switches.h" 10 #include "chromeos/chromeos_switches.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 bool passphrase_required = false; 93 bool passphrase_required = false;
94 properties->GetBooleanWithoutPathExpansion( 94 properties->GetBooleanWithoutPathExpansion(
95 flimflam::kPassphraseRequiredProperty, &passphrase_required); 95 flimflam::kPassphraseRequiredProperty, &passphrase_required);
96 std::string passphrase; 96 std::string passphrase;
97 properties->GetStringWithoutPathExpansion( 97 properties->GetStringWithoutPathExpansion(
98 flimflam::kOpenVPNPasswordProperty, &passphrase); 98 flimflam::kOpenVPNPasswordProperty, &passphrase);
99 if (passphrase_required && passphrase.empty()) { 99 if (passphrase_required && passphrase.empty()) {
100 NET_LOG_EVENT("OpenVPN: No passphrase", service_path); 100 NET_LOG_EVENT("OpenVPN: No passphrase", service_path);
101 return false; 101 return false;
102 } 102 }
103 std::string client_cert_id;
104 properties->GetStringWithoutPathExpansion(
105 flimflam::kOpenVPNClientCertIdProperty, &client_cert_id);
106 if (client_cert_id.empty()) {
107 NET_LOG_EVENT("OpenVPN: No cert id", service_path);
108 return false;
109 }
110 NET_LOG_EVENT("OpenVPN Is Configured", service_path); 103 NET_LOG_EVENT("OpenVPN Is Configured", service_path);
111 } else { 104 } else {
112 bool passphrase_required = false; 105 bool passphrase_required = false;
113 std::string passphrase; 106 std::string passphrase;
114 properties->GetBooleanWithoutPathExpansion( 107 properties->GetBooleanWithoutPathExpansion(
115 flimflam::kL2tpIpsecPskRequiredProperty, &passphrase_required); 108 flimflam::kL2tpIpsecPskRequiredProperty, &passphrase_required);
116 properties->GetStringWithoutPathExpansion( 109 properties->GetStringWithoutPathExpansion(
117 flimflam::kL2tpIpsecPskProperty, &passphrase); 110 flimflam::kL2tpIpsecPskProperty, &passphrase);
118 if (passphrase_required && passphrase.empty()) 111 if (passphrase_required && passphrase.empty())
119 return false; 112 return false;
120 NET_LOG_EVENT("VPN Is Configured", service_path); 113 NET_LOG_EVENT("VPN Is Configured", service_path);
121 } 114 }
122 return true; 115 return true;
123 } 116 }
124 117
125 bool CertificateIsConfigured(NetworkUIData* ui_data) {
126 if (ui_data->certificate_type() != CLIENT_CERT_TYPE_PATTERN)
127 return true; // No certificate or a reference.
128 if (ui_data->onc_source() == onc::ONC_SOURCE_DEVICE_POLICY) {
129 // We skip checking certificate patterns for device policy ONC so that an
130 // unmanaged user can't get to the place where a cert is presented for them
131 // involuntarily.
132 return true;
133 }
134 if (ui_data->certificate_pattern().Empty())
135 return false;
136
137 // Find the matching certificate.
138 scoped_refptr<net::X509Certificate> matching_cert =
139 certificate_pattern::GetCertificateMatch(
140 ui_data->certificate_pattern());
141 if (!matching_cert.get())
142 return false;
143 return true;
144 }
145
146 } // namespace 118 } // namespace
147 119
148 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; 120 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found";
149 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; 121 const char NetworkConnectionHandler::kErrorConnected[] = "connected";
150 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; 122 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting";
151 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; 123 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected";
152 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = 124 const char NetworkConnectionHandler::kErrorPassphraseRequired[] =
153 "passphrase-required"; 125 "passphrase-required";
154 const char NetworkConnectionHandler::kErrorActivationRequired[] = 126 const char NetworkConnectionHandler::kErrorActivationRequired[] =
155 "activation-required"; 127 "activation-required";
156 const char NetworkConnectionHandler::kErrorCertificateRequired[] = 128 const char NetworkConnectionHandler::kErrorCertificateRequired[] =
157 "certificate-required"; 129 "certificate-required";
158 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = 130 const char NetworkConnectionHandler::kErrorConfigurationRequired[] =
159 "configuration-required"; 131 "configuration-required";
160 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; 132 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error";
161 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; 133 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed";
162 const char NetworkConnectionHandler::kErrorUnknown[] = "unknown-error"; 134 const char NetworkConnectionHandler::kErrorUnknown[] = "unknown-error";
163 135
164 struct NetworkConnectionHandler::ConnectRequest { 136 struct NetworkConnectionHandler::ConnectRequest {
165 ConnectRequest(const base::Closure& success, 137 ConnectRequest(const std::string& service_path,
138 const base::Closure& success,
166 const network_handler::ErrorCallback& error) 139 const network_handler::ErrorCallback& error)
167 : connect_state(CONNECT_REQUESTED), 140 : service_path(service_path),
141 connect_state(CONNECT_REQUESTED),
168 success_callback(success), 142 success_callback(success),
169 error_callback(error) { 143 error_callback(error) {
170 } 144 }
171 enum ConnectState { 145 enum ConnectState {
172 CONNECT_REQUESTED = 0, 146 CONNECT_REQUESTED = 0,
173 CONNECT_STARTED = 1, 147 CONNECT_STARTED = 1,
174 CONNECT_CONNECTING = 2 148 CONNECT_CONNECTING = 2
175 }; 149 };
150 std::string service_path;
176 ConnectState connect_state; 151 ConnectState connect_state;
177 base::Closure success_callback; 152 base::Closure success_callback;
178 network_handler::ErrorCallback error_callback; 153 network_handler::ErrorCallback error_callback;
179 }; 154 };
180 155
181 NetworkConnectionHandler::NetworkConnectionHandler() 156 NetworkConnectionHandler::NetworkConnectionHandler()
182 : network_state_handler_(NULL), 157 : cert_loader_(NULL),
183 network_configuration_handler_(NULL) { 158 network_state_handler_(NULL),
184 const char* new_handler_enabled = 159 network_configuration_handler_(NULL),
185 CommandLine::ForCurrentProcess()->HasSwitch( 160 logged_in_(false),
186 chromeos::switches::kUseNewNetworkConnectionHandler) ? 161 certificates_loaded_(false) {
187 "enabled" : "disabled";
188 NET_LOG_EVENT("NewNetworkConnectionHandler", new_handler_enabled);
189 } 162 }
190 163
191 NetworkConnectionHandler::~NetworkConnectionHandler() { 164 NetworkConnectionHandler::~NetworkConnectionHandler() {
192 if (network_state_handler_) 165 if (network_state_handler_)
193 network_state_handler_->RemoveObserver(this); 166 network_state_handler_->RemoveObserver(this);
167 if (cert_loader_)
168 cert_loader_->RemoveObserver(this);
169 if (LoginState::IsInitialized())
170 LoginState::Get()->RemoveObserver(this);
194 } 171 }
195 172
196 void NetworkConnectionHandler::Init( 173 void NetworkConnectionHandler::Init(
174 CertLoader* cert_loader,
197 NetworkStateHandler* network_state_handler, 175 NetworkStateHandler* network_state_handler,
198 NetworkConfigurationHandler* network_configuration_handler) { 176 NetworkConfigurationHandler* network_configuration_handler) {
177 LoginState::Get()->AddObserver(this);
178 logged_in_ =
179 LoginState::Get()->GetLoggedInState() == LoginState::LOGGED_IN_ACTIVE;
180 if (cert_loader) {
181 cert_loader_ = cert_loader;
182 cert_loader_->AddObserver(this);
183 certificates_loaded_ = cert_loader->certificates_loaded();
184 } else {
185 certificates_loaded_ = true;
186 }
199 if (network_state_handler) { 187 if (network_state_handler) {
200 network_state_handler_ = network_state_handler; 188 network_state_handler_ = network_state_handler;
201 network_state_handler_->AddObserver(this); 189 network_state_handler_->AddObserver(this);
202 } 190 }
203 network_configuration_handler_ = network_configuration_handler; 191 network_configuration_handler_ = network_configuration_handler;
204 } 192 }
205 193
194 void NetworkConnectionHandler::LoggedInStateChanged(
195 LoginState::LoggedInState state) {
196 NET_LOG_EVENT("NewNetworkConnectionHandler",
197 CommandLine::ForCurrentProcess()->HasSwitch(
198 chromeos::switches::kUseNewNetworkConnectionHandler) ?
199 "enabled" : "disabled");
200 if (state == LoginState::LOGGED_IN_ACTIVE) {
201 logged_in_ = true;
202 NET_LOG_EVENT("Logged In", "");
203 }
204 }
205
206 void NetworkConnectionHandler::OnCertificatesLoaded(
207 const net::CertificateList& cert_list,
208 bool initial_load) {
209 certificates_loaded_ = true;
210 NET_LOG_EVENT("Certificates Loaded", "");
211 if (queued_connect_) {
212 NET_LOG_EVENT("Connecting to Queued Network",
213 queued_connect_->service_path);
214 ConnectToNetwork(queued_connect_->service_path,
215 queued_connect_->success_callback,
216 queued_connect_->error_callback,
217 true /* ignore_error_state */);
218 } else if (initial_load) {
219 // Once certificates have loaded, connect to the "best" available network.
220 NetworkHandler::Get()->network_state_handler()->ConnectToBestWifiNetwork();
221 }
222 }
223
206 void NetworkConnectionHandler::ConnectToNetwork( 224 void NetworkConnectionHandler::ConnectToNetwork(
207 const std::string& service_path, 225 const std::string& service_path,
208 const base::Closure& success_callback, 226 const base::Closure& success_callback,
209 const network_handler::ErrorCallback& error_callback, 227 const network_handler::ErrorCallback& error_callback,
210 bool ignore_error_state) { 228 bool ignore_error_state) {
211 NET_LOG_USER("ConnectToNetwork", service_path); 229 NET_LOG_USER("ConnectToNetwork", service_path);
230 // Clear any existing queued connect request.
231 queued_connect_.reset();
212 const NetworkState* network = 232 const NetworkState* network =
213 network_state_handler_->GetNetworkState(service_path); 233 network_state_handler_->GetNetworkState(service_path);
214 if (!network) { 234 if (!network) {
215 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); 235 InvokeErrorCallback(service_path, error_callback, kErrorNotFound);
216 return; 236 return;
217 } 237 }
218 if (HasConnectingNetwork(service_path)) { 238 if (HasConnectingNetwork(service_path)) {
219 NET_LOG_USER("Connect Request While Pending", service_path); 239 NET_LOG_USER("Connect Request While Pending", service_path);
220 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); 240 InvokeErrorCallback(service_path, error_callback, kErrorConnecting);
221 return; 241 return;
(...skipping 28 matching lines...) Expand all
250 } 270 }
251 if (network->HasAuthenticationError()) { 271 if (network->HasAuthenticationError()) {
252 InvokeErrorCallback(service_path, error_callback, 272 InvokeErrorCallback(service_path, error_callback,
253 kErrorConfigurationRequired); 273 kErrorConfigurationRequired);
254 return; 274 return;
255 } 275 }
256 } 276 }
257 277
258 // All synchronous checks passed, add |service_path| to connecting list. 278 // All synchronous checks passed, add |service_path| to connecting list.
259 pending_requests_.insert(std::make_pair( 279 pending_requests_.insert(std::make_pair(
260 service_path, ConnectRequest(success_callback, error_callback))); 280 service_path,
281 ConnectRequest(service_path, success_callback, error_callback)));
261 282
262 if (!NetworkConnectable(network) && NetworkMayNeedCredentials(network)) { 283 if (!NetworkConnectable(network) &&
284 NetworkMayNeedCredentials(network)) {
263 // Request additional properties to check. 285 // Request additional properties to check.
264 network_configuration_handler_->GetProperties( 286 network_configuration_handler_->GetProperties(
265 network->path(), 287 network->path(),
266 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, 288 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect,
267 AsWeakPtr()), 289 AsWeakPtr()),
268 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, 290 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure,
269 AsWeakPtr(), network->path())); 291 AsWeakPtr(), network->path()));
270 return; 292 return;
271 } 293 }
272 // All checks passed, send connect request. 294 // All checks passed, send connect request.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 pending_requests_.find(service_path); 335 pending_requests_.find(service_path);
314 return iter != pending_requests_.end() ? &(iter->second) : NULL; 336 return iter != pending_requests_.end() ? &(iter->second) : NULL;
315 } 337 }
316 338
317 // ConnectToNetwork implementation 339 // ConnectToNetwork implementation
318 340
319 void NetworkConnectionHandler::VerifyConfiguredAndConnect( 341 void NetworkConnectionHandler::VerifyConfiguredAndConnect(
320 const std::string& service_path, 342 const std::string& service_path,
321 const base::DictionaryValue& properties) { 343 const base::DictionaryValue& properties) {
322 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); 344 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path);
323 ConnectRequest* request = pending_request(service_path);
324 DCHECK(request);
325 network_handler::ErrorCallback error_callback = request->error_callback;
326 345
327 const NetworkState* network = 346 const NetworkState* network =
328 network_state_handler_->GetNetworkState(service_path); 347 network_state_handler_->GetNetworkState(service_path);
329 if (!network) { 348 if (!network) {
330 pending_requests_.erase(service_path); 349 ErrorCallbackForPendingRequest(service_path, kErrorNotFound);
331 InvokeErrorCallback(service_path, error_callback, kErrorNotFound);
332 return; 350 return;
333 } 351 }
334 352
335 // VPN requires a host and username to be set. 353 // VPN requires a host and username to be set.
336 if (network->type() == flimflam::kTypeVPN && 354 if (network->type() == flimflam::kTypeVPN &&
337 !VPNIsConfigured(service_path, properties)) { 355 !VPNIsConfigured(service_path, properties)) {
338 pending_requests_.erase(service_path); 356 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired);
339 InvokeErrorCallback(service_path, error_callback,
340 kErrorConfigurationRequired);
341 return; 357 return;
342 } 358 }
343 359
344 // Check certificate properties in kUIDataProperty. 360 // Check certificate properties in kUIDataProperty.
345 scoped_ptr<NetworkUIData> ui_data = 361 scoped_ptr<NetworkUIData> ui_data =
346 ManagedNetworkConfigurationHandler::GetUIData(properties); 362 ManagedNetworkConfigurationHandler::GetUIData(properties);
347 if (ui_data && !CertificateIsConfigured(ui_data.get())) { 363 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) {
348 pending_requests_.erase(service_path); 364 // User must be logged in to connect to a network requiring a certificate.
349 InvokeErrorCallback(service_path, error_callback, 365 if (!logged_in_ || !cert_loader_) {
350 kErrorCertificateRequired); 366 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired);
351 return; 367 return;
368 }
369 // If certificates have not been loaded yet, queue the connect request.
370 if (!certificates_loaded_) {
371 ConnectRequest* request = pending_request(service_path);
372 DCHECK(request);
373 NET_LOG_EVENT("Connect Request Queued", service_path);
374 queued_connect_.reset(new ConnectRequest(
375 service_path, request->success_callback, request->error_callback));
376 pending_requests_.erase(service_path);
377 return;
378 }
379
380 // Ensure the certificate is available.
381 std::string pkcs11_id;
382 if (!CertificateIsConfigured(ui_data.get(), &pkcs11_id)) {
383 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired);
384 return;
385 }
386
387 // The network may not be 'Connectable' because the certificate data is
388 // not set up, so configure tpm slot/pin and pkcs11_id before connecting.
389 // TODO(stevenjb): Remove this code once NetworkConfigurationHandler
Greg Spencer (Chromium) 2013/06/06 01:11:46 So, why can't you just move it there now? What's
390 // handles this.
391 NET_LOG_EVENT("Configuring Network", service_path);
392 const std::string& tpm_slot = cert_loader_->tpm_token_slot();
393 const std::string& tpm_pin = cert_loader_->tpm_user_pin();
394 base::DictionaryValue config_properties;
395 network->GetConfigProperties(&config_properties);
396
397 if (network->type() == flimflam::kTypeVPN) {
398 std::string provider_type;
399 properties.GetString(flimflam::kTypeProperty, &provider_type);
400 if (provider_type == flimflam::kProviderOpenVpn) {
401 config_properties.SetStringWithoutPathExpansion(
402 flimflam::kOpenVPNClientCertSlotProperty, tpm_slot);
403 config_properties.SetStringWithoutPathExpansion(
404 flimflam::kOpenVPNPinProperty, tpm_pin);
405 config_properties.SetStringWithoutPathExpansion(
406 flimflam::kOpenVPNClientCertIdProperty, pkcs11_id);
407 } else {
408 config_properties.SetStringWithoutPathExpansion(
409 flimflam::kL2tpIpsecClientCertSlotProperty, tpm_slot);
410 config_properties.SetStringWithoutPathExpansion(
411 flimflam::kL2tpIpsecPinProperty, tpm_pin);
412 config_properties.SetStringWithoutPathExpansion(
413 flimflam::kL2tpIpsecClientCertIdProperty, pkcs11_id);
414 }
415 } else if (network->type() == flimflam::kTypeWifi) {
416 config_properties.SetStringWithoutPathExpansion(
417 flimflam::kEapPinProperty, cert_loader_->tpm_user_pin());
418 config_properties.SetStringWithoutPathExpansion(
419 flimflam::kEapCertIdProperty, pkcs11_id);
420 config_properties.SetStringWithoutPathExpansion(
421 flimflam::kEapKeyIdProperty, pkcs11_id);
422 }
423 network_configuration_handler_->SetProperties(
424 service_path,
425 config_properties,
426 base::Bind(&NetworkConnectionHandler::CallShillConnect,
427 AsWeakPtr(), service_path),
428 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure,
429 AsWeakPtr(), service_path));
430 return;
352 } 431 }
353 432
354 CallShillConnect(service_path); 433 // Otherwise, we need to configure the network.
434 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired);
355 } 435 }
356 436
357 void NetworkConnectionHandler::CallShillConnect( 437 void NetworkConnectionHandler::CallShillConnect(
358 const std::string& service_path) { 438 const std::string& service_path) {
359 NET_LOG_EVENT("Connect Request", service_path); 439 NET_LOG_EVENT("Sending Connect Request to Shill", service_path);
360 DBusThreadManager::Get()->GetShillServiceClient()->Connect( 440 DBusThreadManager::Get()->GetShillServiceClient()->Connect(
361 dbus::ObjectPath(service_path), 441 dbus::ObjectPath(service_path),
362 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess, 442 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess,
363 AsWeakPtr(), service_path), 443 AsWeakPtr(), service_path),
364 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, 444 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure,
365 AsWeakPtr(), service_path)); 445 AsWeakPtr(), service_path));
366 } 446 }
367 447
368 void NetworkConnectionHandler::HandleConfigurationFailure( 448 void NetworkConnectionHandler::HandleConfigurationFailure(
369 const std::string& service_path, 449 const std::string& service_path,
370 const std::string& error_name, 450 const std::string& error_name,
371 scoped_ptr<base::DictionaryValue> error_data) { 451 scoped_ptr<base::DictionaryValue> error_data) {
372 ConnectRequest* request = pending_request(service_path); 452 ConnectRequest* request = pending_request(service_path);
373 DCHECK(request); 453 DCHECK(request);
374 network_handler::ErrorCallback error_callback = request->error_callback; 454 network_handler::ErrorCallback error_callback = request->error_callback;
375 pending_requests_.erase(service_path); 455 pending_requests_.erase(service_path);
376 if (!error_callback.is_null()) 456 if (!error_callback.is_null())
377 error_callback.Run(error_name, error_data.Pass()); 457 error_callback.Run(error_name, error_data.Pass());
378 } 458 }
379 459
380 void NetworkConnectionHandler::HandleShillConnectSuccess( 460 void NetworkConnectionHandler::HandleShillConnectSuccess(
381 const std::string& service_path) { 461 const std::string& service_path) {
382 ConnectRequest* request = pending_request(service_path); 462 ConnectRequest* request = pending_request(service_path);
383 DCHECK(request); 463 DCHECK(request);
384 request->connect_state = ConnectRequest::CONNECT_STARTED; 464 request->connect_state = ConnectRequest::CONNECT_STARTED;
385 NET_LOG_EVENT("Connect Request Sent", service_path); 465 NET_LOG_EVENT("Connect Request Acknowledged", service_path);
386 // Do not call success_callback here, wait for one of the following 466 // Do not call success_callback here, wait for one of the following
387 // conditions: 467 // conditions:
388 // * State transitions to a non connecting state indicating succes or failure 468 // * State transitions to a non connecting state indicating succes or failure
389 // * Network is no longer in the visible list, indicating failure 469 // * Network is no longer in the visible list, indicating failure
390 CheckPendingRequest(service_path); 470 CheckPendingRequest(service_path);
391 } 471 }
392 472
393 void NetworkConnectionHandler::HandleShillConnectFailure( 473 void NetworkConnectionHandler::HandleShillConnectFailure(
394 const std::string& service_path, 474 const std::string& service_path,
395 const std::string& error_name, 475 const std::string& error_name,
396 const std::string& error_message) { 476 const std::string& error_message) {
397 ConnectRequest* request = pending_request(service_path); 477 ConnectRequest* request = pending_request(service_path);
398 DCHECK(request); 478 DCHECK(request);
399 network_handler::ErrorCallback error_callback = request->error_callback; 479 network_handler::ErrorCallback error_callback = request->error_callback;
400 pending_requests_.erase(service_path); 480 pending_requests_.erase(service_path);
401 std::string error = "Connect Failure: " + error_name + ": " + error_message; 481 std::string error = "Connect Failure: " + error_name + ": " + error_message;
402 network_handler::ShillErrorCallbackFunction( 482 network_handler::ShillErrorCallbackFunction(
403 service_path, error_callback, error_name, error_message); 483 service_path, error_callback, error_name, error_message);
404 } 484 }
405 485
406 void NetworkConnectionHandler::CheckPendingRequest( 486 void NetworkConnectionHandler::CheckPendingRequest(
407 const std::string service_path) { 487 const std::string service_path) {
408 ConnectRequest* request = pending_request(service_path); 488 ConnectRequest* request = pending_request(service_path);
409 DCHECK(request); 489 DCHECK(request);
410 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) 490 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED)
411 return; // Request has not started, ignore update 491 return; // Request has not started, ignore update
412 const NetworkState* network = 492 const NetworkState* network =
413 network_state_handler_->GetNetworkState(service_path); 493 network_state_handler_->GetNetworkState(service_path);
414 if (!network) { 494 if (!network) {
415 network_handler::ErrorCallback error_callback = request->error_callback; 495 ErrorCallbackForPendingRequest(service_path, kErrorNotFound);
416 pending_requests_.erase(service_path);
417 InvokeErrorCallback(service_path, error_callback, kErrorNotFound);
418 return; 496 return;
419 } 497 }
420 if (network->IsConnectingState()) { 498 if (network->IsConnectingState()) {
421 request->connect_state = ConnectRequest::CONNECT_CONNECTING; 499 request->connect_state = ConnectRequest::CONNECT_CONNECTING;
422 return; 500 return;
423 } 501 }
424 if (network->IsConnectedState()) { 502 if (network->IsConnectedState()) {
425 NET_LOG_EVENT("Connect Request Succeeded", service_path); 503 NET_LOG_EVENT("Connect Request Succeeded", service_path);
426 if (!request->success_callback.is_null()) 504 if (!request->success_callback.is_null())
427 request->success_callback.Run(); 505 request->success_callback.Run();
(...skipping 27 matching lines...) Expand all
455 error_callback.Run(error_name, error_data.Pass()); 533 error_callback.Run(error_name, error_data.Pass());
456 } 534 }
457 535
458 void NetworkConnectionHandler::CheckAllPendingRequests() { 536 void NetworkConnectionHandler::CheckAllPendingRequests() {
459 for (std::map<std::string, ConnectRequest>::iterator iter = 537 for (std::map<std::string, ConnectRequest>::iterator iter =
460 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { 538 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) {
461 CheckPendingRequest(iter->first); 539 CheckPendingRequest(iter->first);
462 } 540 }
463 } 541 }
464 542
543 bool NetworkConnectionHandler::CertificateIsConfigured(NetworkUIData* ui_data,
544 std::string* pkcs11_id) {
545 if (ui_data->onc_source() == onc::ONC_SOURCE_DEVICE_POLICY) {
546 // We skip checking certificate patterns for device policy ONC so that an
547 // unmanaged user can't get to the place where a cert is presented for them
548 // involuntarily.
549 return true;
550 }
551 if (ui_data->certificate_pattern().Empty())
552 return false;
553
554 // Find the matching certificate.
555 scoped_refptr<net::X509Certificate> matching_cert =
556 certificate_pattern::GetCertificateMatch(ui_data->certificate_pattern());
557 if (!matching_cert.get())
558 return false;
559 *pkcs11_id = cert_loader_->GetPkcs11IdForCert(*matching_cert.get());
560 return true;
561 }
562
563 void NetworkConnectionHandler::ErrorCallbackForPendingRequest(
564 const std::string& service_path,
565 const std::string& error_name) {
566 ConnectRequest* request = pending_request(service_path);
567 DCHECK(request);
568 // Remove the entry before invoking the callback in case it triggers a retry.
569 network_handler::ErrorCallback error_callback = request->error_callback;
570 pending_requests_.erase(service_path);
571 InvokeErrorCallback(service_path, error_callback, error_name);
572 }
573
465 // Disconnect 574 // Disconnect
466 575
467 void NetworkConnectionHandler::CallShillDisconnect( 576 void NetworkConnectionHandler::CallShillDisconnect(
468 const std::string& service_path, 577 const std::string& service_path,
469 const base::Closure& success_callback, 578 const base::Closure& success_callback,
470 const network_handler::ErrorCallback& error_callback) { 579 const network_handler::ErrorCallback& error_callback) {
471 NET_LOG_USER("Disconnect Request", service_path); 580 NET_LOG_USER("Disconnect Request", service_path);
472 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( 581 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect(
473 dbus::ObjectPath(service_path), 582 dbus::ObjectPath(service_path),
474 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, 583 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess,
(...skipping 14 matching lines...) Expand all
489 const network_handler::ErrorCallback& error_callback, 598 const network_handler::ErrorCallback& error_callback,
490 const std::string& error_name, 599 const std::string& error_name,
491 const std::string& error_message) { 600 const std::string& error_message) {
492 std::string error = 601 std::string error =
493 "Disconnect Failure: " + error_name + ": " + error_message; 602 "Disconnect Failure: " + error_name + ": " + error_message;
494 network_handler::ShillErrorCallbackFunction( 603 network_handler::ShillErrorCallbackFunction(
495 service_path, error_callback, error_name, error_message); 604 service_path, error_callback, error_name, error_message);
496 } 605 }
497 606
498 } // namespace chromeos 607 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_connection_handler.h ('k') | chromeos/network/network_connection_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698