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 "chrome/browser/chromeos/cros/network_library_impl_base.h" | 5 #include "chrome/browser/chromeos/cros/network_library_impl_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 return wimax_networks_; | 297 return wimax_networks_; |
298 } | 298 } |
299 const VirtualNetworkVector& NetworkLibraryImplBase::virtual_networks() const { | 299 const VirtualNetworkVector& NetworkLibraryImplBase::virtual_networks() const { |
300 return virtual_networks_; | 300 return virtual_networks_; |
301 } | 301 } |
302 const VirtualNetworkVector& | 302 const VirtualNetworkVector& |
303 NetworkLibraryImplBase::remembered_virtual_networks() const { | 303 NetworkLibraryImplBase::remembered_virtual_networks() const { |
304 return remembered_virtual_networks_; | 304 return remembered_virtual_networks_; |
305 } | 305 } |
306 | 306 |
307 namespace { | |
308 | |
307 // Use shill's ordering of the services to determine which type of | 309 // Use shill's ordering of the services to determine which type of |
308 // network to return (i.e. don't assume priority of network types). | 310 // network to return (i.e. don't assume priority of network types). |
309 // Note: This does not include any virtual networks. | 311 // Note: This does not include any virtual networks. |
310 namespace { | |
311 const Network* highest_priority(const Network* a, const Network*b) { | 312 const Network* highest_priority(const Network* a, const Network*b) { |
312 if (!a) | 313 if (!a) |
313 return b; | 314 return b; |
314 if (!b) | 315 if (!b) |
315 return a; | 316 return a; |
316 if (b->priority_order() < a->priority_order()) | 317 if (b->priority_order() < a->priority_order()) |
317 return b; | 318 return b; |
318 return a; | 319 return a; |
319 } | 320 } |
320 } | 321 |
322 } // namespace | |
321 | 323 |
322 const Network* NetworkLibraryImplBase::active_network() const { | 324 const Network* NetworkLibraryImplBase::active_network() const { |
323 const Network* result = active_nonvirtual_network(); | 325 const Network* result = active_nonvirtual_network(); |
324 if (active_virtual_ && active_virtual_->is_active()) | 326 if (active_virtual_ && active_virtual_->is_active()) |
325 result = highest_priority(result, active_virtual_); | 327 result = highest_priority(result, active_virtual_); |
326 return result; | 328 return result; |
327 } | 329 } |
328 | 330 |
329 const Network* NetworkLibraryImplBase::active_nonvirtual_network() const { | 331 const Network* NetworkLibraryImplBase::active_nonvirtual_network() const { |
330 const Network* result = NULL; | 332 const Network* result = NULL; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
799 connect_data_.security = security; | 801 connect_data_.security = security; |
800 connect_data_.service_name = ssid; | 802 connect_data_.service_name = ssid; |
801 connect_data_.passphrase = passphrase; | 803 connect_data_.passphrase = passphrase; |
802 connect_data_.save_credentials = save_credentials; | 804 connect_data_.save_credentials = save_credentials; |
803 connect_data_.profile_type = shared ? PROFILE_SHARED : PROFILE_USER; | 805 connect_data_.profile_type = shared ? PROFILE_SHARED : PROFILE_USER; |
804 if (security == SECURITY_8021X) { | 806 if (security == SECURITY_8021X) { |
805 DCHECK(eap_config); | 807 DCHECK(eap_config); |
806 connect_data_.service_name = ssid; | 808 connect_data_.service_name = ssid; |
807 connect_data_.eap_method = eap_config->method; | 809 connect_data_.eap_method = eap_config->method; |
808 connect_data_.eap_auth = eap_config->auth; | 810 connect_data_.eap_auth = eap_config->auth; |
809 connect_data_.server_ca_cert_nss_nickname = | 811 connect_data_.server_ca_cert_fingerprint = |
810 eap_config->server_ca_cert_nss_nickname; | 812 eap_config->server_ca_cert_fingerprint; |
811 connect_data_.eap_use_system_cas = eap_config->use_system_cas; | 813 connect_data_.eap_use_system_cas = eap_config->use_system_cas; |
812 connect_data_.client_cert_pkcs11_id = | 814 connect_data_.client_cert_pkcs11_id = |
813 eap_config->client_cert_pkcs11_id; | 815 eap_config->client_cert_pkcs11_id; |
814 connect_data_.eap_identity = eap_config->identity; | 816 connect_data_.eap_identity = eap_config->identity; |
815 connect_data_.eap_anonymous_identity = eap_config->anonymous_identity; | 817 connect_data_.eap_anonymous_identity = eap_config->anonymous_identity; |
816 } | 818 } |
817 | 819 |
818 CallRequestWifiNetworkAndConnect(ssid, security); | 820 CallRequestWifiNetworkAndConnect(ssid, security); |
819 } | 821 } |
820 | 822 |
821 // 1. Connect to a virtual network with a PSK. | 823 // 1. Connect to a virtual network with a PSK. |
822 void NetworkLibraryImplBase::ConnectToUnconfiguredVirtualNetwork( | 824 void NetworkLibraryImplBase::ConnectToUnconfiguredVirtualNetwork( |
823 const std::string& service_name, | 825 const std::string& service_name, |
824 const std::string& server_hostname, | 826 const std::string& server_hostname, |
825 ProviderType provider_type, | 827 ProviderType provider_type, |
826 const VPNConfigData& config) { | 828 const VPNConfigData& config) { |
827 // Store the connection data to be used by the callback. | 829 // Store the connection data to be used by the callback. |
828 connect_data_.service_name = service_name; | 830 connect_data_.service_name = service_name; |
829 connect_data_.server_hostname = server_hostname; | 831 connect_data_.server_hostname = server_hostname; |
830 connect_data_.psk_key = config.psk; | 832 connect_data_.psk_key = config.psk; |
831 connect_data_.server_ca_cert_nss_nickname = | 833 connect_data_.server_ca_cert_fingerprint = |
832 config.server_ca_cert_nss_nickname; | 834 config.server_ca_cert_fingerprint; |
833 connect_data_.client_cert_pkcs11_id = config.client_cert_pkcs11_id; | 835 connect_data_.client_cert_pkcs11_id = config.client_cert_pkcs11_id; |
834 connect_data_.username = config.username; | 836 connect_data_.username = config.username; |
835 connect_data_.passphrase = config.user_passphrase; | 837 connect_data_.passphrase = config.user_passphrase; |
836 connect_data_.otp = config.otp; | 838 connect_data_.otp = config.otp; |
837 connect_data_.group_name = config.group_name; | 839 connect_data_.group_name = config.group_name; |
838 connect_data_.save_credentials = config.save_credentials; | 840 connect_data_.save_credentials = config.save_credentials; |
839 CallRequestVirtualNetworkAndConnect( | 841 CallRequestVirtualNetworkAndConnect( |
840 service_name, server_hostname, provider_type); | 842 service_name, server_hostname, provider_type); |
841 } | 843 } |
842 | 844 |
(...skipping 17 matching lines...) Expand all Loading... | |
860 if (wifi->name() != data.service_name) { | 862 if (wifi->name() != data.service_name) { |
861 LOG(WARNING) << "WiFi network name does not match ConnectData: " | 863 LOG(WARNING) << "WiFi network name does not match ConnectData: " |
862 << wifi->name() << " != " << data.service_name; | 864 << wifi->name() << " != " << data.service_name; |
863 return; | 865 return; |
864 } | 866 } |
865 wifi->set_added(true); | 867 wifi->set_added(true); |
866 if (data.security == SECURITY_8021X) { | 868 if (data.security == SECURITY_8021X) { |
867 // Enterprise 802.1X EAP network. | 869 // Enterprise 802.1X EAP network. |
868 wifi->SetEAPMethod(data.eap_method); | 870 wifi->SetEAPMethod(data.eap_method); |
869 wifi->SetEAPPhase2Auth(data.eap_auth); | 871 wifi->SetEAPPhase2Auth(data.eap_auth); |
870 wifi->SetEAPServerCaCertNssNickname(data.server_ca_cert_nss_nickname); | 872 wifi->SetEAPServerCaCertFingerprint(data.server_ca_cert_fingerprint); |
871 wifi->SetEAPUseSystemCAs(data.eap_use_system_cas); | 873 wifi->SetEAPUseSystemCAs(data.eap_use_system_cas); |
872 wifi->SetEAPClientCertPkcs11Id(data.client_cert_pkcs11_id); | 874 wifi->SetEAPClientCertPkcs11Id(data.client_cert_pkcs11_id); |
873 wifi->SetEAPIdentity(data.eap_identity); | 875 wifi->SetEAPIdentity(data.eap_identity); |
874 wifi->SetEAPAnonymousIdentity(data.eap_anonymous_identity); | 876 wifi->SetEAPAnonymousIdentity(data.eap_anonymous_identity); |
875 wifi->SetEAPPassphrase(data.passphrase); | 877 wifi->SetEAPPassphrase(data.passphrase); |
876 wifi->SetSaveCredentials(data.save_credentials); | 878 wifi->SetSaveCredentials(data.save_credentials); |
877 } else { | 879 } else { |
878 // Ordinary, non-802.1X network. | 880 // Ordinary, non-802.1X network. |
879 wifi->SetPassphrase(data.passphrase); | 881 wifi->SetPassphrase(data.passphrase); |
880 } | 882 } |
(...skipping 25 matching lines...) Expand all Loading... | |
906 // the code to make the flow more straightforward. See crosbug.com/24636 | 908 // the code to make the flow more straightforward. See crosbug.com/24636 |
907 if (vpn->provider_type() == PROVIDER_TYPE_L2TP_IPSEC_PSK && | 909 if (vpn->provider_type() == PROVIDER_TYPE_L2TP_IPSEC_PSK && |
908 !connect_data_.client_cert_pkcs11_id.empty()) { | 910 !connect_data_.client_cert_pkcs11_id.empty()) { |
909 vpn->set_provider_type(PROVIDER_TYPE_L2TP_IPSEC_USER_CERT); | 911 vpn->set_provider_type(PROVIDER_TYPE_L2TP_IPSEC_USER_CERT); |
910 } | 912 } |
911 | 913 |
912 vpn->set_added(true); | 914 vpn->set_added(true); |
913 if (!data.server_hostname.empty()) | 915 if (!data.server_hostname.empty()) |
914 vpn->set_server_hostname(data.server_hostname); | 916 vpn->set_server_hostname(data.server_hostname); |
915 | 917 |
916 vpn->SetCACertNSS(data.server_ca_cert_nss_nickname); | 918 vpn->SetCACertFingerprint(data.server_ca_cert_fingerprint); |
917 switch (vpn->provider_type()) { | 919 switch (vpn->provider_type()) { |
918 case PROVIDER_TYPE_L2TP_IPSEC_PSK: | 920 case PROVIDER_TYPE_L2TP_IPSEC_PSK: |
919 vpn->SetL2TPIPsecPSKCredentials( | 921 vpn->SetL2TPIPsecPSKCredentials( |
920 data.psk_key, data.username, data.passphrase, data.group_name); | 922 data.psk_key, data.username, data.passphrase, data.group_name); |
921 break; | 923 break; |
922 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: { | 924 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: { |
923 vpn->SetL2TPIPsecCertCredentials( | 925 vpn->SetL2TPIPsecCertCredentials( |
924 data.client_cert_pkcs11_id, | 926 data.client_cert_pkcs11_id, |
925 data.username, data.passphrase, data.group_name); | 927 data.username, data.passphrase, data.group_name); |
926 break; | 928 break; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1016 else | 1018 else |
1017 return false; | 1019 return false; |
1018 return true; | 1020 return true; |
1019 } | 1021 } |
1020 }; | 1022 }; |
1021 | 1023 |
1022 } // namespace | 1024 } // namespace |
1023 | 1025 |
1024 void NetworkLibraryImplBase::LoadOncNetworks( | 1026 void NetworkLibraryImplBase::LoadOncNetworks( |
1025 const base::ListValue& network_configs, | 1027 const base::ListValue& network_configs, |
1026 onc::ONCSource source) { | 1028 onc::ONCSource source, |
1029 const base::Callback<std::string(const std::string&)>& fingerprint_to_pem) { | |
1027 VLOG(2) << __func__ << ": called on " << network_configs; | 1030 VLOG(2) << __func__ << ": called on " << network_configs; |
1028 NetworkProfile* profile = NULL; | 1031 NetworkProfile* profile = NULL; |
1029 bool from_policy = (source == onc::ONC_SOURCE_USER_POLICY || | 1032 bool from_policy = (source == onc::ONC_SOURCE_USER_POLICY || |
1030 source == onc::ONC_SOURCE_DEVICE_POLICY); | 1033 source == onc::ONC_SOURCE_DEVICE_POLICY); |
1031 | 1034 |
1032 // Policies are applied to a specific Shill profile. User ONC import however | 1035 // Policies are applied to a specific Shill profile. User ONC import however |
1033 // is applied to whatever profile Shill chooses. This should be the profile | 1036 // is applied to whatever profile Shill chooses. This should be the profile |
1034 // that is already associated with a network and if no profile is associated | 1037 // that is already associated with a network and if no profile is associated |
1035 // yet, it should be the user profile. | 1038 // yet, it should be the user profile. |
1036 if (from_policy) { | 1039 if (from_policy) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1096 | 1099 |
1097 // Normalize the ONC: Remove irrelevant fields. | 1100 // Normalize the ONC: Remove irrelevant fields. |
1098 onc::Normalizer normalizer(true /* remove recommended fields */); | 1101 onc::Normalizer normalizer(true /* remove recommended fields */); |
1099 scoped_ptr<base::DictionaryValue> normalized_network = | 1102 scoped_ptr<base::DictionaryValue> normalized_network = |
1100 normalizer.NormalizeObject(&onc::kNetworkConfigurationSignature, | 1103 normalizer.NormalizeObject(&onc::kNetworkConfigurationSignature, |
1101 *expanded_network); | 1104 *expanded_network); |
1102 | 1105 |
1103 // Configure the network. | 1106 // Configure the network. |
1104 scoped_ptr<base::DictionaryValue> shill_dict = | 1107 scoped_ptr<base::DictionaryValue> shill_dict = |
1105 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, | 1108 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, |
1106 *normalized_network); | 1109 *normalized_network, |
1110 fingerprint_to_pem); | |
stevenjb
2013/06/21 22:47:13
Passing the callback through here is pretty confus
| |
1107 | 1111 |
1108 // Set the ProxyConfig. | 1112 // Set the ProxyConfig. |
1109 const base::DictionaryValue* proxy_settings; | 1113 const base::DictionaryValue* proxy_settings; |
1110 if (normalized_network->GetDictionaryWithoutPathExpansion( | 1114 if (normalized_network->GetDictionaryWithoutPathExpansion( |
1111 onc::network_config::kProxySettings, | 1115 onc::network_config::kProxySettings, |
1112 &proxy_settings)) { | 1116 &proxy_settings)) { |
1113 scoped_ptr<base::DictionaryValue> proxy_config = | 1117 scoped_ptr<base::DictionaryValue> proxy_config = |
1114 onc::ConvertOncProxySettingsToProxyConfig(*proxy_settings); | 1118 onc::ConvertOncProxySettingsToProxyConfig(*proxy_settings); |
1115 std::string proxy_json; | 1119 std::string proxy_json; |
1116 base::JSONWriter::Write(proxy_config.get(), &proxy_json); | 1120 base::JSONWriter::Write(proxy_config.get(), &proxy_json); |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1679 GetTpmInfo(); | 1683 GetTpmInfo(); |
1680 return tpm_slot_; | 1684 return tpm_slot_; |
1681 } | 1685 } |
1682 | 1686 |
1683 const std::string& NetworkLibraryImplBase::GetTpmPin() { | 1687 const std::string& NetworkLibraryImplBase::GetTpmPin() { |
1684 GetTpmInfo(); | 1688 GetTpmInfo(); |
1685 return tpm_pin_; | 1689 return tpm_pin_; |
1686 } | 1690 } |
1687 | 1691 |
1688 } // namespace chromeos | 1692 } // namespace chromeos |
OLD | NEW |