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/base/cert_trust_anchor_provider.h" | |
21 #include "net/base/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 // A simple implementation of net::CertTrustAnchorProvider that returns a list | |
29 // of certificates that can be set by the owner of this object. | |
30 class NetworkConfigurationUpdater::CertTrustAnchorProviderImpl | |
Ryan Sleevi
2013/03/25 21:09:53
*mostly* a nit, but I'm inclined to suggest you ju
Joao da Silva
2013/03/31 19:22:14
Done.
| |
31 : public net::CertTrustAnchorProvider { | |
32 public: | |
33 CertTrustAnchorProviderImpl() {} | |
34 virtual ~CertTrustAnchorProviderImpl() {} | |
35 | |
36 // CertTrustAnchorProvider: | |
pneubeck (no reviews)
2013/03/26 10:01:25
in the header the syntax
Cert..Provider override
Joao da Silva
2013/03/31 19:22:14
Done.
| |
37 virtual const net::CertificateList& GetAdditionalTrustAnchors() OVERRIDE { | |
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
39 return trust_anchors_; | |
40 } | |
41 | |
42 void SetTrustAnchors(scoped_ptr<net::CertificateList> trust_anchors) { | |
Ryan Sleevi
2013/03/25 21:09:53
Why are you passing a pointer? Just use a
"const n
Joao da Silva
2013/03/31 19:22:14
The list is passed from the UI thread to the IO th
| |
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
44 trust_anchors_.swap(*trust_anchors); | |
45 } | |
46 | |
47 private: | |
48 net::CertificateList trust_anchors_; | |
49 | |
50 DISALLOW_COPY_AND_ASSIGN(CertTrustAnchorProviderImpl); | |
51 }; | |
52 | |
19 NetworkConfigurationUpdater::NetworkConfigurationUpdater( | 53 NetworkConfigurationUpdater::NetworkConfigurationUpdater( |
20 PolicyService* policy_service, | 54 PolicyService* policy_service, |
21 chromeos::NetworkLibrary* network_library) | 55 chromeos::NetworkLibrary* network_library) |
22 : policy_change_registrar_( | 56 : policy_change_registrar_( |
23 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())), | 57 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())), |
24 network_library_(network_library), | 58 network_library_(network_library), |
25 user_policy_initialized_(false), | 59 user_policy_initialized_(false), |
26 allow_web_trust_(false), | 60 allow_web_trust_(false), |
27 policy_service_(policy_service) { | 61 policy_service_(policy_service), |
62 cert_trust_provider_(NULL) { | |
pneubeck (no reviews)
2013/03/26 10:01:25
Just create it here.
Makes the code below a bit si
Joao da Silva
2013/03/31 19:22:14
Done.
| |
28 DCHECK(network_library_); | 63 DCHECK(network_library_); |
29 policy_change_registrar_.Observe( | 64 policy_change_registrar_.Observe( |
30 key::kDeviceOpenNetworkConfiguration, | 65 key::kDeviceOpenNetworkConfiguration, |
31 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, | 66 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, |
32 base::Unretained(this), | 67 base::Unretained(this), |
33 chromeos::onc::ONC_SOURCE_DEVICE_POLICY)); | 68 chromeos::onc::ONC_SOURCE_DEVICE_POLICY)); |
34 policy_change_registrar_.Observe( | 69 policy_change_registrar_.Observe( |
35 key::kOpenNetworkConfiguration, | 70 key::kOpenNetworkConfiguration, |
36 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, | 71 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, |
37 base::Unretained(this), | 72 base::Unretained(this), |
38 chromeos::onc::ONC_SOURCE_USER_POLICY)); | 73 chromeos::onc::ONC_SOURCE_USER_POLICY)); |
39 | 74 |
40 network_library_->AddNetworkProfileObserver(this); | 75 network_library_->AddNetworkProfileObserver(this); |
41 | 76 |
42 // Apply the current policies immediately. | 77 // Apply the current policies immediately. |
43 ApplyNetworkConfigurations(); | 78 ApplyNetworkConfigurations(); |
44 } | 79 } |
45 | 80 |
46 NetworkConfigurationUpdater::~NetworkConfigurationUpdater() { | 81 NetworkConfigurationUpdater::~NetworkConfigurationUpdater() { |
47 network_library_->RemoveNetworkProfileObserver(this); | 82 network_library_->RemoveNetworkProfileObserver(this); |
83 if (cert_trust_provider_) { | |
84 bool posted = BrowserThread::DeleteSoon( | |
85 BrowserThread::IO, FROM_HERE, cert_trust_provider_); | |
86 if (!posted) | |
pneubeck (no reviews)
2013/03/26 10:01:25
is that an error/problematic case? if so should we
Joao da Silva
2013/03/31 19:22:14
This occurs when shutdown happens very early, befo
| |
87 delete cert_trust_provider_; | |
88 } | |
48 } | 89 } |
49 | 90 |
50 void NetworkConfigurationUpdater::OnProfileListChanged() { | 91 void NetworkConfigurationUpdater::OnProfileListChanged() { |
51 VLOG(1) << "Network profile list changed, applying policies."; | 92 VLOG(1) << "Network profile list changed, applying policies."; |
52 ApplyNetworkConfigurations(); | 93 ApplyNetworkConfigurations(); |
53 } | 94 } |
54 | 95 |
55 void NetworkConfigurationUpdater::OnUserPolicyInitialized() { | 96 void NetworkConfigurationUpdater::OnUserPolicyInitialized() { |
56 VLOG(1) << "User policy initialized, applying policies."; | 97 VLOG(1) << "User policy initialized, applying policies."; |
57 user_policy_initialized_ = true; | 98 user_policy_initialized_ = true; |
58 ApplyNetworkConfigurations(); | 99 ApplyNetworkConfigurations(); |
59 } | 100 } |
60 | 101 |
102 net::CertTrustAnchorProvider* | |
103 NetworkConfigurationUpdater::GetCertTrustAnchorProvider() { | |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
105 if (!cert_trust_provider_) | |
106 cert_trust_provider_ = new CertTrustAnchorProviderImpl(); | |
Ryan Sleevi
2013/03/25 21:09:53
Why the lazy-load?
Joao da Silva
2013/03/31 19:22:14
No good reason, removed.
| |
107 return cert_trust_provider_; | |
108 } | |
109 | |
61 void NetworkConfigurationUpdater::OnPolicyChanged( | 110 void NetworkConfigurationUpdater::OnPolicyChanged( |
62 chromeos::onc::ONCSource onc_source, | 111 chromeos::onc::ONCSource onc_source, |
63 const base::Value* previous, | 112 const base::Value* previous, |
64 const base::Value* current) { | 113 const base::Value* current) { |
65 VLOG(1) << "Policy for ONC source " | 114 VLOG(1) << "Policy for ONC source " |
66 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; | 115 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; |
67 ApplyNetworkConfigurations(); | 116 ApplyNetworkConfigurations(); |
68 } | 117 } |
69 | 118 |
70 void NetworkConfigurationUpdater::ApplyNetworkConfigurations() { | 119 void NetworkConfigurationUpdater::ApplyNetworkConfigurations() { |
(...skipping 23 matching lines...) Expand all Loading... | |
94 << chromeos::onc::GetSourceAsString(onc_source) | 143 << chromeos::onc::GetSourceAsString(onc_source) |
95 << " is not a string value."; | 144 << " is not a string value."; |
96 } | 145 } |
97 } | 146 } |
98 | 147 |
99 // An empty string is not a valid ONC and generates warnings and | 148 // An empty string is not a valid ONC and generates warnings and |
100 // errors. Replace by a valid empty configuration. | 149 // errors. Replace by a valid empty configuration. |
101 if (new_network_config.empty()) | 150 if (new_network_config.empty()) |
102 new_network_config = chromeos::onc::kEmptyUnencryptedConfiguration; | 151 new_network_config = chromeos::onc::kEmptyUnencryptedConfiguration; |
103 | 152 |
153 scoped_ptr<net::CertificateList> web_trust_certs(new net::CertificateList()); | |
104 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source, | 154 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source, |
105 allow_web_trust_)) { | 155 web_trust_certs.get())) { |
106 LOG(ERROR) << "Errors occurred during the ONC policy application."; | 156 LOG(ERROR) << "Errors occurred during the ONC policy application."; |
107 } | 157 } |
158 | |
159 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
160 if (onc_source == chromeos::onc::ONC_SOURCE_USER_POLICY && | |
161 allow_web_trust_ && | |
162 command_line->HasSwitch(switches::kEnableWebTrustCerts)) { | |
163 GetCertTrustAnchorProvider(); // Make sure it's there. | |
164 BrowserThread::PostTask( | |
165 BrowserThread::IO, FROM_HERE, | |
166 base::Bind(&CertTrustAnchorProviderImpl::SetTrustAnchors, | |
167 base::Unretained(cert_trust_provider_), | |
168 base::Passed(&web_trust_certs))); | |
Ryan Sleevi
2013/03/25 21:09:53
In the larger context, this highlights an interest
Joao da Silva
2013/03/31 19:22:14
SGTM; I'll leave that for another CL.
That requir
Ryan Sleevi
2013/04/02 19:16:06
I'll have to think more about this one. We can add
| |
169 } | |
108 } | 170 } |
109 | 171 |
110 } // namespace policy | 172 } // namespace policy |
OLD | NEW |