| 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/onc_network_parser.h" | 5 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
| 6 | 6 |
| 7 #include <keyhi.h> | 7 #include <keyhi.h> |
| 8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
| 12 #include "chrome/browser/chromeos/login/user_manager.h" | 12 #include "chrome/browser/chromeos/login/user_manager.h" |
| 13 #include "base/json/json_writer.h" // for debug output only. | 13 #include "base/json/json_writer.h" // for debug output only. |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/chromeos/cros/certificate_pattern.h" | 16 #include "chrome/browser/chromeos/cros/certificate_pattern.h" |
| 17 #include "chrome/browser/chromeos/cros/cros_library.h" | 17 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 18 #include "chrome/browser/chromeos/cros/native_network_constants.h" | 18 #include "chrome/browser/chromeos/cros/native_network_constants.h" |
| 19 #include "chrome/browser/chromeos/cros/native_network_parser.h" | 19 #include "chrome/browser/chromeos/cros/native_network_parser.h" |
| 20 #include "chrome/browser/chromeos/cros/network_library.h" | 20 #include "chrome/browser/chromeos/cros/network_library.h" |
| 21 #include "chrome/browser/chromeos/cros/onc_constants.h" | 21 #include "chrome/browser/chromeos/cros/onc_constants.h" |
| 22 #include "chrome/browser/chromeos/network_settings/onc_signature.h" |
| 23 #include "chrome/browser/chromeos/network_settings/onc_validator.h" |
| 22 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 24 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 23 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 25 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 24 #include "chrome/common/net/x509_certificate_model.h" | 26 #include "chrome/common/net/x509_certificate_model.h" |
| 25 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 26 #include "crypto/encryptor.h" | 28 #include "crypto/encryptor.h" |
| 27 #include "crypto/hmac.h" | 29 #include "crypto/hmac.h" |
| 28 #include "crypto/scoped_nss_types.h" | 30 #include "crypto/scoped_nss_types.h" |
| 29 #include "crypto/symmetric_key.h" | 31 #include "crypto/symmetric_key.h" |
| 30 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 31 #include "net/base/crypto_module.h" | 33 #include "net/base/crypto_module.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 299 |
| 298 // Check and see if this is an encrypted ONC file. If so, decrypt it. | 300 // Check and see if this is an encrypted ONC file. If so, decrypt it. |
| 299 std::string ciphertext_test; | 301 std::string ciphertext_test; |
| 300 if (root_dict_->GetString("Ciphertext", &ciphertext_test)) | 302 if (root_dict_->GetString("Ciphertext", &ciphertext_test)) |
| 301 root_dict_.reset(Decrypt(passphrase, root_dict_.get())); | 303 root_dict_.reset(Decrypt(passphrase, root_dict_.get())); |
| 302 | 304 |
| 303 // Decryption failed, errors will be in parse_error_; | 305 // Decryption failed, errors will be in parse_error_; |
| 304 if (!root_dict_.get()) | 306 if (!root_dict_.get()) |
| 305 return; | 307 return; |
| 306 | 308 |
| 309 // Validate the ONC dictionary. We are liberal and ignore unknown field |
| 310 // names and ignore invalid field names in kRecommended arrays. |
| 311 bool is_managed = onc_source == NetworkUIData::ONC_SOURCE_USER_POLICY || |
| 312 onc_source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY; |
| 313 scoped_ptr<onc::Validator> validator( |
| 314 new onc::Validator(false, // Ignore unknown fields. |
| 315 false, // Ignore invalid recommended field names. |
| 316 true, // Fail on missing fields. |
| 317 is_managed)); |
| 318 |
| 319 // Unknown fields are removed from the result. |
| 320 root_dict_ = validator->ValidateAndRepairObject( |
| 321 &onc::kUnencryptedConfigurationSignature, |
| 322 *root_dict_); |
| 323 |
| 324 if (!root_dict_.get()) { |
| 325 LOG(WARNING) << "Provided ONC is invalid and couldn't be repaired"; |
| 326 return; |
| 327 } |
| 328 |
| 307 // At least one of NetworkConfigurations or Certificates is required. | 329 // At least one of NetworkConfigurations or Certificates is required. |
| 308 bool has_network_configurations = | 330 bool has_network_configurations = |
| 309 root_dict_->GetList("NetworkConfigurations", &network_configs_); | 331 root_dict_->GetList("NetworkConfigurations", &network_configs_); |
| 310 bool has_certificates = | 332 bool has_certificates = |
| 311 root_dict_->GetList("Certificates", &certificates_); | 333 root_dict_->GetList("Certificates", &certificates_); |
| 312 VLOG(2) << "ONC file has " << GetNetworkConfigsSize() << " networks and " | 334 VLOG(2) << "ONC file has " << GetNetworkConfigsSize() << " networks and " |
| 313 << GetCertificatesSize() << " certificates"; | 335 << GetCertificatesSize() << " certificates"; |
| 314 LOG_IF(WARNING, (!has_network_configurations && !has_certificates)) | 336 LOG_IF(WARNING, (!has_network_configurations && !has_certificates)) |
| 315 << "ONC file has no NetworkConfigurations or Certificates."; | 337 << "ONC file has no NetworkConfigurations or Certificates."; |
| 316 } | 338 } |
| (...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 // on the value of AuthenticationType. | 2052 // on the value of AuthenticationType. |
| 2031 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, | 2053 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, |
| 2032 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, | 2054 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, |
| 2033 }; | 2055 }; |
| 2034 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, | 2056 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, |
| 2035 (table, arraysize(table), PROVIDER_TYPE_MAX)); | 2057 (table, arraysize(table), PROVIDER_TYPE_MAX)); |
| 2036 return parser.Get(type); | 2058 return parser.Get(type); |
| 2037 } | 2059 } |
| 2038 | 2060 |
| 2039 } // namespace chromeos | 2061 } // namespace chromeos |
| OLD | NEW |