OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/policy/network_configuration_updater_impl.h" | 5 #include "chrome/browser/chromeos/policy/network_configuration_updater_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/debug/stack_trace.h" | 11 #include "base/debug/stack_trace.h" |
12 #include "chrome/browser/policy/policy_map.h" | 12 #include "chrome/browser/policy/policy_map.h" |
| 13 #include "chromeos/network/certificate_handler.h" |
13 #include "chromeos/network/managed_network_configuration_handler.h" | 14 #include "chromeos/network/managed_network_configuration_handler.h" |
14 #include "chromeos/network/onc/onc_utils.h" | 15 #include "chromeos/network/onc/onc_utils.h" |
15 #include "policy/policy_constants.h" | 16 #include "policy/policy_constants.h" |
16 | 17 |
17 namespace policy { | 18 namespace policy { |
18 | 19 |
19 NetworkConfigurationUpdaterImpl::NetworkConfigurationUpdaterImpl( | 20 NetworkConfigurationUpdaterImpl::NetworkConfigurationUpdaterImpl( |
20 PolicyService* policy_service) | 21 PolicyService* policy_service, |
| 22 chromeos::ManagedNetworkConfigurationHandler* network_config_handler, |
| 23 chromeos::CertificateHandler* certificate_handler) |
21 : user_policy_initialized_(false), | 24 : user_policy_initialized_(false), |
22 policy_change_registrar_( | 25 policy_change_registrar_( |
23 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())), | 26 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())), |
24 policy_service_(policy_service) { | 27 policy_service_(policy_service), |
| 28 network_config_handler_(network_config_handler), |
| 29 certificate_handler_(certificate_handler) { |
25 policy_change_registrar_.Observe( | 30 policy_change_registrar_.Observe( |
26 key::kDeviceOpenNetworkConfiguration, | 31 key::kDeviceOpenNetworkConfiguration, |
27 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged, | 32 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged, |
28 base::Unretained(this), | 33 base::Unretained(this), |
29 chromeos::onc::ONC_SOURCE_DEVICE_POLICY)); | 34 chromeos::onc::ONC_SOURCE_DEVICE_POLICY)); |
30 policy_change_registrar_.Observe( | 35 policy_change_registrar_.Observe( |
31 key::kOpenNetworkConfiguration, | 36 key::kOpenNetworkConfiguration, |
32 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged, | 37 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged, |
33 base::Unretained(this), | 38 base::Unretained(this), |
34 chromeos::onc::ONC_SOURCE_USER_POLICY)); | 39 chromeos::onc::ONC_SOURCE_USER_POLICY)); |
35 | 40 |
36 ApplyNetworkConfiguration(chromeos::onc::ONC_SOURCE_DEVICE_POLICY); | 41 ApplyNetworkConfiguration(chromeos::onc::ONC_SOURCE_DEVICE_POLICY); |
37 } | 42 } |
38 | 43 |
39 NetworkConfigurationUpdaterImpl::~NetworkConfigurationUpdaterImpl() { | 44 NetworkConfigurationUpdaterImpl::~NetworkConfigurationUpdaterImpl() { |
40 } | 45 } |
41 | 46 |
42 void NetworkConfigurationUpdaterImpl::OnUserPolicyInitialized() { | 47 void NetworkConfigurationUpdaterImpl::OnUserPolicyInitialized() { |
43 VLOG(1) << "User policy initialized."; | 48 VLOG(1) << "User policy initialized."; |
44 user_policy_initialized_ = true; | 49 user_policy_initialized_ = true; |
45 ApplyNetworkConfiguration(chromeos::onc::ONC_SOURCE_USER_POLICY); | 50 ApplyNetworkConfiguration(chromeos::onc::ONC_SOURCE_USER_POLICY); |
46 } | 51 } |
47 | 52 |
48 net::CertTrustAnchorProvider* | |
49 NetworkConfigurationUpdaterImpl::GetCertTrustAnchorProvider() { | |
50 return NULL; | |
51 } | |
52 | |
53 void NetworkConfigurationUpdaterImpl::OnPolicyChanged( | 53 void NetworkConfigurationUpdaterImpl::OnPolicyChanged( |
54 chromeos::onc::ONCSource onc_source, | 54 chromeos::onc::ONCSource onc_source, |
55 const base::Value* previous, | 55 const base::Value* previous, |
56 const base::Value* current) { | 56 const base::Value* current) { |
57 VLOG(1) << "Policy for ONC source " | 57 VLOG(1) << "Policy for ONC source " |
58 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; | 58 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; |
59 VLOG(2) << "User policy is " << (user_policy_initialized_ ? "" : "not ") | 59 VLOG(2) << "User policy is " << (user_policy_initialized_ ? "" : "not ") |
60 << "initialized."; | 60 << "initialized."; |
61 ApplyNetworkConfiguration(onc_source); | 61 ApplyNetworkConfiguration(onc_source); |
62 } | 62 } |
(...skipping 15 matching lines...) Expand all Loading... |
78 | 78 |
79 std::string onc_blob; | 79 std::string onc_blob; |
80 if (policy_value) { | 80 if (policy_value) { |
81 if (!policy_value->GetAsString(&onc_blob)) | 81 if (!policy_value->GetAsString(&onc_blob)) |
82 LOG(ERROR) << "ONC policy " << policy_key << " is not a string value."; | 82 LOG(ERROR) << "ONC policy " << policy_key << " is not a string value."; |
83 } else { | 83 } else { |
84 VLOG(2) << "The policy is not set."; | 84 VLOG(2) << "The policy is not set."; |
85 } | 85 } |
86 VLOG(2) << "The policy contains this ONC: " << onc_blob; | 86 VLOG(2) << "The policy contains this ONC: " << onc_blob; |
87 | 87 |
88 if (onc_blob.empty()) | 88 scoped_ptr<base::ListValue> network_configs; |
89 onc_blob = chromeos::onc::kEmptyUnencryptedConfiguration; | 89 scoped_ptr<base::ListValue> certificates; |
| 90 ParseAndValidateOncForImport( |
| 91 onc_blob, onc_source, "", &network_configs, &certificates); |
90 | 92 |
91 scoped_ptr<base::DictionaryValue> onc_dict = | 93 if (network_configs) |
92 chromeos::onc::ReadDictionaryFromJson(onc_blob); | 94 network_config_handler_->SetPolicy(onc_source, *network_configs); |
93 if (!onc_dict) { | 95 |
94 LOG(ERROR) << "ONC loaded from policy " << policy_key | 96 scoped_ptr<net::CertificateList> web_trust_certs(new net::CertificateList); |
95 << " is not a valid JSON dictionary."; | 97 if (certificates) { |
96 return; | 98 certificate_handler_->ImportCertificates( |
| 99 *certificates, onc_source, web_trust_certs.get()); |
97 } | 100 } |
98 | 101 |
99 chromeos::ManagedNetworkConfigurationHandler::Get()->SetPolicy(onc_source, | 102 if (onc_source == chromeos::onc::ONC_SOURCE_USER_POLICY) |
100 *onc_dict); | 103 SetTrustAnchors(web_trust_certs.Pass()); |
101 } | 104 } |
102 | 105 |
103 } // namespace policy | 106 } // namespace policy |
OLD | NEW |