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/policy/network_configuration_updater.h" | 5 #include "chrome/browser/chromeos/policy/network_configuration_updater.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/command_line.h" |
| 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/browser/chromeos/cros/network_library.h" | 14 #include "chrome/browser/chromeos/cros/network_library.h" |
12 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
| 16 #include "chrome/common/chrome_switches.h" |
13 #include "chromeos/network/onc/onc_constants.h" | 17 #include "chromeos/network/onc/onc_constants.h" |
14 #include "chromeos/network/onc/onc_utils.h" | 18 #include "chromeos/network/onc/onc_utils.h" |
| 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "net/cert/cert_trust_anchor_provider.h" |
| 21 #include "net/cert/x509_certificate.h" |
15 #include "policy/policy_constants.h" | 22 #include "policy/policy_constants.h" |
16 | 23 |
| 24 using content::BrowserThread; |
| 25 |
17 namespace policy { | 26 namespace policy { |
18 | 27 |
| 28 namespace { |
| 29 |
| 30 // A simple implementation of net::CertTrustAnchorProvider that returns a list |
| 31 // of certificates that can be set by the owner of this object. |
| 32 class CrosTrustAnchorProvider : public net::CertTrustAnchorProvider { |
| 33 public: |
| 34 CrosTrustAnchorProvider() {} |
| 35 virtual ~CrosTrustAnchorProvider() {} |
| 36 |
| 37 // CertTrustAnchorProvider overrides. |
| 38 virtual const net::CertificateList& GetAdditionalTrustAnchors() OVERRIDE { |
| 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 40 return trust_anchors_; |
| 41 } |
| 42 |
| 43 void SetTrustAnchors(scoped_ptr<net::CertificateList> trust_anchors) { |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 45 trust_anchors_.swap(*trust_anchors); |
| 46 } |
| 47 |
| 48 private: |
| 49 net::CertificateList trust_anchors_; |
| 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(CrosTrustAnchorProvider); |
| 52 }; |
| 53 |
| 54 } // namespace |
| 55 |
19 NetworkConfigurationUpdater::NetworkConfigurationUpdater( | 56 NetworkConfigurationUpdater::NetworkConfigurationUpdater( |
20 PolicyService* policy_service, | 57 PolicyService* policy_service, |
21 chromeos::NetworkLibrary* network_library) | 58 chromeos::NetworkLibrary* network_library) |
22 : policy_change_registrar_( | 59 : policy_change_registrar_( |
23 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())), | 60 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())), |
24 network_library_(network_library), | 61 network_library_(network_library), |
25 user_policy_initialized_(false), | 62 user_policy_initialized_(false), |
26 allow_web_trust_(false), | 63 allow_trusted_certificates_from_policy_(false), |
27 policy_service_(policy_service) { | 64 policy_service_(policy_service), |
| 65 cert_trust_provider_(new CrosTrustAnchorProvider()) { |
28 DCHECK(network_library_); | 66 DCHECK(network_library_); |
29 policy_change_registrar_.Observe( | 67 policy_change_registrar_.Observe( |
30 key::kDeviceOpenNetworkConfiguration, | 68 key::kDeviceOpenNetworkConfiguration, |
31 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, | 69 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, |
32 base::Unretained(this), | 70 base::Unretained(this), |
33 chromeos::onc::ONC_SOURCE_DEVICE_POLICY)); | 71 chromeos::onc::ONC_SOURCE_DEVICE_POLICY)); |
34 policy_change_registrar_.Observe( | 72 policy_change_registrar_.Observe( |
35 key::kOpenNetworkConfiguration, | 73 key::kOpenNetworkConfiguration, |
36 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, | 74 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, |
37 base::Unretained(this), | 75 base::Unretained(this), |
38 chromeos::onc::ONC_SOURCE_USER_POLICY)); | 76 chromeos::onc::ONC_SOURCE_USER_POLICY)); |
39 | 77 |
40 network_library_->AddNetworkProfileObserver(this); | 78 network_library_->AddNetworkProfileObserver(this); |
41 | 79 |
42 // Apply the current policies immediately. | 80 // Apply the current policies immediately. |
43 ApplyNetworkConfigurations(); | 81 ApplyNetworkConfigurations(); |
44 } | 82 } |
45 | 83 |
46 NetworkConfigurationUpdater::~NetworkConfigurationUpdater() { | 84 NetworkConfigurationUpdater::~NetworkConfigurationUpdater() { |
47 network_library_->RemoveNetworkProfileObserver(this); | 85 network_library_->RemoveNetworkProfileObserver(this); |
| 86 bool posted = BrowserThread::DeleteSoon( |
| 87 BrowserThread::IO, FROM_HERE, cert_trust_provider_); |
| 88 if (!posted) |
| 89 delete cert_trust_provider_; |
48 } | 90 } |
49 | 91 |
50 void NetworkConfigurationUpdater::OnProfileListChanged() { | 92 void NetworkConfigurationUpdater::OnProfileListChanged() { |
51 VLOG(1) << "Network profile list changed, applying policies."; | 93 VLOG(1) << "Network profile list changed, applying policies."; |
52 ApplyNetworkConfigurations(); | 94 ApplyNetworkConfigurations(); |
53 } | 95 } |
54 | 96 |
55 void NetworkConfigurationUpdater::OnUserPolicyInitialized() { | 97 void NetworkConfigurationUpdater::OnUserPolicyInitialized() { |
56 VLOG(1) << "User policy initialized, applying policies."; | 98 VLOG(1) << "User policy initialized, applying policies."; |
57 user_policy_initialized_ = true; | 99 user_policy_initialized_ = true; |
58 ApplyNetworkConfigurations(); | 100 ApplyNetworkConfigurations(); |
59 } | 101 } |
60 | 102 |
| 103 net::CertTrustAnchorProvider* |
| 104 NetworkConfigurationUpdater::GetCertTrustAnchorProvider() { |
| 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 106 return cert_trust_provider_; |
| 107 } |
| 108 |
61 void NetworkConfigurationUpdater::OnPolicyChanged( | 109 void NetworkConfigurationUpdater::OnPolicyChanged( |
62 chromeos::onc::ONCSource onc_source, | 110 chromeos::onc::ONCSource onc_source, |
63 const base::Value* previous, | 111 const base::Value* previous, |
64 const base::Value* current) { | 112 const base::Value* current) { |
65 VLOG(1) << "Policy for ONC source " | 113 VLOG(1) << "Policy for ONC source " |
66 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; | 114 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; |
67 ApplyNetworkConfigurations(); | 115 ApplyNetworkConfigurations(); |
68 } | 116 } |
69 | 117 |
70 void NetworkConfigurationUpdater::ApplyNetworkConfigurations() { | 118 void NetworkConfigurationUpdater::ApplyNetworkConfigurations() { |
(...skipping 23 matching lines...) Expand all Loading... |
94 << chromeos::onc::GetSourceAsString(onc_source) | 142 << chromeos::onc::GetSourceAsString(onc_source) |
95 << " is not a string value."; | 143 << " is not a string value."; |
96 } | 144 } |
97 } | 145 } |
98 | 146 |
99 // An empty string is not a valid ONC and generates warnings and | 147 // An empty string is not a valid ONC and generates warnings and |
100 // errors. Replace by a valid empty configuration. | 148 // errors. Replace by a valid empty configuration. |
101 if (new_network_config.empty()) | 149 if (new_network_config.empty()) |
102 new_network_config = chromeos::onc::kEmptyUnencryptedConfiguration; | 150 new_network_config = chromeos::onc::kEmptyUnencryptedConfiguration; |
103 | 151 |
| 152 scoped_ptr<net::CertificateList> web_trust_certs(new net::CertificateList()); |
104 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source, | 153 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source, |
105 allow_web_trust_)) { | 154 web_trust_certs.get())) { |
106 LOG(ERROR) << "Errors occurred during the ONC policy application."; | 155 LOG(ERROR) << "Errors occurred during the ONC policy application."; |
107 } | 156 } |
| 157 |
| 158 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 159 if (onc_source == chromeos::onc::ONC_SOURCE_USER_POLICY && |
| 160 allow_trusted_certificates_from_policy_ && |
| 161 command_line->HasSwitch(switches::kEnableWebTrustCerts)) { |
| 162 BrowserThread::PostTask( |
| 163 BrowserThread::IO, FROM_HERE, |
| 164 base::Bind(&CrosTrustAnchorProvider::SetTrustAnchors, |
| 165 base::Unretained(static_cast<CrosTrustAnchorProvider*>( |
| 166 cert_trust_provider_)), |
| 167 base::Passed(&web_trust_certs))); |
| 168 } |
108 } | 169 } |
109 | 170 |
110 } // namespace policy | 171 } // namespace policy |
OLD | NEW |