Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: chrome/browser/chromeos/cros/network_library_impl_base.cc

Issue 11415148: Adding error handling to ONC validation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@extract_onc_certificate
Patch Set: Initial patch. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 } 1070 }
1071 1071
1072 // Validate the ONC dictionary. We are liberal and ignore unknown field 1072 // Validate the ONC dictionary. We are liberal and ignore unknown field
1073 // names and ignore invalid field names in kRecommended arrays. 1073 // names and ignore invalid field names in kRecommended arrays.
1074 onc::Validator validator(false, // Ignore unknown fields. 1074 onc::Validator validator(false, // Ignore unknown fields.
1075 false, // Ignore invalid recommended field names. 1075 false, // Ignore invalid recommended field names.
1076 true, // Fail on missing fields. 1076 true, // Fail on missing fields.
1077 from_policy); 1077 from_policy);
1078 1078
1079 // Unknown fields are removed from the result. 1079 // Unknown fields are removed from the result.
1080 std::string validator_error;
1080 root_dict = validator.ValidateAndRepairObject( 1081 root_dict = validator.ValidateAndRepairObject(
1081 &onc::kUnencryptedConfigurationSignature, 1082 &onc::kToplevelConfigurationSignature, *root_dict, &validator_error);
1082 *root_dict); 1083
1084 if (!validator_error.empty()) {
1085 if (error != NULL) {
1086 *error = validator_error;
1087 error->append("\n");
1088 }
1089 LOG(WARNING) << "ONC from source " << source
1090 << " contains errors: " << validator_error;
1091 }
1083 1092
1084 if (root_dict.get() == NULL) { 1093 if (root_dict.get() == NULL) {
1085 LOG(WARNING) << "ONC from source " << source 1094 LOG(WARNING) << "ONC from source " << source
1086 << " is invalid and couldn't be repaired."; 1095 << " is invalid and couldn't be repaired.";
1087 return false; 1096 return false;
1088 } 1097 }
1089 1098
1090 const base::ListValue* certificates; 1099 const base::ListValue* certificates;
1091 bool has_certificates = 1100 bool has_certificates =
1092 root_dict->GetListWithoutPathExpansion(onc::kCertificates, &certificates); 1101 root_dict->GetListWithoutPathExpansion(onc::kCertificates, &certificates);
1093 1102
1094 const base::ListValue* network_configs; 1103 const base::ListValue* network_configs;
1095 bool has_network_configurations = root_dict->GetListWithoutPathExpansion( 1104 bool has_network_configurations = root_dict->GetListWithoutPathExpansion(
1096 onc::kNetworkConfigurations, 1105 onc::kNetworkConfigurations,
1097 &network_configs); 1106 &network_configs);
1098 1107
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) { 1108 if (has_certificates) {
1105 VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates"; 1109 VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates";
1106 1110
1107 onc::CertificateImporter cert_importer(source, allow_web_trust_from_policy); 1111 onc::CertificateImporter cert_importer(source, allow_web_trust_from_policy);
1108 std::string cert_error; 1112 std::string cert_error;
1109 if (!cert_importer.ParseAndStoreCertificates(*certificates, &cert_error)) { 1113 if (!cert_importer.ParseAndStoreCertificates(*certificates, &cert_error)) {
1110 if (error != NULL) 1114 if (error != NULL) {
1111 *error = cert_error; 1115 error->append(cert_error);
1116 error->append("\n");
1117 }
1112 LOG(WARNING) << "Cannot parse some of the certificates in the ONC from " 1118 LOG(WARNING) << "Cannot parse some of the certificates in the ONC from "
1113 << "source " << source << " with error: " << cert_error; 1119 << "source " << source << " with error: " << cert_error;
1114 return false; 1120 return false;
1115 } 1121 }
1116 } 1122 }
1117 1123
1118 std::set<std::string> removal_ids; 1124 std::set<std::string> removal_ids;
1119 std::set<std::string>& network_ids(network_source_map_[source]); 1125 std::set<std::string>& network_ids(network_source_map_[source]);
1120 network_ids.clear(); 1126 network_ids.clear();
1121 if (has_network_configurations) { 1127 if (has_network_configurations) {
1122 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; 1128 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks";
1123 OncNetworkParser parser(*network_configs, source); 1129 OncNetworkParser parser(*network_configs, source);
1124 1130
1125 // Parse all networks. Bail out if that fails. 1131 // Parse all networks. Bail out if that fails.
1126 NetworkOncMap added_onc_map; 1132 NetworkOncMap added_onc_map;
1127 ScopedVector<Network> networks; 1133 ScopedVector<Network> networks;
1128 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { 1134 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) {
1129 // Parse Open Network Configuration blob into a temporary Network object. 1135 // Parse Open Network Configuration blob into a temporary Network object.
1130 bool marked_for_removal = false; 1136 bool marked_for_removal = false;
1131 Network* network = parser.ParseNetwork(i, &marked_for_removal); 1137 Network* network = parser.ParseNetwork(i, &marked_for_removal);
1132 if (!network) { 1138 if (!network) {
1133 if (error != NULL) 1139 if (error != NULL) {
1134 *error = parser.parse_error(); 1140 error->append(parser.parse_error());
1141 error->append("\n");
1142 }
1135 LOG(WARNING) << "Error during parsing network at index " << i 1143 LOG(WARNING) << "Error during parsing network at index " << i
1136 << " from ONC source " << source 1144 << " from ONC source " << source
1137 << ": " << parser.parse_error(); 1145 << ": " << parser.parse_error();
1138 return false; 1146 return false;
1139 } 1147 }
1140 1148
1141 // Disallow anything but WiFi and Ethernet for device-level policy (which 1149 // Disallow anything but WiFi and Ethernet for device-level policy (which
1142 // corresponds to shared networks). See also http://crosbug.com/28741. 1150 // corresponds to shared networks). See also http://crosbug.com/28741.
1143 if (source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY && 1151 if (source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY &&
1144 network->type() != TYPE_WIFI && 1152 network->type() != TYPE_WIFI &&
1145 network->type() != TYPE_ETHERNET) { 1153 network->type() != TYPE_ETHERNET) {
1154 if (error != NULL) {
1155 error->append(l10n_util::GetStringUTF8(
1156 IDS_NETWORK_CONFIG_ERROR_IGNORING_DEVICE_LEVEL_POLICY));
1157 error->append("\n");
1158 }
1146 LOG(WARNING) << "Ignoring device-level policy-pushed network of type " 1159 LOG(WARNING) << "Ignoring device-level policy-pushed network of type "
1147 << network->type(); 1160 << network->type();
1148 delete network; 1161 delete network;
1149 continue; 1162 continue;
1150 } 1163 }
1151 1164
1152 networks.push_back(network); 1165 networks.push_back(network);
1153 if (!(source == NetworkUIData::ONC_SOURCE_USER_IMPORT && 1166 if (!(source == NetworkUIData::ONC_SOURCE_USER_IMPORT &&
1154 marked_for_removal)) { 1167 marked_for_removal)) {
1155 added_onc_map[network->unique_id()] = parser.GetNetworkConfig(i); 1168 added_onc_map[network->unique_id()] = parser.GetNetworkConfig(i);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 // Set the appropriate profile for |source|. 1211 // Set the appropriate profile for |source|.
1199 if (profile != NULL) 1212 if (profile != NULL)
1200 dict.SetString(flimflam::kProfileProperty, profile->path); 1213 dict.SetString(flimflam::kProfileProperty, profile->path);
1201 1214
1202 // For Ethernet networks, apply them to the current Ethernet service. 1215 // For Ethernet networks, apply them to the current Ethernet service.
1203 if (network->type() == TYPE_ETHERNET) { 1216 if (network->type() == TYPE_ETHERNET) {
1204 const EthernetNetwork* ethernet = ethernet_network(); 1217 const EthernetNetwork* ethernet = ethernet_network();
1205 if (ethernet) { 1218 if (ethernet) {
1206 CallConfigureService(ethernet->unique_id(), &dict); 1219 CallConfigureService(ethernet->unique_id(), &dict);
1207 } else { 1220 } else {
1221 if (error != NULL) {
1222 error->append(l10n_util::GetStringUTF8(
1223 IDS_NETWORK_CONFIG_ERROR_IGNORING_DEVICE_LEVEL_POLICY));
1224 error->append("\n");
1225 }
1208 DLOG(WARNING) << "Tried to import ONC with an Ethernet network when " 1226 DLOG(WARNING) << "Tried to import ONC with an Ethernet network when "
1209 << "there is no active Ethernet connection."; 1227 << "there is no active Ethernet connection.";
1210 } 1228 }
1211 } else { 1229 } else {
1212 CallConfigureService(network->unique_id(), &dict); 1230 CallConfigureService(network->unique_id(), &dict);
1213 } 1231 }
1214 1232
1215 network_ids.insert(network->unique_id()); 1233 network_ids.insert(network->unique_id());
1216 } 1234 }
1217 } 1235 }
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 GetTpmInfo(); 1764 GetTpmInfo();
1747 return tpm_slot_; 1765 return tpm_slot_;
1748 } 1766 }
1749 1767
1750 const std::string& NetworkLibraryImplBase::GetTpmPin() { 1768 const std::string& NetworkLibraryImplBase::GetTpmPin() {
1751 GetTpmInfo(); 1769 GetTpmInfo();
1752 return tpm_pin_; 1770 return tpm_pin_;
1753 } 1771 }
1754 1772
1755 } // namespace chromeos 1773 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698