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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 } | 1064 } |
1065 } | 1065 } |
1066 | 1066 |
1067 // Validate the ONC dictionary. We are liberal and ignore unknown field | 1067 // Validate the ONC dictionary. We are liberal and ignore unknown field |
1068 // names and ignore invalid field names in kRecommended arrays. | 1068 // names and ignore invalid field names in kRecommended arrays. |
1069 onc::Validator validator(false, // Ignore unknown fields. | 1069 onc::Validator validator(false, // Ignore unknown fields. |
1070 false, // Ignore invalid recommended field names. | 1070 false, // Ignore invalid recommended field names. |
1071 true, // Fail on missing fields. | 1071 true, // Fail on missing fields. |
1072 from_policy); | 1072 from_policy); |
1073 | 1073 |
1074 // Unknown fields are removed from the result. | |
1075 onc::Validator::Result validation_result; | 1074 onc::Validator::Result validation_result; |
1076 validator.ValidateAndRepairObject(&onc::kToplevelConfigurationSignature, | 1075 validator.ValidateAndRepairObject(&onc::kToplevelConfigurationSignature, |
1077 *root_dict, | 1076 *root_dict, |
1078 &validation_result); | 1077 &validation_result); |
1079 | 1078 |
1080 if (from_policy) { | 1079 if (from_policy) { |
1081 UMA_HISTOGRAM_BOOLEAN("Enterprise.ONC.PolicyValidation", | 1080 UMA_HISTOGRAM_BOOLEAN("Enterprise.ONC.PolicyValidation", |
1082 validation_result == onc::Validator::VALID); | 1081 validation_result == onc::Validator::VALID); |
1083 } | 1082 } |
1084 | 1083 |
| 1084 bool success = true; |
1085 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) { | 1085 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) { |
1086 LOG(WARNING) << "ONC from " << onc::GetSourceAsString(source) | 1086 LOG(WARNING) << "ONC from " << onc::GetSourceAsString(source) |
1087 << " produced warnings."; | 1087 << " produced warnings."; |
1088 } else if (validation_result == onc::Validator::INVALID) { | 1088 } else if (validation_result == onc::Validator::INVALID) { |
1089 LOG(ERROR) << "ONC from " << onc::GetSourceAsString(source) | 1089 LOG(ERROR) << "ONC from " << onc::GetSourceAsString(source) |
1090 << " is invalid and couldn't be repaired."; | 1090 << " is invalid and couldn't be repaired."; |
| 1091 success = false; |
1091 } | 1092 } |
1092 | 1093 |
1093 const base::ListValue* certificates; | 1094 const base::ListValue* certificates; |
1094 bool has_certificates = | 1095 bool has_certificates = |
1095 root_dict->GetListWithoutPathExpansion(onc::kCertificates, &certificates); | 1096 root_dict->GetListWithoutPathExpansion(onc::kCertificates, &certificates); |
1096 | 1097 |
1097 const base::ListValue* network_configs; | 1098 const base::ListValue* network_configs; |
1098 bool has_network_configurations = root_dict->GetListWithoutPathExpansion( | 1099 bool has_network_configurations = root_dict->GetListWithoutPathExpansion( |
1099 onc::kNetworkConfigurations, | 1100 onc::kNetworkConfigurations, |
1100 &network_configs); | 1101 &network_configs); |
1101 | 1102 |
1102 if (has_certificates) { | 1103 if (has_certificates) { |
1103 VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates"; | 1104 VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates"; |
1104 | 1105 |
1105 onc::CertificateImporter cert_importer(source, allow_web_trust_from_policy); | 1106 onc::CertificateImporter cert_importer(source, allow_web_trust_from_policy); |
1106 if (cert_importer.ParseAndStoreCertificates(*certificates) != | 1107 if (cert_importer.ParseAndStoreCertificates(*certificates) != |
1107 onc::CertificateImporter::IMPORT_OK) { | 1108 onc::CertificateImporter::IMPORT_OK) { |
1108 LOG(ERROR) << "Cannot parse some of the certificates in the ONC from " | 1109 LOG(ERROR) << "Cannot parse some of the certificates in the ONC from " |
1109 << onc::GetSourceAsString(source); | 1110 << onc::GetSourceAsString(source); |
1110 return false; | 1111 success = false; |
1111 } | 1112 } |
1112 } | 1113 } |
1113 | 1114 |
1114 std::set<std::string> removal_ids; | 1115 std::set<std::string> removal_ids; |
1115 std::set<std::string>& network_ids(network_source_map_[source]); | 1116 std::set<std::string>& network_ids(network_source_map_[source]); |
1116 network_ids.clear(); | 1117 network_ids.clear(); |
1117 if (has_network_configurations) { | 1118 if (has_network_configurations) { |
1118 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; | 1119 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; |
1119 OncNetworkParser parser(*network_configs, source); | 1120 OncNetworkParser parser(*network_configs, source); |
1120 | 1121 |
1121 // Parse all networks. Bail out if that fails. | 1122 // Parse all networks. Bail out if that fails. |
1122 NetworkOncMap added_onc_map; | 1123 NetworkOncMap added_onc_map; |
1123 ScopedVector<Network> networks; | 1124 ScopedVector<Network> networks; |
1124 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { | 1125 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { |
1125 // Parse Open Network Configuration blob into a temporary Network object. | 1126 // Parse Open Network Configuration blob into a temporary Network object. |
1126 bool marked_for_removal = false; | 1127 bool marked_for_removal = false; |
1127 Network* network = parser.ParseNetwork(i, &marked_for_removal); | 1128 Network* network = parser.ParseNetwork(i, &marked_for_removal); |
1128 if (!network) { | 1129 if (!network) { |
1129 LOG(ERROR) << "Error during ONC parsing network at index " << i | 1130 LOG(ERROR) << "Error during ONC parsing network at index " << i |
1130 << " from " << onc::GetSourceAsString(source); | 1131 << " from " << onc::GetSourceAsString(source); |
1131 return false; | 1132 success = false; |
| 1133 continue; |
1132 } | 1134 } |
1133 | 1135 |
1134 // Disallow anything but WiFi and Ethernet for device-level policy (which | 1136 // Disallow anything but WiFi and Ethernet for device-level policy (which |
1135 // corresponds to shared networks). See also http://crosbug.com/28741. | 1137 // corresponds to shared networks). See also http://crosbug.com/28741. |
1136 if (source == onc::ONC_SOURCE_DEVICE_POLICY && | 1138 if (source == onc::ONC_SOURCE_DEVICE_POLICY && |
1137 network->type() != TYPE_WIFI && | 1139 network->type() != TYPE_WIFI && |
1138 network->type() != TYPE_ETHERNET) { | 1140 network->type() != TYPE_ETHERNET) { |
1139 LOG(WARNING) << "Ignoring device-level policy-pushed network of type " | 1141 LOG(WARNING) << "Ignoring device-level policy-pushed network of type " |
1140 << network->type(); | 1142 << network->type(); |
1141 delete network; | 1143 delete network; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 network_ids.insert(network->unique_id()); | 1210 network_ids.insert(network->unique_id()); |
1209 } | 1211 } |
1210 } | 1212 } |
1211 | 1213 |
1212 if (from_policy) { | 1214 if (from_policy) { |
1213 // For policy-managed networks, go through the list of existing remembered | 1215 // For policy-managed networks, go through the list of existing remembered |
1214 // networks and clean out the ones that no longer have a definition in the | 1216 // networks and clean out the ones that no longer have a definition in the |
1215 // ONC blob. We first collect the networks and do the actual deletion later | 1217 // ONC blob. We first collect the networks and do the actual deletion later |
1216 // because ForgetNetwork() changes the remembered network vectors. | 1218 // because ForgetNetwork() changes the remembered network vectors. |
1217 ForgetNetworksById(source, network_ids, false); | 1219 ForgetNetworksById(source, network_ids, false); |
1218 } else if (source == onc::ONC_SOURCE_USER_IMPORT) { | 1220 } else if (source == onc::ONC_SOURCE_USER_IMPORT && !removal_ids.empty()) { |
1219 if (removal_ids.empty()) | |
1220 return true; | |
1221 | |
1222 ForgetNetworksById(source, removal_ids, true); | 1221 ForgetNetworksById(source, removal_ids, true); |
1223 } | 1222 } |
1224 | 1223 |
1225 return true; | 1224 return success; |
1226 } | 1225 } |
1227 | 1226 |
1228 //////////////////////////////////////////////////////////////////////////// | 1227 //////////////////////////////////////////////////////////////////////////// |
1229 // Testing functions. | 1228 // Testing functions. |
1230 | 1229 |
1231 bool NetworkLibraryImplBase::SetActiveNetwork( | 1230 bool NetworkLibraryImplBase::SetActiveNetwork( |
1232 ConnectionType type, const std::string& service_path) { | 1231 ConnectionType type, const std::string& service_path) { |
1233 Network* network = NULL; | 1232 Network* network = NULL; |
1234 if (!service_path.empty()) | 1233 if (!service_path.empty()) |
1235 network = FindNetworkByPath(service_path); | 1234 network = FindNetworkByPath(service_path); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1739 GetTpmInfo(); | 1738 GetTpmInfo(); |
1740 return tpm_slot_; | 1739 return tpm_slot_; |
1741 } | 1740 } |
1742 | 1741 |
1743 const std::string& NetworkLibraryImplBase::GetTpmPin() { | 1742 const std::string& NetworkLibraryImplBase::GetTpmPin() { |
1744 GetTpmInfo(); | 1743 GetTpmInfo(); |
1745 return tpm_pin_; | 1744 return tpm_pin_; |
1746 } | 1745 } |
1747 | 1746 |
1748 } // namespace chromeos | 1747 } // namespace chromeos |
OLD | NEW |