| 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 "chromeos/network/onc/onc_utils.h" | 5 #include "chromeos/network/onc/onc_utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 if (!field_signature) | 274 if (!field_signature) |
| 275 continue; | 275 continue; |
| 276 | 276 |
| 277 ExpandStringsInOncObject(*field_signature->value_signature, | 277 ExpandStringsInOncObject(*field_signature->value_signature, |
| 278 substitution, inner_object); | 278 substitution, inner_object); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 void ExpandStringsInNetworks(const StringSubstitution& substitution, | 282 void ExpandStringsInNetworks(const StringSubstitution& substitution, |
| 283 base::ListValue* network_configs) { | 283 base::ListValue* network_configs) { |
| 284 for (auto& entry : *network_configs) { | 284 for (const auto& entry : *network_configs) { |
| 285 base::DictionaryValue* network = nullptr; | 285 base::DictionaryValue* network = nullptr; |
| 286 entry.GetAsDictionary(&network); | 286 entry->GetAsDictionary(&network); |
| 287 DCHECK(network); | 287 DCHECK(network); |
| 288 ExpandStringsInOncObject( | 288 ExpandStringsInOncObject( |
| 289 kNetworkConfigurationSignature, substitution, network); | 289 kNetworkConfigurationSignature, substitution, network); |
| 290 } | 290 } |
| 291 } | 291 } |
| 292 | 292 |
| 293 void FillInHexSSIDFieldsInOncObject(const OncValueSignature& signature, | 293 void FillInHexSSIDFieldsInOncObject(const OncValueSignature& signature, |
| 294 base::DictionaryValue* onc_object) { | 294 base::DictionaryValue* onc_object) { |
| 295 if (&signature == &kWiFiSignature) | 295 if (&signature == &kWiFiSignature) |
| 296 FillInHexSSIDField(onc_object); | 296 FillInHexSSIDField(onc_object); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 } | 400 } |
| 401 } | 401 } |
| 402 return decoded; | 402 return decoded; |
| 403 } | 403 } |
| 404 | 404 |
| 405 CertPEMsByGUIDMap GetServerAndCACertsByGUID( | 405 CertPEMsByGUIDMap GetServerAndCACertsByGUID( |
| 406 const base::ListValue& certificates) { | 406 const base::ListValue& certificates) { |
| 407 CertPEMsByGUIDMap certs_by_guid; | 407 CertPEMsByGUIDMap certs_by_guid; |
| 408 for (const auto& entry : certificates) { | 408 for (const auto& entry : certificates) { |
| 409 const base::DictionaryValue* cert = nullptr; | 409 const base::DictionaryValue* cert = nullptr; |
| 410 bool entry_is_dictionary = entry.GetAsDictionary(&cert); | 410 bool entry_is_dictionary = entry->GetAsDictionary(&cert); |
| 411 DCHECK(entry_is_dictionary); | 411 DCHECK(entry_is_dictionary); |
| 412 | 412 |
| 413 std::string guid; | 413 std::string guid; |
| 414 cert->GetStringWithoutPathExpansion(certificate::kGUID, &guid); | 414 cert->GetStringWithoutPathExpansion(certificate::kGUID, &guid); |
| 415 std::string cert_type; | 415 std::string cert_type; |
| 416 cert->GetStringWithoutPathExpansion(certificate::kType, &cert_type); | 416 cert->GetStringWithoutPathExpansion(certificate::kType, &cert_type); |
| 417 if (cert_type != certificate::kServer && | 417 if (cert_type != certificate::kServer && |
| 418 cert_type != certificate::kAuthority) { | 418 cert_type != certificate::kAuthority) { |
| 419 continue; | 419 continue; |
| 420 } | 420 } |
| 421 std::string x509_data; | 421 std::string x509_data; |
| 422 cert->GetStringWithoutPathExpansion(certificate::kX509, &x509_data); | 422 cert->GetStringWithoutPathExpansion(certificate::kX509, &x509_data); |
| 423 | 423 |
| 424 std::string der = DecodePEM(x509_data); | 424 std::string der = DecodePEM(x509_data); |
| 425 std::string pem; | 425 std::string pem; |
| 426 if (der.empty() || !net::X509Certificate::GetPEMEncodedFromDER(der, &pem)) { | 426 if (der.empty() || !net::X509Certificate::GetPEMEncodedFromDER(der, &pem)) { |
| 427 LOG(ERROR) << "Certificate with GUID " << guid | 427 LOG(ERROR) << "Certificate with GUID " << guid |
| 428 << " is not in PEM encoding."; | 428 << " is not in PEM encoding."; |
| 429 continue; | 429 continue; |
| 430 } | 430 } |
| 431 certs_by_guid[guid] = pem; | 431 certs_by_guid[guid] = pem; |
| 432 } | 432 } |
| 433 | 433 |
| 434 return certs_by_guid; | 434 return certs_by_guid; |
| 435 } | 435 } |
| 436 | 436 |
| 437 void FillInHexSSIDFieldsInNetworks(base::ListValue* network_configs) { | 437 void FillInHexSSIDFieldsInNetworks(base::ListValue* network_configs) { |
| 438 for (auto& entry : *network_configs) { | 438 for (const auto& entry : *network_configs) { |
| 439 base::DictionaryValue* network = nullptr; | 439 base::DictionaryValue* network = nullptr; |
| 440 entry.GetAsDictionary(&network); | 440 entry->GetAsDictionary(&network); |
| 441 DCHECK(network); | 441 DCHECK(network); |
| 442 FillInHexSSIDFieldsInOncObject(kNetworkConfigurationSignature, network); | 442 FillInHexSSIDFieldsInOncObject(kNetworkConfigurationSignature, network); |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | 445 |
| 446 } // namespace | 446 } // namespace |
| 447 | 447 |
| 448 bool ParseAndValidateOncForImport(const std::string& onc_blob, | 448 bool ParseAndValidateOncForImport(const std::string& onc_blob, |
| 449 ONCSource onc_source, | 449 ONCSource onc_source, |
| 450 const std::string& passphrase, | 450 const std::string& passphrase, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 base::DictionaryValue* onc_object) { | 596 base::DictionaryValue* onc_object) { |
| 597 const base::ListValue* guid_ref_list = nullptr; | 597 const base::ListValue* guid_ref_list = nullptr; |
| 598 if (!onc_object->GetListWithoutPathExpansion(key_guid_ref_list, | 598 if (!onc_object->GetListWithoutPathExpansion(key_guid_ref_list, |
| 599 &guid_ref_list)) { | 599 &guid_ref_list)) { |
| 600 return true; | 600 return true; |
| 601 } | 601 } |
| 602 | 602 |
| 603 std::unique_ptr<base::ListValue> pem_list(new base::ListValue); | 603 std::unique_ptr<base::ListValue> pem_list(new base::ListValue); |
| 604 for (const auto& entry : *guid_ref_list) { | 604 for (const auto& entry : *guid_ref_list) { |
| 605 std::string guid_ref; | 605 std::string guid_ref; |
| 606 bool entry_is_string = entry.GetAsString(&guid_ref); | 606 bool entry_is_string = entry->GetAsString(&guid_ref); |
| 607 DCHECK(entry_is_string); | 607 DCHECK(entry_is_string); |
| 608 | 608 |
| 609 std::string pem_encoded; | 609 std::string pem_encoded; |
| 610 if (!GUIDRefToPEMEncoding(certs_by_guid, guid_ref, &pem_encoded)) | 610 if (!GUIDRefToPEMEncoding(certs_by_guid, guid_ref, &pem_encoded)) |
| 611 return false; | 611 return false; |
| 612 | 612 |
| 613 pem_list->AppendString(pem_encoded); | 613 pem_list->AppendString(pem_encoded); |
| 614 } | 614 } |
| 615 | 615 |
| 616 onc_object->RemoveWithoutPathExpansion(key_guid_ref_list, nullptr); | 616 onc_object->RemoveWithoutPathExpansion(key_guid_ref_list, nullptr); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 } | 723 } |
| 724 | 724 |
| 725 } // namespace | 725 } // namespace |
| 726 | 726 |
| 727 bool ResolveServerCertRefsInNetworks(const CertPEMsByGUIDMap& certs_by_guid, | 727 bool ResolveServerCertRefsInNetworks(const CertPEMsByGUIDMap& certs_by_guid, |
| 728 base::ListValue* network_configs) { | 728 base::ListValue* network_configs) { |
| 729 bool success = true; | 729 bool success = true; |
| 730 for (base::ListValue::iterator it = network_configs->begin(); | 730 for (base::ListValue::iterator it = network_configs->begin(); |
| 731 it != network_configs->end(); ) { | 731 it != network_configs->end(); ) { |
| 732 base::DictionaryValue* network = nullptr; | 732 base::DictionaryValue* network = nullptr; |
| 733 it->GetAsDictionary(&network); | 733 (*it)->GetAsDictionary(&network); |
| 734 if (!ResolveServerCertRefsInNetwork(certs_by_guid, network)) { | 734 if (!ResolveServerCertRefsInNetwork(certs_by_guid, network)) { |
| 735 std::string guid; | 735 std::string guid; |
| 736 network->GetStringWithoutPathExpansion(network_config::kGUID, &guid); | 736 network->GetStringWithoutPathExpansion(network_config::kGUID, &guid); |
| 737 // This might happen even with correct validation, if the referenced | 737 // This might happen even with correct validation, if the referenced |
| 738 // certificate couldn't be imported. | 738 // certificate couldn't be imported. |
| 739 LOG(ERROR) << "Couldn't resolve some certificate reference of network " | 739 LOG(ERROR) << "Couldn't resolve some certificate reference of network " |
| 740 << guid; | 740 << guid; |
| 741 it = network_configs->Erase(it, nullptr); | 741 it = network_configs->Erase(it, nullptr); |
| 742 success = false; | 742 success = false; |
| 743 continue; | 743 continue; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 ProxyConfigDictionary::EncodeAndAppendProxyServer(url_scheme, proxy_server, | 850 ProxyConfigDictionary::EncodeAndAppendProxyServer(url_scheme, proxy_server, |
| 851 spec); | 851 spec); |
| 852 } | 852 } |
| 853 | 853 |
| 854 net::ProxyBypassRules ConvertOncExcludeDomainsToBypassRules( | 854 net::ProxyBypassRules ConvertOncExcludeDomainsToBypassRules( |
| 855 const base::ListValue& onc_exclude_domains) { | 855 const base::ListValue& onc_exclude_domains) { |
| 856 net::ProxyBypassRules rules; | 856 net::ProxyBypassRules rules; |
| 857 for (base::ListValue::const_iterator it = onc_exclude_domains.begin(); | 857 for (base::ListValue::const_iterator it = onc_exclude_domains.begin(); |
| 858 it != onc_exclude_domains.end(); ++it) { | 858 it != onc_exclude_domains.end(); ++it) { |
| 859 std::string rule; | 859 std::string rule; |
| 860 it->GetAsString(&rule); | 860 (*it)->GetAsString(&rule); |
| 861 rules.AddRuleFromString(rule); | 861 rules.AddRuleFromString(rule); |
| 862 } | 862 } |
| 863 return rules; | 863 return rules; |
| 864 } | 864 } |
| 865 | 865 |
| 866 std::string SchemeToString(net::ProxyServer::Scheme scheme) { | 866 std::string SchemeToString(net::ProxyServer::Scheme scheme) { |
| 867 switch (scheme) { | 867 switch (scheme) { |
| 868 case net::ProxyServer::SCHEME_DIRECT: | 868 case net::ProxyServer::SCHEME_DIRECT: |
| 869 return kDirectScheme; | 869 return kDirectScheme; |
| 870 case net::ProxyServer::SCHEME_HTTP: | 870 case net::ProxyServer::SCHEME_HTTP: |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 namespace { | 1038 namespace { |
| 1039 | 1039 |
| 1040 const base::DictionaryValue* GetNetworkConfigByGUID( | 1040 const base::DictionaryValue* GetNetworkConfigByGUID( |
| 1041 const base::ListValue& network_configs, | 1041 const base::ListValue& network_configs, |
| 1042 const std::string& guid) { | 1042 const std::string& guid) { |
| 1043 for (base::ListValue::const_iterator it = network_configs.begin(); | 1043 for (base::ListValue::const_iterator it = network_configs.begin(); |
| 1044 it != network_configs.end(); ++it) { | 1044 it != network_configs.end(); ++it) { |
| 1045 const base::DictionaryValue* network = NULL; | 1045 const base::DictionaryValue* network = NULL; |
| 1046 it->GetAsDictionary(&network); | 1046 (*it)->GetAsDictionary(&network); |
| 1047 DCHECK(network); | 1047 DCHECK(network); |
| 1048 | 1048 |
| 1049 std::string current_guid; | 1049 std::string current_guid; |
| 1050 network->GetStringWithoutPathExpansion(::onc::network_config::kGUID, | 1050 network->GetStringWithoutPathExpansion(::onc::network_config::kGUID, |
| 1051 ¤t_guid); | 1051 ¤t_guid); |
| 1052 if (current_guid == guid) | 1052 if (current_guid == guid) |
| 1053 return network; | 1053 return network; |
| 1054 } | 1054 } |
| 1055 return NULL; | 1055 return NULL; |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 const base::DictionaryValue* GetNetworkConfigForEthernetWithoutEAP( | 1058 const base::DictionaryValue* GetNetworkConfigForEthernetWithoutEAP( |
| 1059 const base::ListValue& network_configs) { | 1059 const base::ListValue& network_configs) { |
| 1060 VLOG(2) << "Search for ethernet policy without EAP."; | 1060 VLOG(2) << "Search for ethernet policy without EAP."; |
| 1061 for (base::ListValue::const_iterator it = network_configs.begin(); | 1061 for (base::ListValue::const_iterator it = network_configs.begin(); |
| 1062 it != network_configs.end(); ++it) { | 1062 it != network_configs.end(); ++it) { |
| 1063 const base::DictionaryValue* network = NULL; | 1063 const base::DictionaryValue* network = NULL; |
| 1064 it->GetAsDictionary(&network); | 1064 (*it)->GetAsDictionary(&network); |
| 1065 DCHECK(network); | 1065 DCHECK(network); |
| 1066 | 1066 |
| 1067 std::string type; | 1067 std::string type; |
| 1068 network->GetStringWithoutPathExpansion(::onc::network_config::kType, &type); | 1068 network->GetStringWithoutPathExpansion(::onc::network_config::kType, &type); |
| 1069 if (type != ::onc::network_type::kEthernet) | 1069 if (type != ::onc::network_type::kEthernet) |
| 1070 continue; | 1070 continue; |
| 1071 | 1071 |
| 1072 const base::DictionaryValue* ethernet = NULL; | 1072 const base::DictionaryValue* ethernet = NULL; |
| 1073 network->GetDictionaryWithoutPathExpansion(::onc::network_config::kEthernet, | 1073 network->GetDictionaryWithoutPathExpansion(::onc::network_config::kEthernet, |
| 1074 ðernet); | 1074 ðernet); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 user->username_hash()); | 1180 user->username_hash()); |
| 1181 if (!profile) { | 1181 if (!profile) { |
| 1182 *error = "User profile doesn't exist."; | 1182 *error = "User profile doesn't exist."; |
| 1183 return; | 1183 return; |
| 1184 } | 1184 } |
| 1185 | 1185 |
| 1186 bool ethernet_not_found = false; | 1186 bool ethernet_not_found = false; |
| 1187 for (base::ListValue::const_iterator it = expanded_networks->begin(); | 1187 for (base::ListValue::const_iterator it = expanded_networks->begin(); |
| 1188 it != expanded_networks->end(); ++it) { | 1188 it != expanded_networks->end(); ++it) { |
| 1189 const base::DictionaryValue* network = NULL; | 1189 const base::DictionaryValue* network = NULL; |
| 1190 it->GetAsDictionary(&network); | 1190 (*it)->GetAsDictionary(&network); |
| 1191 DCHECK(network); | 1191 DCHECK(network); |
| 1192 | 1192 |
| 1193 // Remove irrelevant fields. | 1193 // Remove irrelevant fields. |
| 1194 onc::Normalizer normalizer(true /* remove recommended fields */); | 1194 onc::Normalizer normalizer(true /* remove recommended fields */); |
| 1195 std::unique_ptr<base::DictionaryValue> normalized_network = | 1195 std::unique_ptr<base::DictionaryValue> normalized_network = |
| 1196 normalizer.NormalizeObject(&onc::kNetworkConfigurationSignature, | 1196 normalizer.NormalizeObject(&onc::kNetworkConfigurationSignature, |
| 1197 *network); | 1197 *network); |
| 1198 | 1198 |
| 1199 // TODO(pneubeck): Use ONC and ManagedNetworkConfigurationHandler instead. | 1199 // TODO(pneubeck): Use ONC and ManagedNetworkConfigurationHandler instead. |
| 1200 // crbug.com/457936 | 1200 // crbug.com/457936 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 const PrefService* local_state_prefs, | 1319 const PrefService* local_state_prefs, |
| 1320 const NetworkState& network) { | 1320 const NetworkState& network) { |
| 1321 ::onc::ONCSource ignored_onc_source; | 1321 ::onc::ONCSource ignored_onc_source; |
| 1322 const base::DictionaryValue* policy = onc::GetPolicyForNetwork( | 1322 const base::DictionaryValue* policy = onc::GetPolicyForNetwork( |
| 1323 profile_prefs, local_state_prefs, network, &ignored_onc_source); | 1323 profile_prefs, local_state_prefs, network, &ignored_onc_source); |
| 1324 return policy != NULL; | 1324 return policy != NULL; |
| 1325 } | 1325 } |
| 1326 | 1326 |
| 1327 } // namespace onc | 1327 } // namespace onc |
| 1328 } // namespace chromeos | 1328 } // namespace chromeos |
| OLD | NEW |