| OLD | NEW |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 71 |
| 68 // TPM info is only valid once the TPM is available (IsHardwareBacked is | 72 // TPM info is only valid once the TPM is available (IsHardwareBacked is |
| 69 // true). Otherwise empty strings will be returned. | 73 // true). Otherwise empty strings will be returned. |
| 70 const std::string& tpm_token_name() const { return tpm_token_name_; } | 74 const std::string& tpm_token_name() const { return tpm_token_name_; } |
| 71 const std::string& tpm_token_slot() const { return tpm_token_slot_; } | 75 const std::string& tpm_token_slot() const { return tpm_token_slot_; } |
| 72 const std::string& tpm_user_pin() const { return tpm_user_pin_; } | 76 const std::string& tpm_user_pin() const { return tpm_user_pin_; } |
| 73 | 77 |
| 74 // This will be empty until certificates_loaded() is true. | 78 // This will be empty until certificates_loaded() is true. |
| 75 const net::CertificateList& cert_list() const { return cert_list_; } | 79 const net::CertificateList& cert_list() const { return cert_list_; } |
| 76 | 80 |
| 81 // TEST, DO NOT CHECK IN |
| 82 void InvalidateInitializeTokenFactory(); |
| 83 void InvalidateUpdateCertificatesFactory(); |
| 84 void InvalidateCryptoFactory(); |
| 85 |
| 77 private: | 86 private: |
| 78 friend class NetworkHandler; | 87 friend class NetworkHandler; |
| 79 CertLoader(); | 88 CertLoader(); |
| 89 // |crypto_task_runner| is the task runner that any synchronous crypto calls |
| 90 // should be made from. e.g. in Chrome this is the IO thread. |
| 91 void Init(const scoped_refptr<base::SequencedTaskRunner>& crypto_task_runner); |
| 80 | 92 |
| 81 void RequestCertificates(); | 93 void RequestCertificates(); |
| 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. |
| 97 void CallOpenPersistentNSSDB(); |
| 98 void OnPersistentNSSDBOpened(); |
| 85 void InitializeTokenAndLoadCertificates(); | 99 void InitializeTokenAndLoadCertificates(); |
| 86 void RetryTokenInitializationLater(); | 100 void RetryTokenInitializationLater(); |
| 87 void OnTpmIsEnabled(DBusMethodCallStatus call_status, | 101 void OnTpmIsEnabled(DBusMethodCallStatus call_status, |
| 88 bool tpm_is_enabled); | 102 bool tpm_is_enabled); |
| 89 void OnPkcs11IsTpmTokenReady(DBusMethodCallStatus call_status, | 103 void OnPkcs11IsTpmTokenReady(DBusMethodCallStatus call_status, |
| 90 bool is_tpm_token_ready); | 104 bool is_tpm_token_ready); |
| 91 void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status, | 105 void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status, |
| 92 const std::string& token_name, | 106 const std::string& token_name, |
| 93 const std::string& user_pin); | 107 const std::string& user_pin); |
| 94 void InitializeNSSForTPMToken(); | 108 void OnTPMTokenInitialized(bool success); |
| 95 | 109 |
| 96 // These calls handle the updating of the certificate list after the TPM token | 110 // These calls handle the updating of the certificate list after the TPM token |
| 97 // was initialized. | 111 // was initialized. |
| 98 void StartLoadCertificates(); | 112 void StartLoadCertificates(); |
| 99 void UpdateCertificates(net::CertificateList* cert_list); | 113 void UpdateCertificates(net::CertificateList* cert_list); |
| 100 | 114 |
| 101 void NotifyCertificatesLoaded(bool initial_load); | 115 void NotifyCertificatesLoaded(bool initial_load); |
| 102 | 116 |
| 103 // net::CertDatabase::Observer | 117 // net::CertDatabase::Observer |
| 104 virtual void OnCertTrustChanged(const net::X509Certificate* cert) OVERRIDE; | 118 virtual void OnCertTrustChanged(const net::X509Certificate* cert) OVERRIDE; |
| 105 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE; | 119 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE; |
| 106 virtual void OnCertRemoved(const net::X509Certificate* cert) OVERRIDE; | 120 virtual void OnCertRemoved(const net::X509Certificate* cert) OVERRIDE; |
| 107 | 121 |
| 108 // LoginState::Observer | 122 // LoginState::Observer |
| 109 virtual void LoggedInStateChanged(LoginState::LoggedInState state) OVERRIDE; | 123 virtual void LoggedInStateChanged(LoginState::LoggedInState state) OVERRIDE; |
| 110 | 124 |
| 111 ObserverList<Observer> observers_; | 125 ObserverList<Observer> observers_; |
| 112 | 126 |
| 113 bool certificates_requested_; | 127 bool certificates_requested_; |
| 114 bool certificates_loaded_; | 128 bool certificates_loaded_; |
| 115 bool certificates_update_required_; | 129 bool certificates_update_required_; |
| 116 bool certificates_update_running_; | 130 bool certificates_update_running_; |
| 117 | 131 |
| 118 // The states are traversed in this order but some might get omitted or never | 132 // The states are traversed in this order but some might get omitted or never |
| 119 // be left. | 133 // be left. |
| 120 enum TPMTokenState { | 134 enum TPMTokenState { |
| 121 TPM_STATE_UNKNOWN, | 135 TPM_STATE_UNKNOWN, |
| 136 TPM_DB_OPENED, |
| 122 TPM_DISABLED, | 137 TPM_DISABLED, |
| 123 TPM_ENABLED, | 138 TPM_ENABLED, |
| 124 TPM_TOKEN_READY, | 139 TPM_TOKEN_READY, |
| 125 TPM_TOKEN_INFO_RECEIVED, | 140 TPM_TOKEN_INFO_RECEIVED, |
| 126 TPM_TOKEN_NSS_INITIALIZED, | 141 TPM_TOKEN_INITIALIZED, |
| 127 }; | 142 }; |
| 128 TPMTokenState tpm_token_state_; | 143 TPMTokenState tpm_token_state_; |
| 129 | 144 |
| 130 // The current request delay before the next attempt to initialize the | 145 // The current request delay before the next attempt to initialize the |
| 131 // TPM. Will be adapted after each attempt. | 146 // TPM. Will be adapted after each attempt. |
| 132 base::TimeDelta tpm_request_delay_; | 147 base::TimeDelta tpm_request_delay_; |
| 133 | 148 |
| 134 // Cached TPM token info. | 149 // Cached TPM token info. |
| 135 std::string tpm_token_name_; | 150 std::string tpm_token_name_; |
| 136 std::string tpm_token_slot_; | 151 std::string tpm_token_slot_; |
| 137 std::string tpm_user_pin_; | 152 std::string tpm_user_pin_; |
| 138 | 153 |
| 139 // Cached Certificates. | 154 // Cached Certificates. |
| 140 net::CertificateList cert_list_; | 155 net::CertificateList cert_list_; |
| 141 | 156 |
| 142 base::ThreadChecker thread_checker_; | 157 base::ThreadChecker thread_checker_; |
| 143 | 158 |
| 159 // TaskRunner for crypto calls. |
| 160 scoped_refptr<base::SequencedTaskRunner> crypto_task_runner_; |
| 161 |
| 144 // This factory should be used only for callbacks during TPMToken | 162 // This factory should be used only for callbacks during TPMToken |
| 145 // initialization. | 163 // initialization. |
| 146 base::WeakPtrFactory<CertLoader> initialize_token_factory_; | 164 base::WeakPtrFactory<CertLoader> initialize_token_factory_; |
| 147 | 165 |
| 148 // This factory should be used only for callbacks during updating the | 166 // This factory should be used only for callbacks during updating the |
| 149 // certificate list. | 167 // certificate list. |
| 150 base::WeakPtrFactory<CertLoader> update_certificates_factory_; | 168 base::WeakPtrFactory<CertLoader> update_certificates_factory_; |
| 151 | 169 |
| 170 // This factory should be used only for callbacks on the crypto task runner. |
| 171 base::WeakPtrFactory<CertLoader> crypto_factory_; |
| 172 |
| 152 DISALLOW_COPY_AND_ASSIGN(CertLoader); | 173 DISALLOW_COPY_AND_ASSIGN(CertLoader); |
| 153 }; | 174 }; |
| 154 | 175 |
| 155 } // namespace chromeos | 176 } // namespace chromeos |
| 156 | 177 |
| 157 #endif // CHROMEOS_NETWORK_CERT_LOADER_H_ | 178 #endif // CHROMEOS_NETWORK_CERT_LOADER_H_ |
| OLD | NEW |