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

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

Issue 11469026: Extending ONC validator's logging. Completing toplevel validation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@add_error_handling_to_validator
Patch Set: Rebased (don't reject policies by onc::Validator). 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/metrics/histogram.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 #include "chrome/browser/chromeos/cros/native_network_parser.h" 12 #include "chrome/browser/chromeos/cros/native_network_parser.h"
12 #include "chrome/browser/chromeos/cros/onc_network_parser.h" 13 #include "chrome/browser/chromeos/cros/onc_network_parser.h"
13 #include "chrome/browser/chromeos/network_login_observer.h" 14 #include "chrome/browser/chromeos/network_login_observer.h"
14 #include "chromeos/network/onc/onc_certificate_importer.h" 15 #include "chromeos/network/onc/onc_certificate_importer.h"
15 #include "chromeos/network/onc/onc_constants.h" 16 #include "chromeos/network/onc/onc_constants.h"
16 #include "chromeos/network/onc/onc_signature.h" 17 #include "chromeos/network/onc/onc_signature.h"
17 #include "chromeos/network/onc/onc_utils.h" 18 #include "chromeos/network/onc/onc_utils.h"
18 #include "chromeos/network/onc/onc_validator.h" 19 #include "chromeos/network/onc/onc_validator.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 ConnectToWifiNetwork(wifi); 1019 ConnectToWifiNetwork(wifi);
1019 break; 1020 break;
1020 } 1021 }
1021 } 1022 }
1022 } 1023 }
1023 1024
1024 bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, 1025 bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
1025 const std::string& passphrase, 1026 const std::string& passphrase,
1026 onc::ONCSource source, 1027 onc::ONCSource source,
1027 bool allow_web_trust_from_policy) { 1028 bool allow_web_trust_from_policy) {
1029 VLOG(2) << __func__ << ": called on " << onc_blob;
1028 NetworkProfile* profile = NULL; 1030 NetworkProfile* profile = NULL;
1029 bool from_policy = (source == onc::ONC_SOURCE_USER_POLICY || 1031 bool from_policy = (source == onc::ONC_SOURCE_USER_POLICY ||
1030 source == onc::ONC_SOURCE_DEVICE_POLICY); 1032 source == onc::ONC_SOURCE_DEVICE_POLICY);
1031 1033
1032 // Policies are applied to a specific Shill profile. User ONC import however 1034 // 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 1035 // 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 1036 // that is already associated with a network and if no profile is associated
1035 // yet, it should be the user profile. 1037 // yet, it should be the user profile.
1036 if (from_policy) { 1038 if (from_policy) {
1037 profile = GetProfileForType(GetProfileTypeForSource(source)); 1039 profile = GetProfileForType(GetProfileTypeForSource(source));
1038 if (profile == NULL) { 1040 if (profile == NULL) {
1039 DLOG(WARNING) << "Profile for ONC source " 1041 VLOG(2) << "Profile for ONC source " << onc::GetSourceAsString(source)
1040 << onc::GetSourceAsString(source) 1042 << " doesn't exist.";
1041 << " doesn't exist."; 1043 return true;
1042 return false;
1043 } 1044 }
1044 } 1045 }
1045 1046
1046 VLOG(2) << __func__ << ": called on " << onc_blob;
1047 scoped_ptr<base::DictionaryValue> root_dict = 1047 scoped_ptr<base::DictionaryValue> root_dict =
1048 onc::ReadDictionaryFromJson(onc_blob); 1048 onc::ReadDictionaryFromJson(onc_blob);
1049 if (root_dict.get() == NULL) { 1049 if (root_dict.get() == NULL) {
1050 LOG(WARNING) << "ONC loaded from " << onc::GetSourceAsString(source) 1050 LOG(ERROR) << "ONC loaded from " << onc::GetSourceAsString(source)
1051 << " is not a valid JSON dictionary."; 1051 << " is not a valid JSON dictionary.";
1052 return false; 1052 return false;
1053 } 1053 }
1054 1054
1055 // Check and see if this is an encrypted ONC file. If so, decrypt it. 1055 // Check and see if this is an encrypted ONC file. If so, decrypt it.
1056 std::string onc_type; 1056 std::string onc_type;
1057 root_dict->GetStringWithoutPathExpansion(onc::kType, &onc_type); 1057 root_dict->GetStringWithoutPathExpansion(onc::kType, &onc_type);
1058 if (onc_type == onc::kEncryptedConfiguration) { 1058 if (onc_type == onc::kEncryptedConfiguration) {
1059 root_dict = onc::Decrypt(passphrase, *root_dict); 1059 root_dict = onc::Decrypt(passphrase, *root_dict);
1060 if (root_dict.get() == NULL) { 1060 if (root_dict.get() == NULL) {
1061 LOG(WARNING) << "Couldn't decrypt the ONC from " 1061 LOG(ERROR) << "Couldn't decrypt the ONC from "
1062 << onc::GetSourceAsString(source); 1062 << onc::GetSourceAsString(source);
1063 return false; 1063 return false;
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. 1074 // Unknown fields are removed from the result.
1075 root_dict = validator.ValidateAndRepairObject( 1075 onc::Validator::Result validation_result;
1076 &onc::kUnencryptedConfigurationSignature, 1076 validator.ValidateAndRepairObject(&onc::kToplevelConfigurationSignature,
1077 *root_dict); 1077 *root_dict,
1078 &validation_result);
1078 1079
1079 if (root_dict.get() == NULL) { 1080 if (from_policy) {
1080 LOG(WARNING) << "ONC from source " << source 1081 UMA_HISTOGRAM_BOOLEAN("Enterprise.ONC.PolicyValidation",
1081 << " is invalid and couldn't be repaired."; 1082 validation_result == onc::Validator::VALID);
1082 return false; 1083 }
1084
1085 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) {
1086 LOG(WARNING) << "ONC from " << onc::GetSourceAsString(source)
1087 << " produced warnings.";
1088 } else if (validation_result == onc::Validator::INVALID) {
1089 LOG(ERROR) << "ONC from " << onc::GetSourceAsString(source)
1090 << " is invalid and couldn't be repaired.";
1083 } 1091 }
1084 1092
1085 const base::ListValue* certificates; 1093 const base::ListValue* certificates;
1086 bool has_certificates = 1094 bool has_certificates =
1087 root_dict->GetListWithoutPathExpansion(onc::kCertificates, &certificates); 1095 root_dict->GetListWithoutPathExpansion(onc::kCertificates, &certificates);
1088 1096
1089 const base::ListValue* network_configs; 1097 const base::ListValue* network_configs;
1090 bool has_network_configurations = root_dict->GetListWithoutPathExpansion( 1098 bool has_network_configurations = root_dict->GetListWithoutPathExpansion(
1091 onc::kNetworkConfigurations, 1099 onc::kNetworkConfigurations,
1092 &network_configs); 1100 &network_configs);
1093 1101
1094 // At least one of NetworkConfigurations or Certificates is required.
1095 LOG_IF(WARNING, (!has_network_configurations && !has_certificates))
1096 << "ONC from source " << source
1097 << " has neither NetworkConfigurations nor Certificates.";
1098
1099 if (has_certificates) { 1102 if (has_certificates) {
1100 VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates"; 1103 VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates";
1101 1104
1102 onc::CertificateImporter cert_importer(source, allow_web_trust_from_policy); 1105 onc::CertificateImporter cert_importer(source, allow_web_trust_from_policy);
1103 if (cert_importer.ParseAndStoreCertificates(*certificates) != 1106 if (cert_importer.ParseAndStoreCertificates(*certificates) !=
1104 onc::CertificateImporter::IMPORT_OK) { 1107 onc::CertificateImporter::IMPORT_OK) {
1105 LOG(WARNING) << "Cannot parse some of the certificates in the ONC from " 1108 LOG(ERROR) << "Cannot parse some of the certificates in the ONC from "
1106 << onc::GetSourceAsString(source); 1109 << onc::GetSourceAsString(source);
1107 return false; 1110 return false;
1108 } 1111 }
1109 } 1112 }
1110 1113
1111 std::set<std::string> removal_ids; 1114 std::set<std::string> removal_ids;
1112 std::set<std::string>& network_ids(network_source_map_[source]); 1115 std::set<std::string>& network_ids(network_source_map_[source]);
1113 network_ids.clear(); 1116 network_ids.clear();
1114 if (has_network_configurations) { 1117 if (has_network_configurations) {
1115 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; 1118 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks";
1116 OncNetworkParser parser(*network_configs, source); 1119 OncNetworkParser parser(*network_configs, source);
1117 1120
1118 // Parse all networks. Bail out if that fails. 1121 // Parse all networks. Bail out if that fails.
1119 NetworkOncMap added_onc_map; 1122 NetworkOncMap added_onc_map;
1120 ScopedVector<Network> networks; 1123 ScopedVector<Network> networks;
1121 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { 1124 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) {
1122 // Parse Open Network Configuration blob into a temporary Network object. 1125 // Parse Open Network Configuration blob into a temporary Network object.
1123 bool marked_for_removal = false; 1126 bool marked_for_removal = false;
1124 Network* network = parser.ParseNetwork(i, &marked_for_removal); 1127 Network* network = parser.ParseNetwork(i, &marked_for_removal);
1125 if (!network) { 1128 if (!network) {
1126 LOG(WARNING) << "Error during parsing network at index " << i 1129 LOG(ERROR) << "Error during ONC parsing network at index " << i
1127 << " from ONC source " << onc::GetSourceAsString(source); 1130 << " from " << onc::GetSourceAsString(source);
1128 return false; 1131 return false;
1129 } 1132 }
1130 1133
1131 // Disallow anything but WiFi and Ethernet for device-level policy (which 1134 // Disallow anything but WiFi and Ethernet for device-level policy (which
1132 // corresponds to shared networks). See also http://crosbug.com/28741. 1135 // corresponds to shared networks). See also http://crosbug.com/28741.
1133 if (source == onc::ONC_SOURCE_DEVICE_POLICY && 1136 if (source == onc::ONC_SOURCE_DEVICE_POLICY &&
1134 network->type() != TYPE_WIFI && 1137 network->type() != TYPE_WIFI &&
1135 network->type() != TYPE_ETHERNET) { 1138 network->type() != TYPE_ETHERNET) {
1136 LOG(WARNING) << "Ignoring device-level policy-pushed network of type " 1139 LOG(WARNING) << "Ignoring device-level policy-pushed network of type "
1137 << network->type(); 1140 << network->type();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 // Set the appropriate profile for |source|. 1191 // Set the appropriate profile for |source|.
1189 if (profile != NULL) 1192 if (profile != NULL)
1190 dict.SetString(flimflam::kProfileProperty, profile->path); 1193 dict.SetString(flimflam::kProfileProperty, profile->path);
1191 1194
1192 // For Ethernet networks, apply them to the current Ethernet service. 1195 // For Ethernet networks, apply them to the current Ethernet service.
1193 if (network->type() == TYPE_ETHERNET) { 1196 if (network->type() == TYPE_ETHERNET) {
1194 const EthernetNetwork* ethernet = ethernet_network(); 1197 const EthernetNetwork* ethernet = ethernet_network();
1195 if (ethernet) { 1198 if (ethernet) {
1196 CallConfigureService(ethernet->unique_id(), &dict); 1199 CallConfigureService(ethernet->unique_id(), &dict);
1197 } else { 1200 } else {
1198 DLOG(WARNING) << "Tried to import ONC with an Ethernet network when " 1201 LOG(WARNING) << "Tried to import ONC with an Ethernet network when "
1199 << "there is no active Ethernet connection."; 1202 << "there is no active Ethernet connection.";
1200 } 1203 }
1201 } else { 1204 } else {
1202 CallConfigureService(network->unique_id(), &dict); 1205 CallConfigureService(network->unique_id(), &dict);
1203 } 1206 }
1204 1207
1205 network_ids.insert(network->unique_id()); 1208 network_ids.insert(network->unique_id());
1206 } 1209 }
1207 } 1210 }
1208 1211
1209 if (from_policy) { 1212 if (from_policy) {
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 GetTpmInfo(); 1739 GetTpmInfo();
1737 return tpm_slot_; 1740 return tpm_slot_;
1738 } 1741 }
1739 1742
1740 const std::string& NetworkLibraryImplBase::GetTpmPin() { 1743 const std::string& NetworkLibraryImplBase::GetTpmPin() {
1741 GetTpmInfo(); 1744 GetTpmInfo();
1742 return tpm_pin_; 1745 return tpm_pin_;
1743 } 1746 }
1744 1747
1745 } // namespace chromeos 1748 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698