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