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" |
11 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
12 #include "chromeos/dbus/shill_manager_client.h" | 12 #include "chromeos/dbus/shill_manager_client.h" |
13 #include "chromeos/dbus/shill_service_client.h" | 13 #include "chromeos/dbus/shill_service_client.h" |
14 #include "chromeos/network/client_cert_util.h" | 14 #include "chromeos/network/client_cert_util.h" |
15 #include "chromeos/network/managed_network_configuration_handler.h" | |
16 #include "chromeos/network/network_configuration_handler.h" | 15 #include "chromeos/network/network_configuration_handler.h" |
17 #include "chromeos/network/network_event_log.h" | 16 #include "chromeos/network/network_event_log.h" |
18 #include "chromeos/network/network_handler_callbacks.h" | 17 #include "chromeos/network/network_handler_callbacks.h" |
19 #include "chromeos/network/network_state.h" | 18 #include "chromeos/network/network_state.h" |
20 #include "chromeos/network/network_state_handler.h" | 19 #include "chromeos/network/network_state_handler.h" |
21 #include "chromeos/network/network_ui_data.h" | 20 #include "chromeos/network/network_ui_data.h" |
| 21 #include "chromeos/network/shill_property_util.h" |
22 #include "dbus/object_path.h" | 22 #include "dbus/object_path.h" |
23 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
24 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
25 | 25 |
26 namespace chromeos { | 26 namespace chromeos { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 void InvokeErrorCallback(const std::string& service_path, | 30 void InvokeErrorCallback(const std::string& service_path, |
31 const network_handler::ErrorCallback& error_callback, | 31 const network_handler::ErrorCallback& error_callback, |
32 const std::string& error_name) { | 32 const std::string& error_name) { |
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 == flimflam::kErrorBadWEPKey || |
44 error == flimflam::kErrorPppAuthFailed || | 44 error == flimflam::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 void CopyStringFromDictionary(const base::DictionaryValue& source, | |
51 const std::string& key, | |
52 base::DictionaryValue* dest) { | |
53 std::string string_value; | |
54 if (source.GetStringWithoutPathExpansion(key, &string_value)) | |
55 dest->SetStringWithoutPathExpansion(key, string_value); | |
56 } | |
57 | |
58 bool NetworkRequiresActivation(const NetworkState* network) { | 50 bool NetworkRequiresActivation(const NetworkState* network) { |
59 return (network->type() == flimflam::kTypeCellular && | 51 return (network->type() == flimflam::kTypeCellular && |
60 ((network->activation_state() != flimflam::kActivationStateActivated && | 52 ((network->activation_state() != flimflam::kActivationStateActivated && |
61 network->activation_state() != flimflam::kActivationStateUnknown))); | 53 network->activation_state() != flimflam::kActivationStateUnknown))); |
62 } | 54 } |
63 | 55 |
64 bool VPNIsConfigured(const std::string& service_path, | 56 bool VPNIsConfigured(const std::string& service_path, |
65 const std::string& provider_type, | 57 const std::string& provider_type, |
66 const base::DictionaryValue& provider_properties) { | 58 const base::DictionaryValue& provider_properties) { |
67 if (provider_type == flimflam::kProviderOpenVpn) { | 59 if (provider_type == flimflam::kProviderOpenVpn) { |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 base::DictionaryValue config_properties; | 396 base::DictionaryValue config_properties; |
405 if (client_cert_type != client_cert::CONFIG_TYPE_NONE) { | 397 if (client_cert_type != client_cert::CONFIG_TYPE_NONE) { |
406 // If the client certificate must be configured, this will be set to a | 398 // If the client certificate must be configured, this will be set to a |
407 // non-empty string. | 399 // non-empty string. |
408 std::string pkcs11_id; | 400 std::string pkcs11_id; |
409 | 401 |
410 // Check certificate properties in kUIDataProperty if configured. | 402 // Check certificate properties in kUIDataProperty if configured. |
411 // Note: Wifi/VPNConfigView set these properties explicitly, in which case | 403 // Note: Wifi/VPNConfigView set these properties explicitly, in which case |
412 // only the TPM must be configured. | 404 // only the TPM must be configured. |
413 scoped_ptr<NetworkUIData> ui_data = | 405 scoped_ptr<NetworkUIData> ui_data = |
414 ManagedNetworkConfigurationHandler::GetUIData(service_properties); | 406 shill_property_util::GetUIDataFromProperties(service_properties); |
415 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) { | 407 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) { |
416 // User must be logged in to connect to a network requiring a certificate. | 408 // User must be logged in to connect to a network requiring a certificate. |
417 if (!logged_in_ || !cert_loader_) { | 409 if (!logged_in_ || !cert_loader_) { |
418 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); | 410 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
419 return; | 411 return; |
420 } | 412 } |
421 | 413 |
422 // If certificates have not been loaded yet, queue the connect request. | 414 // If certificates have not been loaded yet, queue the connect request. |
423 if (!certificates_loaded_) { | 415 if (!certificates_loaded_) { |
424 ConnectRequest* request = GetPendingRequest(service_path); | 416 ConnectRequest* request = GetPendingRequest(service_path); |
(...skipping 24 matching lines...) Expand all Loading... |
449 client_cert::SetShillProperties(client_cert_type, | 441 client_cert::SetShillProperties(client_cert_type, |
450 cert_loader_->tpm_token_slot(), | 442 cert_loader_->tpm_token_slot(), |
451 cert_loader_->tpm_user_pin(), | 443 cert_loader_->tpm_user_pin(), |
452 pkcs11_id.empty() ? NULL : &pkcs11_id, | 444 pkcs11_id.empty() ? NULL : &pkcs11_id, |
453 &config_properties); | 445 &config_properties); |
454 } | 446 } |
455 } | 447 } |
456 | 448 |
457 if (!config_properties.empty()) { | 449 if (!config_properties.empty()) { |
458 NET_LOG_EVENT("Configuring Network", service_path); | 450 NET_LOG_EVENT("Configuring Network", service_path); |
459 | 451 if (shill_property_util::CopyIdentifyingProperties(service_properties, |
460 // Set configuration properties required by Shill to identify the network. | 452 &config_properties)) { |
461 config_properties.SetStringWithoutPathExpansion( | 453 network_configuration_handler_->SetProperties( |
462 flimflam::kTypeProperty, type); | 454 service_path, |
463 CopyStringFromDictionary(service_properties, flimflam::kNameProperty, | 455 config_properties, |
464 &config_properties); | 456 base::Bind(&NetworkConnectionHandler::CallShillConnect, |
465 CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, | 457 AsWeakPtr(), |
466 &config_properties); | 458 service_path), |
467 if (type == flimflam::kTypeVPN) { | 459 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
468 config_properties.SetStringWithoutPathExpansion( | 460 AsWeakPtr(), |
469 flimflam::kProviderTypeProperty, vpn_provider_type); | 461 service_path)); |
470 config_properties.SetStringWithoutPathExpansion( | 462 return; |
471 flimflam::kProviderHostProperty, vpn_provider_host); | |
472 } else if (type == flimflam::kTypeWifi) { | |
473 config_properties.SetStringWithoutPathExpansion( | |
474 flimflam::kSecurityProperty, security); | |
475 } | 463 } |
476 | 464 NET_LOG_ERROR("Shill dictionary is missing some relevant entries", |
477 network_configuration_handler_->SetProperties( | 465 service_path); |
478 service_path, | |
479 config_properties, | |
480 base::Bind(&NetworkConnectionHandler::CallShillConnect, | |
481 AsWeakPtr(), service_path), | |
482 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | |
483 AsWeakPtr(), service_path)); | |
484 return; | |
485 } | 466 } |
486 | 467 |
487 // Otherwise, we probably still need to configure the network since | 468 // Otherwise, we probably still need to configure the network since |
488 // 'Connectable' is false. If |check_error_state| is true, signal an | 469 // 'Connectable' is false. If |check_error_state| is true, signal an |
489 // error, otherwise attempt to connect to possibly gain additional error | 470 // error, otherwise attempt to connect to possibly gain additional error |
490 // state from Shill (or in case 'Connectable' is improperly unset). | 471 // state from Shill (or in case 'Connectable' is improperly unset). |
491 if (check_error_state) | 472 if (check_error_state) |
492 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 473 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
493 else | 474 else |
494 CallShillConnect(service_path); | 475 CallShillConnect(service_path); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 | 644 |
664 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 645 void NetworkConnectionHandler::HandleShillDisconnectSuccess( |
665 const std::string& service_path, | 646 const std::string& service_path, |
666 const base::Closure& success_callback) { | 647 const base::Closure& success_callback) { |
667 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 648 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
668 if (!success_callback.is_null()) | 649 if (!success_callback.is_null()) |
669 success_callback.Run(); | 650 success_callback.Run(); |
670 } | 651 } |
671 | 652 |
672 } // namespace chromeos | 653 } // namespace chromeos |
OLD | NEW |