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

Side by Side Diff: chromeos/network/cert_loader.h

Issue 20130002: Call crypto::InitializeTPMToken on the IO thread (Take 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser tests Created 7 years, 4 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 CHROMEOS_NETWORK_CERT_LOADER_H_ 5 #ifndef CHROMEOS_NETWORK_CERT_LOADER_H_
6 #define CHROMEOS_NETWORK_CERT_LOADER_H_ 6 #define CHROMEOS_NETWORK_CERT_LOADER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list_threadsafe.h" 13 #include "base/observer_list_threadsafe.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "chromeos/chromeos_export.h" 15 #include "chromeos/chromeos_export.h"
16 #include "chromeos/dbus/dbus_method_call_status.h" 16 #include "chromeos/dbus/dbus_method_call_status.h"
17 #include "chromeos/login/login_state.h" 17 #include "chromeos/login/login_state.h"
18 #include "chromeos/network/network_handler.h" 18 #include "chromeos/network/network_handler.h"
19 #include "net/cert/cert_database.h" 19 #include "net/cert/cert_database.h"
20 #include "net/cert/x509_certificate.h" 20 #include "net/cert/x509_certificate.h"
21 21
22 namespace base {
23 class SequencedTaskRunner;
24 }
25
22 namespace crypto { 26 namespace crypto {
23 class SymmetricKey; 27 class SymmetricKey;
24 } 28 }
25 29
26 namespace chromeos { 30 namespace chromeos {
27 31
28 // This class is responsible for initializing the TPM token and loading 32 // This class is responsible for initializing the TPM token and loading
29 // certificates once the TPM is initialized. It is expected to be constructed 33 // certificates once the TPM is initialized. It is expected to be constructed
30 // on the UI thread and public methods should all be called from the UI thread. 34 // on the UI thread and public methods should all be called from the UI thread.
31 // When certificates have been loaded (after login completes), or the cert 35 // When certificates have been loaded (after login completes), or the cert
(...skipping 13 matching lines...) Expand all
45 49
46 protected: 50 protected:
47 Observer() {} 51 Observer() {}
48 52
49 private: 53 private:
50 DISALLOW_COPY_AND_ASSIGN(Observer); 54 DISALLOW_COPY_AND_ASSIGN(Observer);
51 }; 55 };
52 56
53 virtual ~CertLoader(); 57 virtual ~CertLoader();
54 58
59 // |crypto_task_runner| is the task runner that any synchronous crypto calls
60 // should be made from. e.g. in Chrome this is the IO thread. Must be called
61 // after the thread is started. Certificate loading will not happen unless
62 // this is set.
63 void SetCryptoTaskRunner(
64 const scoped_refptr<base::SequencedTaskRunner>& crypto_task_runner);
65
55 void AddObserver(CertLoader::Observer* observer); 66 void AddObserver(CertLoader::Observer* observer);
56 void RemoveObserver(CertLoader::Observer* observer); 67 void RemoveObserver(CertLoader::Observer* observer);
57 68
58 // Returns true when the certificate list has been requested but not loaded. 69 // Returns true when the certificate list has been requested but not loaded.
59 bool CertificatesLoading() const; 70 bool CertificatesLoading() const;
60 71
61 // Returns true if the TPM is available for hardware-backed certificates. 72 // Returns true if the TPM is available for hardware-backed certificates.
62 bool IsHardwareBacked() const; 73 bool IsHardwareBacked() const;
63 74
64 std::string GetPkcs11IdForCert(const net::X509Certificate& cert) const; 75 std::string GetPkcs11IdForCert(const net::X509Certificate& cert) const;
65 76
66 bool certificates_loaded() const { return certificates_loaded_; } 77 bool certificates_loaded() const { return certificates_loaded_; }
67 78
68 // TPM info is only valid once the TPM is available (IsHardwareBacked is 79 // TPM info is only valid once the TPM is available (IsHardwareBacked is
69 // true). Otherwise empty strings will be returned. 80 // true). Otherwise empty strings will be returned.
70 const std::string& tpm_token_name() const { return tpm_token_name_; } 81 const std::string& tpm_token_name() const { return tpm_token_name_; }
71 const std::string& tpm_token_slot() const { return tpm_token_slot_; } 82 const std::string& tpm_token_slot() const { return tpm_token_slot_; }
72 const std::string& tpm_user_pin() const { return tpm_user_pin_; } 83 const std::string& tpm_user_pin() const { return tpm_user_pin_; }
73 84
74 // This will be empty until certificates_loaded() is true. 85 // This will be empty until certificates_loaded() is true.
75 const net::CertificateList& cert_list() const { return cert_list_; } 86 const net::CertificateList& cert_list() const { return cert_list_; }
76 87
77 private: 88 private:
78 friend class NetworkHandler; 89 friend class NetworkHandler;
79 CertLoader(); 90 CertLoader();
80 91
81 void RequestCertificates(); 92 void Init();
93 void MaybeRequestCertificates();
82 94
83 // This is the cyclic chain of callbacks to initialize the TPM token and to 95 // This is the cyclic chain of callbacks to initialize the TPM token and to
84 // kick off the update of the certificate list. 96 // kick off the update of the certificate list.
85 void InitializeTokenAndLoadCertificates(); 97 void InitializeTokenAndLoadCertificates();
86 void RetryTokenInitializationLater(); 98 void RetryTokenInitializationLater();
99 void OnPersistentNSSDBOpened();
87 void OnTpmIsEnabled(DBusMethodCallStatus call_status, 100 void OnTpmIsEnabled(DBusMethodCallStatus call_status,
88 bool tpm_is_enabled); 101 bool tpm_is_enabled);
89 void OnPkcs11IsTpmTokenReady(DBusMethodCallStatus call_status, 102 void OnPkcs11IsTpmTokenReady(DBusMethodCallStatus call_status,
90 bool is_tpm_token_ready); 103 bool is_tpm_token_ready);
91 void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status, 104 void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status,
92 const std::string& token_name, 105 const std::string& token_name,
93 const std::string& user_pin); 106 const std::string& user_pin);
94 void InitializeNSSForTPMToken(); 107 void OnTPMTokenInitialized(bool success);
95 108
96 // These calls handle the updating of the certificate list after the TPM token 109 // These calls handle the updating of the certificate list after the TPM token
97 // was initialized. 110 // was initialized.
98 void StartLoadCertificates(); 111 void StartLoadCertificates();
99 void UpdateCertificates(net::CertificateList* cert_list); 112 void UpdateCertificates(net::CertificateList* cert_list);
100 113
101 void NotifyCertificatesLoaded(bool initial_load); 114 void NotifyCertificatesLoaded(bool initial_load);
102 115
103 // net::CertDatabase::Observer 116 // net::CertDatabase::Observer
104 virtual void OnCertTrustChanged(const net::X509Certificate* cert) OVERRIDE; 117 virtual void OnCertTrustChanged(const net::X509Certificate* cert) OVERRIDE;
105 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE; 118 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE;
106 virtual void OnCertRemoved(const net::X509Certificate* cert) OVERRIDE; 119 virtual void OnCertRemoved(const net::X509Certificate* cert) OVERRIDE;
107 120
108 // LoginState::Observer 121 // LoginState::Observer
109 virtual void LoggedInStateChanged(LoginState::LoggedInState state) OVERRIDE; 122 virtual void LoggedInStateChanged(LoginState::LoggedInState state) OVERRIDE;
110 123
111 ObserverList<Observer> observers_; 124 ObserverList<Observer> observers_;
112 125
113 bool certificates_requested_; 126 bool certificates_requested_;
114 bool certificates_loaded_; 127 bool certificates_loaded_;
115 bool certificates_update_required_; 128 bool certificates_update_required_;
116 bool certificates_update_running_; 129 bool certificates_update_running_;
117 130
118 // The states are traversed in this order but some might get omitted or never 131 // The states are traversed in this order but some might get omitted or never
119 // be left. 132 // be left.
120 enum TPMTokenState { 133 enum TPMTokenState {
121 TPM_STATE_UNKNOWN, 134 TPM_STATE_UNKNOWN,
135 TPM_DB_OPENED,
122 TPM_DISABLED, 136 TPM_DISABLED,
123 TPM_ENABLED, 137 TPM_ENABLED,
124 TPM_TOKEN_READY, 138 TPM_TOKEN_READY,
125 TPM_TOKEN_INFO_RECEIVED, 139 TPM_TOKEN_INFO_RECEIVED,
126 TPM_TOKEN_NSS_INITIALIZED, 140 TPM_TOKEN_INITIALIZED,
127 }; 141 };
128 TPMTokenState tpm_token_state_; 142 TPMTokenState tpm_token_state_;
129 143
130 // The current request delay before the next attempt to initialize the 144 // The current request delay before the next attempt to initialize the
131 // TPM. Will be adapted after each attempt. 145 // TPM. Will be adapted after each attempt.
132 base::TimeDelta tpm_request_delay_; 146 base::TimeDelta tpm_request_delay_;
133 147
134 // Cached TPM token info. 148 // Cached TPM token info.
135 std::string tpm_token_name_; 149 std::string tpm_token_name_;
136 std::string tpm_token_slot_; 150 std::string tpm_token_slot_;
137 std::string tpm_user_pin_; 151 std::string tpm_user_pin_;
138 152
139 // Cached Certificates. 153 // Cached Certificates.
140 net::CertificateList cert_list_; 154 net::CertificateList cert_list_;
141 155
142 base::ThreadChecker thread_checker_; 156 base::ThreadChecker thread_checker_;
143 157
158 // TaskRunner for crypto calls.
159 scoped_refptr<base::SequencedTaskRunner> crypto_task_runner_;
160
144 // This factory should be used only for callbacks during TPMToken 161 // This factory should be used only for callbacks during TPMToken
145 // initialization. 162 // initialization.
146 base::WeakPtrFactory<CertLoader> initialize_token_factory_; 163 base::WeakPtrFactory<CertLoader> initialize_token_factory_;
147 164
148 // This factory should be used only for callbacks during updating the 165 // This factory should be used only for callbacks during updating the
149 // certificate list. 166 // certificate list.
150 base::WeakPtrFactory<CertLoader> update_certificates_factory_; 167 base::WeakPtrFactory<CertLoader> update_certificates_factory_;
151 168
152 DISALLOW_COPY_AND_ASSIGN(CertLoader); 169 DISALLOW_COPY_AND_ASSIGN(CertLoader);
153 }; 170 };
154 171
155 } // namespace chromeos 172 } // namespace chromeos
156 173
157 #endif // CHROMEOS_NETWORK_CERT_LOADER_H_ 174 #endif // CHROMEOS_NETWORK_CERT_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698