OLD | NEW |
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 22 matching lines...) Expand all Loading... |
33 std::string error_msg = "Connect Error: " + error_name; | 33 std::string error_msg = "Connect Error: " + error_name; |
34 NET_LOG_ERROR(error_msg, service_path); | 34 NET_LOG_ERROR(error_msg, service_path); |
35 if (error_callback.is_null()) | 35 if (error_callback.is_null()) |
36 return; | 36 return; |
37 scoped_ptr<base::DictionaryValue> error_data( | 37 scoped_ptr<base::DictionaryValue> error_data( |
38 network_handler::CreateErrorData(service_path, error_name, error_msg)); | 38 network_handler::CreateErrorData(service_path, error_name, error_msg)); |
39 error_callback.Run(error_name, error_data.Pass()); | 39 error_callback.Run(error_name, error_data.Pass()); |
40 } | 40 } |
41 | 41 |
42 bool IsAuthenticationError(const std::string& error) { | 42 bool IsAuthenticationError(const std::string& error) { |
43 return (error == flimflam::kErrorBadWEPKey || | 43 return (error == shill::kErrorBadWEPKey || |
44 error == flimflam::kErrorPppAuthFailed || | 44 error == shill::kErrorPppAuthFailed || |
45 error == shill::kErrorEapLocalTlsFailed || | 45 error == shill::kErrorEapLocalTlsFailed || |
46 error == shill::kErrorEapRemoteTlsFailed || | 46 error == shill::kErrorEapRemoteTlsFailed || |
47 error == shill::kErrorEapAuthenticationFailed); | 47 error == shill::kErrorEapAuthenticationFailed); |
48 } | 48 } |
49 | 49 |
50 bool VPNIsConfigured(const std::string& service_path, | 50 bool VPNIsConfigured(const std::string& service_path, |
51 const std::string& provider_type, | 51 const std::string& provider_type, |
52 const base::DictionaryValue& provider_properties) { | 52 const base::DictionaryValue& provider_properties) { |
53 if (provider_type == flimflam::kProviderOpenVpn) { | 53 if (provider_type == shill::kProviderOpenVpn) { |
54 std::string hostname; | 54 std::string hostname; |
55 provider_properties.GetStringWithoutPathExpansion( | 55 provider_properties.GetStringWithoutPathExpansion( |
56 flimflam::kHostProperty, &hostname); | 56 shill::kHostProperty, &hostname); |
57 if (hostname.empty()) { | 57 if (hostname.empty()) { |
58 NET_LOG_EVENT("OpenVPN: No hostname", service_path); | 58 NET_LOG_EVENT("OpenVPN: No hostname", service_path); |
59 return false; | 59 return false; |
60 } | 60 } |
61 std::string username; | 61 std::string username; |
62 provider_properties.GetStringWithoutPathExpansion( | 62 provider_properties.GetStringWithoutPathExpansion( |
63 flimflam::kOpenVPNUserProperty, &username); | 63 shill::kOpenVPNUserProperty, &username); |
64 if (username.empty()) { | 64 if (username.empty()) { |
65 NET_LOG_EVENT("OpenVPN: No username", service_path); | 65 NET_LOG_EVENT("OpenVPN: No username", service_path); |
66 return false; | 66 return false; |
67 } | 67 } |
68 bool passphrase_required = false; | 68 bool passphrase_required = false; |
69 provider_properties.GetBooleanWithoutPathExpansion( | 69 provider_properties.GetBooleanWithoutPathExpansion( |
70 flimflam::kPassphraseRequiredProperty, &passphrase_required); | 70 shill::kPassphraseRequiredProperty, &passphrase_required); |
71 if (passphrase_required) { | 71 if (passphrase_required) { |
72 NET_LOG_EVENT("OpenVPN: Passphrase Required", service_path); | 72 NET_LOG_EVENT("OpenVPN: Passphrase Required", service_path); |
73 return false; | 73 return false; |
74 } | 74 } |
75 NET_LOG_EVENT("OpenVPN Is Configured", service_path); | 75 NET_LOG_EVENT("OpenVPN Is Configured", service_path); |
76 } else { | 76 } else { |
77 bool passphrase_required = false; | 77 bool passphrase_required = false; |
78 std::string passphrase; | 78 std::string passphrase; |
79 provider_properties.GetBooleanWithoutPathExpansion( | 79 provider_properties.GetBooleanWithoutPathExpansion( |
80 flimflam::kL2tpIpsecPskRequiredProperty, &passphrase_required); | 80 shill::kL2tpIpsecPskRequiredProperty, &passphrase_required); |
81 if (passphrase_required) { | 81 if (passphrase_required) { |
82 NET_LOG_EVENT("VPN: PSK Required", service_path); | 82 NET_LOG_EVENT("VPN: PSK Required", service_path); |
83 return false; | 83 return false; |
84 } | 84 } |
85 NET_LOG_EVENT("VPN Is Configured", service_path); | 85 NET_LOG_EVENT("VPN Is Configured", service_path); |
86 } | 86 } |
87 return true; | 87 return true; |
88 } | 88 } |
89 | 89 |
90 } // namespace | 90 } // namespace |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 return; | 225 return; |
226 } | 226 } |
227 if (network->RequiresActivation()) { | 227 if (network->RequiresActivation()) { |
228 InvokeErrorCallback(service_path, error_callback, | 228 InvokeErrorCallback(service_path, error_callback, |
229 kErrorActivationRequired); | 229 kErrorActivationRequired); |
230 return; | 230 return; |
231 } | 231 } |
232 | 232 |
233 if (check_error_state) { | 233 if (check_error_state) { |
234 const std::string& error = network->error(); | 234 const std::string& error = network->error(); |
235 if (error == flimflam::kErrorBadPassphrase) { | 235 if (error == shill::kErrorBadPassphrase) { |
236 InvokeErrorCallback(service_path, error_callback, error); | 236 InvokeErrorCallback(service_path, error_callback, error); |
237 return; | 237 return; |
238 } | 238 } |
239 if (IsAuthenticationError(error)) { | 239 if (IsAuthenticationError(error)) { |
240 InvokeErrorCallback( | 240 InvokeErrorCallback( |
241 service_path, error_callback, kErrorAuthenticationRequired); | 241 service_path, error_callback, kErrorAuthenticationRequired); |
242 return; | 242 return; |
243 } | 243 } |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 // All synchronous checks passed, add |service_path| to connecting list. | 247 // All synchronous checks passed, add |service_path| to connecting list. |
248 pending_requests_.insert(std::make_pair( | 248 pending_requests_.insert(std::make_pair( |
249 service_path, | 249 service_path, |
250 ConnectRequest(service_path, success_callback, error_callback))); | 250 ConnectRequest(service_path, success_callback, error_callback))); |
251 | 251 |
252 // Connect immediately to 'connectable' networks. | 252 // Connect immediately to 'connectable' networks. |
253 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. | 253 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. |
254 if (network && | 254 if (network && network->connectable() && network->type() != shill::kTypeVPN) { |
255 network->connectable() && network->type() != flimflam::kTypeVPN) { | |
256 CallShillConnect(service_path); | 255 CallShillConnect(service_path); |
257 return; | 256 return; |
258 } | 257 } |
259 | 258 |
260 // Request additional properties to check. VerifyConfiguredAndConnect will | 259 // Request additional properties to check. VerifyConfiguredAndConnect will |
261 // use only these properties, not cached properties, to ensure that they | 260 // use only these properties, not cached properties, to ensure that they |
262 // are up to date after any recent configuration. | 261 // are up to date after any recent configuration. |
263 network_configuration_handler_->GetProperties( | 262 network_configuration_handler_->GetProperties( |
264 service_path, | 263 service_path, |
265 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, | 264 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 void NetworkConnectionHandler::VerifyConfiguredAndConnect( | 316 void NetworkConnectionHandler::VerifyConfiguredAndConnect( |
318 bool check_error_state, | 317 bool check_error_state, |
319 const std::string& service_path, | 318 const std::string& service_path, |
320 const base::DictionaryValue& service_properties) { | 319 const base::DictionaryValue& service_properties) { |
321 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); | 320 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); |
322 | 321 |
323 // If 'passphrase_required' is still true, then the 'Passphrase' property | 322 // If 'passphrase_required' is still true, then the 'Passphrase' property |
324 // has not been set to a minimum length value. | 323 // has not been set to a minimum length value. |
325 bool passphrase_required = false; | 324 bool passphrase_required = false; |
326 service_properties.GetBooleanWithoutPathExpansion( | 325 service_properties.GetBooleanWithoutPathExpansion( |
327 flimflam::kPassphraseRequiredProperty, &passphrase_required); | 326 shill::kPassphraseRequiredProperty, &passphrase_required); |
328 if (passphrase_required) { | 327 if (passphrase_required) { |
329 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); | 328 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); |
330 return; | 329 return; |
331 } | 330 } |
332 | 331 |
333 std::string type, security; | 332 std::string type, security; |
| 333 service_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); |
334 service_properties.GetStringWithoutPathExpansion( | 334 service_properties.GetStringWithoutPathExpansion( |
335 flimflam::kTypeProperty, &type); | 335 shill::kSecurityProperty, &security); |
336 service_properties.GetStringWithoutPathExpansion( | |
337 flimflam::kSecurityProperty, &security); | |
338 bool connectable = false; | 336 bool connectable = false; |
339 service_properties.GetBooleanWithoutPathExpansion( | 337 service_properties.GetBooleanWithoutPathExpansion( |
340 flimflam::kConnectableProperty, &connectable); | 338 shill::kConnectableProperty, &connectable); |
341 | 339 |
342 // In case NetworkState was not available in ConnectToNetwork (e.g. it had | 340 // In case NetworkState was not available in ConnectToNetwork (e.g. it had |
343 // been recently configured), we need to check Connectable again. | 341 // been recently configured), we need to check Connectable again. |
344 if (connectable && type != flimflam::kTypeVPN) { | 342 if (connectable && type != shill::kTypeVPN) { |
345 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. | 343 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. |
346 CallShillConnect(service_path); | 344 CallShillConnect(service_path); |
347 return; | 345 return; |
348 } | 346 } |
349 | 347 |
350 // Get VPN provider type and host (required for configuration) and ensure | 348 // Get VPN provider type and host (required for configuration) and ensure |
351 // that required VPN non-cert properties are set. | 349 // that required VPN non-cert properties are set. |
352 std::string vpn_provider_type, vpn_provider_host; | 350 std::string vpn_provider_type, vpn_provider_host; |
353 if (type == flimflam::kTypeVPN) { | 351 if (type == shill::kTypeVPN) { |
354 // VPN Provider values are read from the "Provider" dictionary, not the | 352 // VPN Provider values are read from the "Provider" dictionary, not the |
355 // "Provider.Type", etc keys (which are used only to set the values). | 353 // "Provider.Type", etc keys (which are used only to set the values). |
356 const base::DictionaryValue* provider_properties; | 354 const base::DictionaryValue* provider_properties; |
357 if (service_properties.GetDictionaryWithoutPathExpansion( | 355 if (service_properties.GetDictionaryWithoutPathExpansion( |
358 flimflam::kProviderProperty, &provider_properties)) { | 356 shill::kProviderProperty, &provider_properties)) { |
359 provider_properties->GetStringWithoutPathExpansion( | 357 provider_properties->GetStringWithoutPathExpansion( |
360 flimflam::kTypeProperty, &vpn_provider_type); | 358 shill::kTypeProperty, &vpn_provider_type); |
361 provider_properties->GetStringWithoutPathExpansion( | 359 provider_properties->GetStringWithoutPathExpansion( |
362 flimflam::kHostProperty, &vpn_provider_host); | 360 shill::kHostProperty, &vpn_provider_host); |
363 } | 361 } |
364 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { | 362 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { |
365 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 363 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
366 return; | 364 return; |
367 } | 365 } |
368 // VPN requires a host and username to be set. | 366 // VPN requires a host and username to be set. |
369 if (!VPNIsConfigured( | 367 if (!VPNIsConfigured( |
370 service_path, vpn_provider_type, *provider_properties)) { | 368 service_path, vpn_provider_type, *provider_properties)) { |
371 NET_LOG_ERROR("VPN Not Configured", service_path); | 369 NET_LOG_ERROR("VPN Not Configured", service_path); |
372 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 370 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
373 return; | 371 return; |
374 } | 372 } |
375 } | 373 } |
376 | 374 |
377 client_cert::ConfigType client_cert_type = client_cert::CONFIG_TYPE_NONE; | 375 client_cert::ConfigType client_cert_type = client_cert::CONFIG_TYPE_NONE; |
378 if (type == flimflam::kTypeVPN) { | 376 if (type == shill::kTypeVPN) { |
379 if (vpn_provider_type == flimflam::kProviderOpenVpn) | 377 if (vpn_provider_type == shill::kProviderOpenVpn) |
380 client_cert_type = client_cert::CONFIG_TYPE_OPENVPN; | 378 client_cert_type = client_cert::CONFIG_TYPE_OPENVPN; |
381 else | 379 else |
382 client_cert_type = client_cert::CONFIG_TYPE_IPSEC; | 380 client_cert_type = client_cert::CONFIG_TYPE_IPSEC; |
383 } else if (type == flimflam::kTypeWifi && | 381 } else if (type == shill::kTypeWifi && security == shill::kSecurity8021x) { |
384 security == flimflam::kSecurity8021x) { | |
385 client_cert_type = client_cert::CONFIG_TYPE_EAP; | 382 client_cert_type = client_cert::CONFIG_TYPE_EAP; |
386 } | 383 } |
387 | 384 |
388 base::DictionaryValue config_properties; | 385 base::DictionaryValue config_properties; |
389 if (client_cert_type != client_cert::CONFIG_TYPE_NONE) { | 386 if (client_cert_type != client_cert::CONFIG_TYPE_NONE) { |
390 // If the client certificate must be configured, this will be set to a | 387 // If the client certificate must be configured, this will be set to a |
391 // non-empty string. | 388 // non-empty string. |
392 std::string pkcs11_id; | 389 std::string pkcs11_id; |
393 | 390 |
394 // Check certificate properties in kUIDataProperty if configured. | 391 // Check certificate properties in kUIDataProperty if configured. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 const std::string& dbus_error_message) { | 515 const std::string& dbus_error_message) { |
519 ConnectRequest* request = GetPendingRequest(service_path); | 516 ConnectRequest* request = GetPendingRequest(service_path); |
520 if (!request) { | 517 if (!request) { |
521 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", | 518 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", |
522 service_path); | 519 service_path); |
523 return; | 520 return; |
524 } | 521 } |
525 network_handler::ErrorCallback error_callback = request->error_callback; | 522 network_handler::ErrorCallback error_callback = request->error_callback; |
526 pending_requests_.erase(service_path); | 523 pending_requests_.erase(service_path); |
527 network_handler::ShillErrorCallbackFunction( | 524 network_handler::ShillErrorCallbackFunction( |
528 flimflam::kErrorConnectFailed, service_path, error_callback, | 525 shill::kErrorConnectFailed, service_path, error_callback, |
529 dbus_error_name, dbus_error_message); | 526 dbus_error_name, dbus_error_message); |
530 } | 527 } |
531 | 528 |
532 void NetworkConnectionHandler::CheckPendingRequest( | 529 void NetworkConnectionHandler::CheckPendingRequest( |
533 const std::string service_path) { | 530 const std::string service_path) { |
534 ConnectRequest* request = GetPendingRequest(service_path); | 531 ConnectRequest* request = GetPendingRequest(service_path); |
535 DCHECK(request); | 532 DCHECK(request); |
536 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) | 533 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) |
537 return; // Request has not started, ignore update | 534 return; // Request has not started, ignore update |
538 const NetworkState* network = | 535 const NetworkState* network = |
539 network_state_handler_->GetNetworkState(service_path); | 536 network_state_handler_->GetNetworkState(service_path); |
540 if (!network) | 537 if (!network) |
541 return; // NetworkState may not be be updated yet. | 538 return; // NetworkState may not be be updated yet. |
542 | 539 |
543 if (network->IsConnectingState()) { | 540 if (network->IsConnectingState()) { |
544 request->connect_state = ConnectRequest::CONNECT_CONNECTING; | 541 request->connect_state = ConnectRequest::CONNECT_CONNECTING; |
545 return; | 542 return; |
546 } | 543 } |
547 if (network->IsConnectedState()) { | 544 if (network->IsConnectedState()) { |
548 NET_LOG_EVENT("Connect Request Succeeded", service_path); | 545 NET_LOG_EVENT("Connect Request Succeeded", service_path); |
549 if (!request->success_callback.is_null()) | 546 if (!request->success_callback.is_null()) |
550 request->success_callback.Run(); | 547 request->success_callback.Run(); |
551 pending_requests_.erase(service_path); | 548 pending_requests_.erase(service_path); |
552 return; | 549 return; |
553 } | 550 } |
554 if (network->connection_state() == flimflam::kStateIdle && | 551 if (network->connection_state() == shill::kStateIdle && |
555 request->connect_state != ConnectRequest::CONNECT_CONNECTING) { | 552 request->connect_state != ConnectRequest::CONNECT_CONNECTING) { |
556 // Connection hasn't started yet, keep waiting. | 553 // Connection hasn't started yet, keep waiting. |
557 return; | 554 return; |
558 } | 555 } |
559 | 556 |
560 // Network is neither connecting or connected; an error occurred. | 557 // Network is neither connecting or connected; an error occurred. |
561 std::string error_name, error_detail; | 558 std::string error_name, error_detail; |
562 if (network->connection_state() == flimflam::kStateIdle && | 559 if (network->connection_state() == shill::kStateIdle && |
563 pending_requests_.size() > 1) { | 560 pending_requests_.size() > 1) { |
564 // Another connect request canceled this one. | 561 // Another connect request canceled this one. |
565 error_name = kErrorConnectCanceled; | 562 error_name = kErrorConnectCanceled; |
566 error_detail = ""; | 563 error_detail = ""; |
567 } else { | 564 } else { |
568 error_name = flimflam::kErrorConnectFailed; | 565 error_name = shill::kErrorConnectFailed; |
569 error_detail = network->error(); | 566 error_detail = network->error(); |
570 if (error_detail.empty()) { | 567 if (error_detail.empty()) { |
571 if (network->connection_state() == flimflam::kStateFailure) | 568 if (network->connection_state() == shill::kStateFailure) |
572 error_detail = flimflam::kUnknownString; | 569 error_detail = shill::kUnknownString; |
573 else | 570 else |
574 error_detail = "Unexpected State: " + network->connection_state(); | 571 error_detail = "Unexpected State: " + network->connection_state(); |
575 } | 572 } |
576 } | 573 } |
577 std::string error_msg = error_name + ": " + error_detail; | 574 std::string error_msg = error_name + ": " + error_detail; |
578 NET_LOG_ERROR(error_msg, service_path); | 575 NET_LOG_ERROR(error_msg, service_path); |
579 | 576 |
580 network_handler::ErrorCallback error_callback = request->error_callback; | 577 network_handler::ErrorCallback error_callback = request->error_callback; |
581 pending_requests_.erase(service_path); | 578 pending_requests_.erase(service_path); |
582 if (error_callback.is_null()) | 579 if (error_callback.is_null()) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 | 634 |
638 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 635 void NetworkConnectionHandler::HandleShillDisconnectSuccess( |
639 const std::string& service_path, | 636 const std::string& service_path, |
640 const base::Closure& success_callback) { | 637 const base::Closure& success_callback) { |
641 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 638 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
642 if (!success_callback.is_null()) | 639 if (!success_callback.is_null()) |
643 success_callback.Run(); | 640 success_callback.Run(); |
644 } | 641 } |
645 | 642 |
646 } // namespace chromeos | 643 } // namespace chromeos |
OLD | NEW |