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/metrics/histogram.h" | |
11 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
13 #include "chrome/browser/chromeos/cros/network_constants.h" | 12 #include "chrome/browser/chromeos/cros/network_constants.h" |
14 #include "chrome/browser/chromeos/login/user_manager.h" | 13 #include "chrome/browser/chromeos/login/user_manager.h" |
15 #include "chrome/browser/chromeos/net/onc_utils.h" | 14 #include "chrome/browser/chromeos/net/onc_utils.h" |
16 #include "chrome/browser/chromeos/network_login_observer.h" | 15 #include "chrome/browser/chromeos/network_login_observer.h" |
17 #include "chromeos/network/network_ui_data.h" | 16 #include "chromeos/network/network_ui_data.h" |
18 #include "chromeos/network/onc/onc_certificate_importer.h" | |
19 #include "chromeos/network/onc/onc_constants.h" | 17 #include "chromeos/network/onc/onc_constants.h" |
20 #include "chromeos/network/onc/onc_normalizer.h" | 18 #include "chromeos/network/onc/onc_normalizer.h" |
21 #include "chromeos/network/onc/onc_signature.h" | 19 #include "chromeos/network/onc/onc_signature.h" |
22 #include "chromeos/network/onc/onc_translator.h" | 20 #include "chromeos/network/onc/onc_translator.h" |
23 #include "chromeos/network/onc/onc_utils.h" | 21 #include "chromeos/network/onc/onc_utils.h" |
24 #include "chromeos/network/onc/onc_validator.h" | |
25 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
26 #include "crypto/nss_util.h" // crypto::GetTPMTokenInfo() for 802.1X and VPN. | 23 #include "crypto/nss_util.h" // crypto::GetTPMTokenInfo() for 802.1X and VPN. |
27 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
28 | 25 |
29 using content::BrowserThread; | 26 using content::BrowserThread; |
30 | 27 |
31 namespace chromeos { | 28 namespace chromeos { |
32 | 29 |
33 namespace { | 30 namespace { |
34 | 31 |
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1056 else if (placeholder == onc::substitutes::kEmailField) | 1053 else if (placeholder == onc::substitutes::kEmailField) |
1057 *substitute = logged_in_user->email(); | 1054 *substitute = logged_in_user->email(); |
1058 else | 1055 else |
1059 return false; | 1056 return false; |
1060 return true; | 1057 return true; |
1061 } | 1058 } |
1062 }; | 1059 }; |
1063 | 1060 |
1064 } // namespace | 1061 } // namespace |
1065 | 1062 |
1066 bool NetworkLibraryImplBase::LoadOncNetworks( | 1063 void NetworkLibraryImplBase::LoadOncNetworks( |
1067 const std::string& onc_blob, | 1064 const base::ListValue& network_configs, |
1068 const std::string& passphrase, | 1065 onc::ONCSource source) { |
1069 onc::ONCSource source, | 1066 VLOG(2) << __func__ << ": called on " << network_configs; |
1070 net::CertificateList* onc_trusted_certificates) { | |
1071 VLOG(2) << __func__ << ": called on " << onc_blob; | |
1072 NetworkProfile* profile = NULL; | 1067 NetworkProfile* profile = NULL; |
1073 bool from_policy = (source == onc::ONC_SOURCE_USER_POLICY || | 1068 bool from_policy = (source == onc::ONC_SOURCE_USER_POLICY || |
1074 source == onc::ONC_SOURCE_DEVICE_POLICY); | 1069 source == onc::ONC_SOURCE_DEVICE_POLICY); |
1075 | 1070 |
1076 // Policies are applied to a specific Shill profile. User ONC import however | 1071 // Policies are applied to a specific Shill profile. User ONC import however |
1077 // is applied to whatever profile Shill chooses. This should be the profile | 1072 // is applied to whatever profile Shill chooses. This should be the profile |
1078 // that is already associated with a network and if no profile is associated | 1073 // that is already associated with a network and if no profile is associated |
1079 // yet, it should be the user profile. | 1074 // yet, it should be the user profile. |
1080 if (from_policy) { | 1075 if (from_policy) { |
1081 profile = GetProfileForType(GetProfileTypeForSource(source)); | 1076 profile = GetProfileForType(GetProfileTypeForSource(source)); |
1082 if (profile == NULL) { | 1077 if (profile == NULL) { |
1083 VLOG(2) << "Profile for ONC source " << onc::GetSourceAsString(source) | 1078 VLOG(2) << "Profile for ONC source " << onc::GetSourceAsString(source) |
1084 << " doesn't exist."; | 1079 << " doesn't exist."; |
1085 return true; | 1080 return; |
1086 } | |
1087 } | |
1088 | |
1089 scoped_ptr<base::DictionaryValue> root_dict = | |
1090 onc::ReadDictionaryFromJson(onc_blob); | |
1091 if (root_dict.get() == NULL) { | |
1092 LOG(ERROR) << "ONC loaded from " << onc::GetSourceAsString(source) | |
1093 << " is not a valid JSON dictionary."; | |
1094 return false; | |
1095 } | |
1096 | |
1097 // Check and see if this is an encrypted ONC file. If so, decrypt it. | |
1098 std::string onc_type; | |
1099 root_dict->GetStringWithoutPathExpansion(onc::toplevel_config::kType, | |
1100 &onc_type); | |
1101 if (onc_type == onc::toplevel_config::kEncryptedConfiguration) { | |
1102 root_dict = onc::Decrypt(passphrase, *root_dict); | |
1103 if (root_dict.get() == NULL) { | |
1104 LOG(ERROR) << "Couldn't decrypt the ONC from " | |
1105 << onc::GetSourceAsString(source); | |
1106 return false; | |
1107 } | |
1108 } | |
1109 | |
1110 // Validate the ONC dictionary. We are liberal and ignore unknown field | |
1111 // names and ignore invalid field names in kRecommended arrays. | |
1112 onc::Validator validator(false, // Ignore unknown fields. | |
1113 false, // Ignore invalid recommended field names. | |
1114 true, // Fail on missing fields. | |
1115 from_policy); | |
1116 validator.SetOncSource(source); | |
1117 | |
1118 onc::Validator::Result validation_result; | |
1119 root_dict = validator.ValidateAndRepairObject( | |
1120 &onc::kToplevelConfigurationSignature, | |
1121 *root_dict, | |
1122 &validation_result); | |
1123 | |
1124 if (from_policy) { | |
1125 UMA_HISTOGRAM_BOOLEAN("Enterprise.ONC.PolicyValidation", | |
1126 validation_result == onc::Validator::VALID); | |
1127 } | |
1128 | |
1129 bool success = true; | |
1130 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) { | |
1131 LOG(WARNING) << "ONC from " << onc::GetSourceAsString(source) | |
1132 << " produced warnings."; | |
1133 success = false; | |
1134 } else if (validation_result == onc::Validator::INVALID || | |
1135 root_dict == NULL) { | |
1136 LOG(ERROR) << "ONC from " << onc::GetSourceAsString(source) | |
1137 << " is invalid and couldn't be repaired."; | |
1138 return false; | |
1139 } | |
1140 | |
1141 const base::ListValue* certificates; | |
1142 bool has_certificates = | |
1143 root_dict->GetListWithoutPathExpansion( | |
1144 onc::toplevel_config::kCertificates, | |
1145 &certificates); | |
1146 | |
1147 const base::ListValue* network_configs; | |
1148 bool has_network_configurations = root_dict->GetListWithoutPathExpansion( | |
1149 onc::toplevel_config::kNetworkConfigurations, | |
1150 &network_configs); | |
1151 | |
1152 if (has_certificates) { | |
1153 VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates"; | |
1154 | |
1155 // Web trust is only granted to certificates imported by the user. | |
1156 bool allow_trust_imports = source == onc::ONC_SOURCE_USER_IMPORT; | |
1157 onc::CertificateImporter cert_importer(allow_trust_imports); | |
1158 if (cert_importer.ParseAndStoreCertificates( | |
1159 *certificates, onc_trusted_certificates) != | |
1160 onc::CertificateImporter::IMPORT_OK) { | |
1161 LOG(ERROR) << "Cannot parse some of the certificates in the ONC from " | |
1162 << onc::GetSourceAsString(source); | |
1163 success = false; | |
1164 } | 1081 } |
1165 } | 1082 } |
1166 | 1083 |
1167 std::set<std::string> removal_ids; | 1084 std::set<std::string> removal_ids; |
1168 std::set<std::string>& network_ids(network_source_map_[source]); | 1085 std::set<std::string>& network_ids(network_source_map_[source]); |
1169 network_ids.clear(); | 1086 network_ids.clear(); |
1170 if (has_network_configurations) { | 1087 if (true) { |
Joao da Silva
2013/04/22 10:38:09
?
pneubeck (no reviews)
2013/04/23 18:05:25
Done.
| |
1171 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; | 1088 VLOG(2) << "ONC file has " << network_configs.GetSize() << " networks"; |
1172 for (base::ListValue::const_iterator it(network_configs->begin()); | 1089 for (base::ListValue::const_iterator it(network_configs.begin()); |
1173 it != network_configs->end(); ++it) { | 1090 it != network_configs.end(); ++it) { |
1174 const base::DictionaryValue* network; | 1091 const base::DictionaryValue* network; |
1175 (*it)->GetAsDictionary(&network); | 1092 (*it)->GetAsDictionary(&network); |
1176 | 1093 |
1177 bool marked_for_removal = false; | 1094 bool marked_for_removal = false; |
1178 network->GetBooleanWithoutPathExpansion(onc::kRemove, | 1095 network->GetBooleanWithoutPathExpansion(onc::kRemove, |
1179 &marked_for_removal); | 1096 &marked_for_removal); |
1180 | 1097 |
1181 std::string type; | 1098 std::string type; |
1182 network->GetStringWithoutPathExpansion(onc::network_config::kType, &type); | 1099 network->GetStringWithoutPathExpansion(onc::network_config::kType, &type); |
1183 | 1100 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1272 | 1189 |
1273 if (from_policy) { | 1190 if (from_policy) { |
1274 // For policy-managed networks, go through the list of existing remembered | 1191 // For policy-managed networks, go through the list of existing remembered |
1275 // networks and clean out the ones that no longer have a definition in the | 1192 // networks and clean out the ones that no longer have a definition in the |
1276 // ONC blob. We first collect the networks and do the actual deletion later | 1193 // ONC blob. We first collect the networks and do the actual deletion later |
1277 // because ForgetNetwork() changes the remembered network vectors. | 1194 // because ForgetNetwork() changes the remembered network vectors. |
1278 ForgetNetworksById(source, network_ids, false); | 1195 ForgetNetworksById(source, network_ids, false); |
1279 } else if (source == onc::ONC_SOURCE_USER_IMPORT && !removal_ids.empty()) { | 1196 } else if (source == onc::ONC_SOURCE_USER_IMPORT && !removal_ids.empty()) { |
1280 ForgetNetworksById(source, removal_ids, true); | 1197 ForgetNetworksById(source, removal_ids, true); |
1281 } | 1198 } |
1282 | |
1283 return success; | |
1284 } | 1199 } |
1285 | 1200 |
1286 //////////////////////////////////////////////////////////////////////////// | 1201 //////////////////////////////////////////////////////////////////////////// |
1287 // Testing functions. | 1202 // Testing functions. |
1288 | 1203 |
1289 bool NetworkLibraryImplBase::SetActiveNetwork( | 1204 bool NetworkLibraryImplBase::SetActiveNetwork( |
1290 ConnectionType type, const std::string& service_path) { | 1205 ConnectionType type, const std::string& service_path) { |
1291 Network* network = NULL; | 1206 Network* network = NULL; |
1292 if (!service_path.empty()) | 1207 if (!service_path.empty()) |
1293 network = FindNetworkByPath(service_path); | 1208 network = FindNetworkByPath(service_path); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1797 GetTpmInfo(); | 1712 GetTpmInfo(); |
1798 return tpm_slot_; | 1713 return tpm_slot_; |
1799 } | 1714 } |
1800 | 1715 |
1801 const std::string& NetworkLibraryImplBase::GetTpmPin() { | 1716 const std::string& NetworkLibraryImplBase::GetTpmPin() { |
1802 GetTpmInfo(); | 1717 GetTpmInfo(); |
1803 return tpm_pin_; | 1718 return tpm_pin_; |
1804 } | 1719 } |
1805 | 1720 |
1806 } // namespace chromeos | 1721 } // namespace chromeos |
OLD | NEW |