OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" | 16 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" |
17 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
18 #include "content/public/browser/notification_observer.h" | |
19 #include "content/public/browser/notification_registrar.h" | |
20 | |
21 class Profile; | |
22 | 18 |
23 namespace base { | 19 namespace base { |
24 class ListValue; | 20 class ListValue; |
25 } | 21 } |
26 | 22 |
27 namespace user_manager { | 23 namespace user_manager { |
28 class User; | 24 class User; |
29 } | 25 } |
30 | 26 |
31 namespace chromeos { | 27 namespace chromeos { |
32 | |
33 namespace onc { | 28 namespace onc { |
34 class CertificateImporter; | 29 class CertificateImporter; |
35 } | 30 } |
36 } | 31 } |
37 | 32 |
38 namespace net { | 33 namespace net { |
39 class NSSCertDatabase; | 34 class NSSCertDatabase; |
40 class X509Certificate; | 35 class X509Certificate; |
41 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; | 36 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; |
42 } | 37 } |
43 | 38 |
44 namespace policy { | 39 namespace policy { |
45 | 40 |
46 class PolicyService; | 41 class PolicyService; |
47 | 42 |
48 // Implements additional special handling of ONC user policies. Namely string | 43 // Implements additional special handling of ONC user policies. Namely string |
49 // expansion with the user's name (or email address, etc.) and handling of "Web" | 44 // expansion with the user's name (or email address, etc.) and handling of "Web" |
50 // trust of certificates. | 45 // trust of certificates. |
51 class UserNetworkConfigurationUpdater : public NetworkConfigurationUpdater, | 46 class UserNetworkConfigurationUpdater : public NetworkConfigurationUpdater, |
52 public KeyedService, | 47 public KeyedService { |
53 public content::NotificationObserver { | |
54 public: | 48 public: |
55 class WebTrustedCertsObserver { | 49 class WebTrustedCertsObserver { |
56 public: | 50 public: |
57 // Is called everytime the list of imported certificates with Web trust is | 51 // Is called everytime the list of imported certificates with Web trust is |
58 // changed. | 52 // changed. |
59 virtual void OnTrustAnchorsChanged( | 53 virtual void OnTrustAnchorsChanged( |
60 const net::CertificateList& trust_anchors) = 0; | 54 const net::CertificateList& trust_anchors) = 0; |
61 }; | 55 }; |
62 | 56 |
63 virtual ~UserNetworkConfigurationUpdater(); | 57 virtual ~UserNetworkConfigurationUpdater(); |
64 | 58 |
65 // Creates an updater that applies the ONC user policy from |policy_service| | 59 // Creates an updater that applies the ONC user policy from |policy_service| |
66 // for user |user| once the policy service is completely initialized and on | 60 // for user |user| once the policy service is completely initialized and on |
67 // each policy change. Imported certificates, that request it, are only | 61 // each policy change. Imported certificates, that request it, are only |
68 // granted Web trust if |allow_trusted_certs_from_policy| is true. A reference | 62 // granted Web trust if |allow_trusted_certs_from_policy| is true. A reference |
69 // to |user| is stored. It must outlive the returned updater. | 63 // to |user| is stored. It must outlive the returned updater. |
70 static scoped_ptr<UserNetworkConfigurationUpdater> CreateForUserPolicy( | 64 static scoped_ptr<UserNetworkConfigurationUpdater> CreateForUserPolicy( |
71 Profile* profile, | |
72 bool allow_trusted_certs_from_policy, | 65 bool allow_trusted_certs_from_policy, |
73 const user_manager::User& user, | 66 const user_manager::User& user, |
74 PolicyService* policy_service, | 67 PolicyService* policy_service, |
| 68 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer, |
75 chromeos::ManagedNetworkConfigurationHandler* network_config_handler); | 69 chromeos::ManagedNetworkConfigurationHandler* network_config_handler); |
76 | 70 |
77 void AddTrustedCertsObserver(WebTrustedCertsObserver* observer); | 71 void AddTrustedCertsObserver(WebTrustedCertsObserver* observer); |
78 void RemoveTrustedCertsObserver(WebTrustedCertsObserver* observer); | 72 void RemoveTrustedCertsObserver(WebTrustedCertsObserver* observer); |
79 | 73 |
80 // Sets |certs| to the list of Web trusted server and CA certificates from the | 74 // Sets |certs| to the list of Web trusted server and CA certificates from the |
81 // last received policy. | 75 // last received policy. |
82 void GetWebTrustedCertificates(net::CertificateList* certs) const; | 76 void GetWebTrustedCertificates(net::CertificateList* certs) const; |
83 | 77 |
84 // Helper method to expose |SetCertificateImporter| for usage in tests. | |
85 void SetCertificateImporterForTest( | |
86 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer); | |
87 | |
88 private: | 78 private: |
89 class CrosTrustAnchorProvider; | 79 class CrosTrustAnchorProvider; |
90 | 80 |
91 UserNetworkConfigurationUpdater( | 81 UserNetworkConfigurationUpdater( |
92 Profile* profile, | |
93 bool allow_trusted_certs_from_policy, | 82 bool allow_trusted_certs_from_policy, |
94 const user_manager::User& user, | 83 const user_manager::User& user, |
95 PolicyService* policy_service, | 84 PolicyService* policy_service, |
| 85 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer, |
96 chromeos::ManagedNetworkConfigurationHandler* network_config_handler); | 86 chromeos::ManagedNetworkConfigurationHandler* network_config_handler); |
97 | 87 |
98 // Called by the CertificateImporter when an import finished. | 88 // Called by the CertificateImporter when an import finished. |
99 void OnCertificatesImported( | 89 void OnCertificatesImported( |
100 bool success, | 90 bool success, |
101 const net::CertificateList& onc_trusted_certificates); | 91 const net::CertificateList& onc_trusted_certificates); |
102 | 92 |
103 // NetworkConfigurationUpdater: | 93 // NetworkConfigurationUpdater: |
104 virtual void ImportCertificates( | 94 virtual void ImportCertificates( |
105 const base::ListValue& certificates_onc) override; | 95 const base::ListValue& certificates_onc) override; |
106 virtual void ApplyNetworkPolicy( | 96 virtual void ApplyNetworkPolicy( |
107 base::ListValue* network_configs_onc, | 97 base::ListValue* network_configs_onc, |
108 base::DictionaryValue* global_network_config) override; | 98 base::DictionaryValue* global_network_config) override; |
109 | 99 |
110 // content::NotificationObserver implementation. Observes the profile to which | |
111 // |this| belongs to for PROFILE_ADDED notification. | |
112 virtual void Observe(int type, | |
113 const content::NotificationSource& source, | |
114 const content::NotificationDetails& details) override; | |
115 | |
116 // Creates onc::CertImporter with |database| and passes it to | |
117 // |SetCertificateImporter|. | |
118 void CreateAndSetCertificateImporter(net::NSSCertDatabase* database); | |
119 | |
120 // Sets the certificate importer that should be used to import certificate | |
121 // policies. If there is |pending_certificates_onc_|, it gets imported. | |
122 void SetCertificateImporter( | |
123 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer); | |
124 | |
125 void NotifyTrustAnchorsChanged(); | 100 void NotifyTrustAnchorsChanged(); |
126 | 101 |
127 // Whether Web trust is allowed or not. | 102 // Whether Web trust is allowed or not. |
128 bool allow_trusted_certificates_from_policy_; | 103 bool allow_trusted_certificates_from_policy_; |
129 | 104 |
130 // The user for whom the user policy will be applied. | 105 // The user for whom the user policy will be applied. |
131 const user_manager::User* user_; | 106 const user_manager::User* user_; |
132 | 107 |
133 ObserverList<WebTrustedCertsObserver, true> observer_list_; | 108 ObserverList<WebTrustedCertsObserver, true> observer_list_; |
134 | 109 |
135 // Contains the certificates of the last import that requested web trust. Must | 110 // Contains the certificates of the last import that requested web trust. Must |
136 // be empty if Web trust from policy is not allowed. | 111 // be empty if Web trust from policy is not allowed. |
137 net::CertificateList web_trust_certs_; | 112 net::CertificateList web_trust_certs_; |
138 | 113 |
139 // If |ImportCertificates| is called before |SetCertificateImporter|, gets set | |
140 // to a copy of the policy for which the import was requested. | |
141 // The policy will be processed when the certificate importer is set. | |
142 scoped_ptr<base::ListValue> pending_certificates_onc_; | |
143 | |
144 // Certificate importer to be used for importing policy defined certificates. | 114 // Certificate importer to be used for importing policy defined certificates. |
145 // Set by |SetCertificateImporter|. | |
146 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_; | 115 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_; |
147 | 116 |
148 content::NotificationRegistrar registrar_; | |
149 | |
150 base::WeakPtrFactory<UserNetworkConfigurationUpdater> weak_factory_; | 117 base::WeakPtrFactory<UserNetworkConfigurationUpdater> weak_factory_; |
151 | 118 |
152 DISALLOW_COPY_AND_ASSIGN(UserNetworkConfigurationUpdater); | 119 DISALLOW_COPY_AND_ASSIGN(UserNetworkConfigurationUpdater); |
153 }; | 120 }; |
154 | 121 |
155 } // namespace policy | 122 } // namespace policy |
156 | 123 |
157 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_ | 124 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_ |
OLD | NEW |