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_reader.h" | 8 #include "base/json/json_reader.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 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 if (wifi->auto_connect()) { | 1017 if (wifi->auto_connect()) { |
1018 ConnectToWifiNetwork(wifi); | 1018 ConnectToWifiNetwork(wifi); |
1019 break; | 1019 break; |
1020 } | 1020 } |
1021 } | 1021 } |
1022 } | 1022 } |
1023 | 1023 |
1024 bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, | 1024 bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, |
1025 const std::string& passphrase, | 1025 const std::string& passphrase, |
1026 NetworkUIData::ONCSource source, | 1026 NetworkUIData::ONCSource source, |
1027 bool allow_web_trust_from_policy, | 1027 bool allow_web_trust_from_policy) { |
1028 std::string* error) { | 1028 VLOG(2) << __func__ << ": called on " << onc_blob; |
1029 NetworkProfile* profile = NULL; | 1029 NetworkProfile* profile = NULL; |
1030 bool from_policy = (source == NetworkUIData::ONC_SOURCE_USER_POLICY || | 1030 bool from_policy = (source == NetworkUIData::ONC_SOURCE_USER_POLICY || |
1031 source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY); | 1031 source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY); |
1032 | 1032 |
1033 // Policies are applied to a specific Shill profile. User ONC import however | 1033 // Policies are applied to a specific Shill profile. User ONC import however |
1034 // is applied to whatever profile Shill chooses. This should be the profile | 1034 // is applied to whatever profile Shill chooses. This should be the profile |
1035 // that is already associated with a network and if no profile is associated | 1035 // that is already associated with a network and if no profile is associated |
1036 // yet, it should be the user profile. | 1036 // yet, it should be the user profile. |
1037 if (from_policy) { | 1037 if (from_policy) { |
1038 profile = GetProfileForType(GetProfileTypeForSource(source)); | 1038 profile = GetProfileForType(GetProfileTypeForSource(source)); |
1039 if (profile == NULL) { | 1039 if (profile == NULL) { |
1040 DLOG(WARNING) << "Profile for ONC source " << source << " doesn't exist."; | 1040 VLOG(2) << "Profile for ONC source " << source << " doesn't exist."; |
1041 return false; | 1041 return true; |
1042 } | 1042 } |
1043 } | 1043 } |
1044 | 1044 |
1045 VLOG(2) << __func__ << ": called on " << onc_blob; | |
1046 std::string json_error; | 1045 std::string json_error; |
1047 scoped_ptr<base::DictionaryValue> root_dict = | 1046 scoped_ptr<base::DictionaryValue> root_dict = |
1048 onc::ReadDictionaryFromJson(onc_blob, &json_error); | 1047 onc::ReadDictionaryFromJson(onc_blob, &json_error); |
1049 if (root_dict.get() == NULL) { | 1048 if (root_dict.get() == NULL) { |
1050 if (error != NULL) | 1049 LOG(ERROR) << "ONC loaded from ONC source " << source |
1051 *error = json_error; | 1050 << " is not a valid json dictionary: " << json_error; |
1052 LOG(WARNING) << "ONC loaded from ONC source " << source | |
1053 << " is not a valid json dictionary: " << json_error; | |
1054 return false; | 1051 return false; |
1055 } | 1052 } |
1056 | 1053 |
1057 // Check and see if this is an encrypted ONC file. If so, decrypt it. | 1054 // Check and see if this is an encrypted ONC file. If so, decrypt it. |
1058 std::string onc_type; | 1055 std::string onc_type; |
1059 root_dict->GetStringWithoutPathExpansion(onc::kType, &onc_type); | 1056 root_dict->GetStringWithoutPathExpansion(onc::kType, &onc_type); |
1060 if (onc_type == onc::kEncryptedConfiguration) { | 1057 if (onc_type == onc::kEncryptedConfiguration) { |
1061 std::string decrypt_error; | 1058 std::string decrypt_error; |
1062 root_dict = onc::Decrypt(passphrase, *root_dict, &decrypt_error); | 1059 root_dict = onc::Decrypt(passphrase, *root_dict, &decrypt_error); |
1063 if (root_dict.get() == NULL) { | 1060 if (root_dict.get() == NULL) { |
1064 if (error != NULL) | 1061 LOG(ERROR) << "Couldn't decrypt the ONC from source " << source |
1065 *error = decrypt_error; | 1062 << " with error: " << decrypt_error; |
1066 LOG(WARNING) << "Couldn't decrypt the ONC from source " << source | |
1067 << " with error: " << decrypt_error; | |
1068 return false; | 1063 return false; |
1069 } | 1064 } |
1070 } | 1065 } |
1071 | 1066 |
1072 // Validate the ONC dictionary. We are liberal and ignore unknown field | 1067 // Validate the ONC dictionary. We are liberal and ignore unknown field |
1073 // names and ignore invalid field names in kRecommended arrays. | 1068 // names and ignore invalid field names in kRecommended arrays. |
1074 onc::Validator validator(false, // Ignore unknown fields. | 1069 onc::Validator validator(false, // Ignore unknown fields. |
1075 false, // Ignore invalid recommended field names. | 1070 false, // Ignore invalid recommended field names. |
1076 true, // Fail on missing fields. | 1071 true, // Fail on missing fields. |
1077 from_policy); | 1072 from_policy); |
1078 | 1073 |
1079 // Unknown fields are removed from the result. | 1074 // Unknown fields are removed from the result. |
| 1075 onc::Validator::Result validation_result; |
1080 root_dict = validator.ValidateAndRepairObject( | 1076 root_dict = validator.ValidateAndRepairObject( |
1081 &onc::kUnencryptedConfigurationSignature, | 1077 &onc::kToplevelConfigurationSignature, *root_dict, &validation_result); |
1082 *root_dict); | |
1083 | 1078 |
1084 if (root_dict.get() == NULL) { | 1079 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) { |
1085 LOG(WARNING) << "ONC from source " << source | 1080 LOG(WARNING) << "ONC from source " << source << " produced warnings."; |
1086 << " is invalid and couldn't be repaired."; | 1081 } else if (validation_result == onc::Validator::INVALID || |
| 1082 root_dict.get() == NULL) { |
| 1083 LOG(ERROR) << "ONC from source " << source |
| 1084 << " is invalid and couldn't be repaired."; |
1087 return false; | 1085 return false; |
1088 } | 1086 } |
1089 | 1087 |
1090 const base::ListValue* certificates; | 1088 const base::ListValue* certificates; |
1091 bool has_certificates = | 1089 bool has_certificates = |
1092 root_dict->GetListWithoutPathExpansion(onc::kCertificates, &certificates); | 1090 root_dict->GetListWithoutPathExpansion(onc::kCertificates, &certificates); |
1093 | 1091 |
1094 const base::ListValue* network_configs; | 1092 const base::ListValue* network_configs; |
1095 bool has_network_configurations = root_dict->GetListWithoutPathExpansion( | 1093 bool has_network_configurations = root_dict->GetListWithoutPathExpansion( |
1096 onc::kNetworkConfigurations, | 1094 onc::kNetworkConfigurations, |
1097 &network_configs); | 1095 &network_configs); |
1098 | 1096 |
1099 // At least one of NetworkConfigurations or Certificates is required. | |
1100 LOG_IF(WARNING, (!has_network_configurations && !has_certificates)) | |
1101 << "ONC from source " << source | |
1102 << " has neither NetworkConfigurations nor Certificates."; | |
1103 | |
1104 if (has_certificates) { | 1097 if (has_certificates) { |
1105 VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates"; | 1098 VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates"; |
1106 | 1099 |
1107 onc::CertificateImporter cert_importer(source, allow_web_trust_from_policy); | 1100 onc::CertificateImporter cert_importer(source, allow_web_trust_from_policy); |
1108 std::string cert_error; | 1101 std::string cert_error; |
1109 if (!cert_importer.ParseAndStoreCertificates(*certificates, &cert_error)) { | 1102 if (!cert_importer.ParseAndStoreCertificates(*certificates, &cert_error)) { |
1110 if (error != NULL) | 1103 LOG(ERROR) << "Cannot parse some of the certificates in the ONC from " |
1111 *error = cert_error; | 1104 << "source " << source << " with error: " << cert_error; |
1112 LOG(WARNING) << "Cannot parse some of the certificates in the ONC from " | |
1113 << "source " << source << " with error: " << cert_error; | |
1114 return false; | 1105 return false; |
1115 } | 1106 } |
1116 } | 1107 } |
1117 | 1108 |
1118 std::set<std::string> removal_ids; | 1109 std::set<std::string> removal_ids; |
1119 std::set<std::string>& network_ids(network_source_map_[source]); | 1110 std::set<std::string>& network_ids(network_source_map_[source]); |
1120 network_ids.clear(); | 1111 network_ids.clear(); |
1121 if (has_network_configurations) { | 1112 if (has_network_configurations) { |
1122 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; | 1113 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; |
1123 OncNetworkParser parser(*network_configs, source); | 1114 OncNetworkParser parser(*network_configs, source); |
1124 | 1115 |
1125 // Parse all networks. Bail out if that fails. | 1116 // Parse all networks. Bail out if that fails. |
1126 NetworkOncMap added_onc_map; | 1117 NetworkOncMap added_onc_map; |
1127 ScopedVector<Network> networks; | 1118 ScopedVector<Network> networks; |
1128 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { | 1119 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { |
1129 // Parse Open Network Configuration blob into a temporary Network object. | 1120 // Parse Open Network Configuration blob into a temporary Network object. |
1130 bool marked_for_removal = false; | 1121 bool marked_for_removal = false; |
1131 Network* network = parser.ParseNetwork(i, &marked_for_removal); | 1122 Network* network = parser.ParseNetwork(i, &marked_for_removal); |
1132 if (!network) { | 1123 if (!network) { |
1133 if (error != NULL) | 1124 LOG(ERROR) << "Error during parsing network at index " << i |
1134 *error = parser.parse_error(); | |
1135 LOG(WARNING) << "Error during parsing network at index " << i | |
1136 << " from ONC source " << source | 1125 << " from ONC source " << source |
1137 << ": " << parser.parse_error(); | 1126 << ": " << parser.parse_error(); |
1138 return false; | 1127 return false; |
1139 } | 1128 } |
1140 | 1129 |
1141 // Disallow anything but WiFi and Ethernet for device-level policy (which | 1130 // Disallow anything but WiFi and Ethernet for device-level policy (which |
1142 // corresponds to shared networks). See also http://crosbug.com/28741. | 1131 // corresponds to shared networks). See also http://crosbug.com/28741. |
1143 if (source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY && | 1132 if (source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY && |
1144 network->type() != TYPE_WIFI && | 1133 network->type() != TYPE_WIFI && |
1145 network->type() != TYPE_ETHERNET) { | 1134 network->type() != TYPE_ETHERNET) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 // Set the appropriate profile for |source|. | 1187 // Set the appropriate profile for |source|. |
1199 if (profile != NULL) | 1188 if (profile != NULL) |
1200 dict.SetString(flimflam::kProfileProperty, profile->path); | 1189 dict.SetString(flimflam::kProfileProperty, profile->path); |
1201 | 1190 |
1202 // For Ethernet networks, apply them to the current Ethernet service. | 1191 // For Ethernet networks, apply them to the current Ethernet service. |
1203 if (network->type() == TYPE_ETHERNET) { | 1192 if (network->type() == TYPE_ETHERNET) { |
1204 const EthernetNetwork* ethernet = ethernet_network(); | 1193 const EthernetNetwork* ethernet = ethernet_network(); |
1205 if (ethernet) { | 1194 if (ethernet) { |
1206 CallConfigureService(ethernet->unique_id(), &dict); | 1195 CallConfigureService(ethernet->unique_id(), &dict); |
1207 } else { | 1196 } else { |
1208 DLOG(WARNING) << "Tried to import ONC with an Ethernet network when " | 1197 LOG(WARNING) << "Tried to import ONC with an Ethernet network when " |
1209 << "there is no active Ethernet connection."; | 1198 << "there is no active Ethernet connection."; |
1210 } | 1199 } |
1211 } else { | 1200 } else { |
1212 CallConfigureService(network->unique_id(), &dict); | 1201 CallConfigureService(network->unique_id(), &dict); |
1213 } | 1202 } |
1214 | 1203 |
1215 network_ids.insert(network->unique_id()); | 1204 network_ids.insert(network->unique_id()); |
1216 } | 1205 } |
1217 } | 1206 } |
1218 | 1207 |
1219 if (from_policy) { | 1208 if (from_policy) { |
1220 // For policy-managed networks, go through the list of existing remembered | 1209 // For policy-managed networks, go through the list of existing remembered |
1221 // networks and clean out the ones that no longer have a definition in the | 1210 // networks and clean out the ones that no longer have a definition in the |
1222 // ONC blob. We first collect the networks and do the actual deletion later | 1211 // ONC blob. We first collect the networks and do the actual deletion later |
1223 // because ForgetNetwork() changes the remembered network vectors. | 1212 // because ForgetNetwork() changes the remembered network vectors. |
1224 ForgetNetworksById(source, network_ids, false); | 1213 ForgetNetworksById(source, network_ids, false); |
1225 } else if (source == NetworkUIData::ONC_SOURCE_USER_IMPORT) { | 1214 } else if (source == NetworkUIData::ONC_SOURCE_USER_IMPORT && |
1226 if (removal_ids.empty()) | 1215 !removal_ids.empty()) { |
1227 return true; | |
1228 | |
1229 ForgetNetworksById(source, removal_ids, true); | 1216 ForgetNetworksById(source, removal_ids, true); |
1230 } | 1217 } |
1231 | 1218 |
1232 return true; | 1219 return true; |
1233 } | 1220 } |
1234 | 1221 |
1235 //////////////////////////////////////////////////////////////////////////// | 1222 //////////////////////////////////////////////////////////////////////////// |
1236 // Testing functions. | 1223 // Testing functions. |
1237 | 1224 |
1238 bool NetworkLibraryImplBase::SetActiveNetwork( | 1225 bool NetworkLibraryImplBase::SetActiveNetwork( |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 GetTpmInfo(); | 1733 GetTpmInfo(); |
1747 return tpm_slot_; | 1734 return tpm_slot_; |
1748 } | 1735 } |
1749 | 1736 |
1750 const std::string& NetworkLibraryImplBase::GetTpmPin() { | 1737 const std::string& NetworkLibraryImplBase::GetTpmPin() { |
1751 GetTpmInfo(); | 1738 GetTpmInfo(); |
1752 return tpm_pin_; | 1739 return tpm_pin_; |
1753 } | 1740 } |
1754 | 1741 |
1755 } // namespace chromeos | 1742 } // namespace chromeos |
OLD | NEW |