Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: chrome/browser/chromeos/policy/user_network_configuration_updater.h

Issue 148183013: Use per-user nssdb in onc certificate importer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix browser_tests compile Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/observer_list.h" 15 #include "base/observer_list.h"
15 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" 16 #include "chrome/browser/chromeos/policy/network_configuration_updater.h"
16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 17 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20
21 class Profile;
22
23 namespace base {
24 class ListValue;
25 }
17 26
18 namespace chromeos { 27 namespace chromeos {
19 class User; 28 class User;
29
30 namespace onc {
31 class CertificateImporter;
32 }
20 } 33 }
21 34
22 namespace net { 35 namespace net {
36 class NSSCertDatabase;
23 class X509Certificate; 37 class X509Certificate;
24 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; 38 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList;
25 } 39 }
26 40
27 namespace policy { 41 namespace policy {
28 42
29 class PolicyService; 43 class PolicyService;
30 44
31 // Implements additional special handling of ONC user policies. Namely string 45 // Implements additional special handling of ONC user policies. Namely string
32 // expansion with the user's name (or email address, etc.) and handling of "Web" 46 // expansion with the user's name (or email address, etc.) and handling of "Web"
33 // trust of certificates. 47 // trust of certificates.
34 class UserNetworkConfigurationUpdater : public NetworkConfigurationUpdater, 48 class UserNetworkConfigurationUpdater : public NetworkConfigurationUpdater,
35 public BrowserContextKeyedService { 49 public BrowserContextKeyedService,
50 public content::NotificationObserver {
36 public: 51 public:
37 class WebTrustedCertsObserver { 52 class WebTrustedCertsObserver {
38 public: 53 public:
39 // 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
40 // changed. 55 // changed.
41 virtual void OnTrustAnchorsChanged( 56 virtual void OnTrustAnchorsChanged(
42 const net::CertificateList& trust_anchors) = 0; 57 const net::CertificateList& trust_anchors) = 0;
43 }; 58 };
44 59
45 virtual ~UserNetworkConfigurationUpdater(); 60 virtual ~UserNetworkConfigurationUpdater();
46 61
47 // 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|
48 // 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
49 // each policy change. Imported certificates, that request it, are only 64 // each policy change. Imported certificates, that request it, are only
50 // 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
51 // to |user| is stored. It must outlive the returned updater. 66 // to |user| is stored. It must outlive the returned updater.
52 static scoped_ptr<UserNetworkConfigurationUpdater> CreateForUserPolicy( 67 static scoped_ptr<UserNetworkConfigurationUpdater> CreateForUserPolicy(
68 Profile* profile,
53 bool allow_trusted_certs_from_policy, 69 bool allow_trusted_certs_from_policy,
54 const chromeos::User& user, 70 const chromeos::User& user,
55 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer,
56 PolicyService* policy_service, 71 PolicyService* policy_service,
57 chromeos::ManagedNetworkConfigurationHandler* network_config_handler); 72 chromeos::ManagedNetworkConfigurationHandler* network_config_handler);
58 73
59 void AddTrustedCertsObserver(WebTrustedCertsObserver* observer); 74 void AddTrustedCertsObserver(WebTrustedCertsObserver* observer);
60 void RemoveTrustedCertsObserver(WebTrustedCertsObserver* observer); 75 void RemoveTrustedCertsObserver(WebTrustedCertsObserver* observer);
61 76
62 // Sets |certs| to the list of Web trusted server and CA certificates from the 77 // Sets |certs| to the list of Web trusted server and CA certificates from the
63 // last received policy. 78 // last received policy.
64 void GetWebTrustedCertificates(net::CertificateList* certs) const; 79 void GetWebTrustedCertificates(net::CertificateList* certs) const;
65 80
81 // Helper method to expose |SetCertificateImporter| for usage in tests.
82 void SetCertificateImporterForTest(
83 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer);
84
85 // Used in test to delay CertificateImporter creation until the NSSDatabase is
86 // ready. This is needed in some tests as the user's certificate database may
87 // not get initialized in time.
88 // TODO(tbarzic): Remove this when it's not needed.
89 static void SetSkipCertificateImporterCreationForTest(bool skip);
90
66 private: 91 private:
67 class CrosTrustAnchorProvider; 92 class CrosTrustAnchorProvider;
68 93
69 UserNetworkConfigurationUpdater( 94 UserNetworkConfigurationUpdater(
95 Profile* profile,
70 bool allow_trusted_certs_from_policy, 96 bool allow_trusted_certs_from_policy,
71 const chromeos::User& user, 97 const chromeos::User& user,
72 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer,
73 PolicyService* policy_service, 98 PolicyService* policy_service,
74 chromeos::ManagedNetworkConfigurationHandler* network_config_handler); 99 chromeos::ManagedNetworkConfigurationHandler* network_config_handler);
75 100
101 // NetworkConfigurationUpdater:
76 virtual void ImportCertificates( 102 virtual void ImportCertificates(
77 const base::ListValue& certificates_onc) OVERRIDE; 103 const base::ListValue& certificates_onc) OVERRIDE;
78
79 virtual void ApplyNetworkPolicy( 104 virtual void ApplyNetworkPolicy(
80 base::ListValue* network_configs_onc, 105 base::ListValue* network_configs_onc,
81 base::DictionaryValue* global_network_config) OVERRIDE; 106 base::DictionaryValue* global_network_config) OVERRIDE;
82 107
108 // content::NotificationObserver implementation. Observes the profile to which
109 // |this| belongs to for PROFILE_ADDED notification.
110 virtual void Observe(int type,
111 const content::NotificationSource& source,
112 const content::NotificationDetails& details) OVERRIDE;
113
114 // Creates onc::CertImporter with |database| and passes it to
115 // |SetCertificateImporter|.
116 void CreateAndSetCertificateImporter(net::NSSCertDatabase* database);
117
118 // Sets the certificate importer that should be used to import certificate
119 // policies. If there is |pending_certificates_onc_|, it gets imported.
120 void SetCertificateImporter(
121 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer);
122
83 void NotifyTrustAnchorsChanged(); 123 void NotifyTrustAnchorsChanged();
84 124
85 // Whether Web trust is allowed or not. Only relevant for user policies. 125 // Whether Web trust is allowed or not.
86 bool allow_trusted_certificates_from_policy_; 126 bool allow_trusted_certificates_from_policy_;
87 127
88 // The user for whom the user policy will be applied. Is NULL if this Updater 128 // The user for whom the user policy will be applied.
89 // is used for device policy.
90 const chromeos::User* user_; 129 const chromeos::User* user_;
91 130
92 ObserverList<WebTrustedCertsObserver, true> observer_list_; 131 ObserverList<WebTrustedCertsObserver, true> observer_list_;
93 132
94 // Contains the certificates of the last import that requested web trust. Must 133 // Contains the certificates of the last import that requested web trust. Must
95 // be empty if Web trust from policy is not allowed. 134 // be empty if Web trust from policy is not allowed.
96 net::CertificateList web_trust_certs_; 135 net::CertificateList web_trust_certs_;
97 136
137 // If |ImportCertificates| is called before |SetCertificateImporter|, gets set
138 // to a copy of the policy for which the import was requested.
139 // The policy will be processed when the certificate importer is set.
140 scoped_ptr<base::ListValue> pending_certificates_onc_;
141
142 // Certificate importer to be used for importing policy defined certificates.
143 // Set by |SetCertificateImporter|.
144 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_;
145
146 content::NotificationRegistrar registrar_;
147
148 base::WeakPtrFactory<UserNetworkConfigurationUpdater> weak_factory_;
149
98 DISALLOW_COPY_AND_ASSIGN(UserNetworkConfigurationUpdater); 150 DISALLOW_COPY_AND_ASSIGN(UserNetworkConfigurationUpdater);
99 }; 151 };
100 152
101 } // namespace policy 153 } // namespace policy
102 154
103 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_ 155 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698