| 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_CERT_LOADER_H_ | 5 #ifndef CHROMEOS_CERT_LOADER_H_ |
| 6 #define CHROMEOS_CERT_LOADER_H_ | 6 #define CHROMEOS_CERT_LOADER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.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 "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "chromeos/chromeos_export.h" | 17 #include "chromeos/chromeos_export.h" |
| 18 #include "net/cert/cert_database.h" | 18 #include "net/cert/cert_database.h" |
| 19 | 19 |
| 20 namespace base { | |
| 21 class TaskRunner; | |
| 22 } | |
| 23 | |
| 24 namespace net { | 20 namespace net { |
| 25 class NSSCertDatabase; | 21 class NSSCertDatabase; |
| 26 class X509Certificate; | 22 class X509Certificate; |
| 27 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; | 23 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; |
| 28 } | 24 } |
| 29 | 25 |
| 30 namespace chromeos { | 26 namespace chromeos { |
| 31 | 27 |
| 32 // This class is responsible for loading certificates once the TPM is | 28 // This class is responsible for loading certificates once the TPM is |
| 33 // initialized. It is expected to be constructed on the UI thread and public | 29 // initialized. It is expected to be constructed on the UI thread and public |
| (...skipping 23 matching lines...) Expand all Loading... |
| 57 | 53 |
| 58 // Gets the global instance. Initialize() must be called first. | 54 // Gets the global instance. Initialize() must be called first. |
| 59 static CertLoader* Get(); | 55 static CertLoader* Get(); |
| 60 | 56 |
| 61 // Returns true if the global instance has been initialized. | 57 // Returns true if the global instance has been initialized. |
| 62 static bool IsInitialized(); | 58 static bool IsInitialized(); |
| 63 | 59 |
| 64 static std::string GetPkcs11IdForCert(const net::X509Certificate& cert); | 60 static std::string GetPkcs11IdForCert(const net::X509Certificate& cert); |
| 65 | 61 |
| 66 // Starts the CertLoader with the NSS cert database. | 62 // Starts the CertLoader with the NSS cert database. |
| 67 // The CertLoader will _not_ take the ownership of the database. | 63 // The CertLoader will _not_ take the ownership of the database, but it |
| 64 // expects it to stay alive at least until the shutdown starts on the main |
| 65 // thread. This assumes that |StartWithNSSDB| and other methods directly |
| 66 // using |database_| are not called during shutdown. |
| 68 void StartWithNSSDB(net::NSSCertDatabase* database); | 67 void StartWithNSSDB(net::NSSCertDatabase* database); |
| 69 | 68 |
| 70 // Sets the task runner that any slow calls will be made from, e.g. calls | |
| 71 // to the NSS database. If not set, uses base::WorkerPool. | |
| 72 void SetSlowTaskRunnerForTest( | |
| 73 const scoped_refptr<base::TaskRunner>& task_runner); | |
| 74 | |
| 75 void AddObserver(CertLoader::Observer* observer); | 69 void AddObserver(CertLoader::Observer* observer); |
| 76 void RemoveObserver(CertLoader::Observer* observer); | 70 void RemoveObserver(CertLoader::Observer* observer); |
| 77 | 71 |
| 78 int TPMTokenSlotID() const; | 72 int TPMTokenSlotID() const; |
| 79 bool IsHardwareBacked() const; | 73 bool IsHardwareBacked() const; |
| 80 | 74 |
| 81 // Whether the certificate is hardware backed. Returns false if the CertLoader | 75 // Whether the certificate is hardware backed. Returns false if the CertLoader |
| 82 // was not yet started (both |CertificatesLoading()| and | 76 // was not yet started (both |CertificatesLoading()| and |
| 83 // |certificates_loaded()| are false). | 77 // |certificates_loaded()| are false). |
| 84 bool IsCertificateHardwareBacked(const net::X509Certificate* cert) const; | 78 bool IsCertificateHardwareBacked(const net::X509Certificate* cert) const; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 97 | 91 |
| 98 private: | 92 private: |
| 99 CertLoader(); | 93 CertLoader(); |
| 100 virtual ~CertLoader(); | 94 virtual ~CertLoader(); |
| 101 | 95 |
| 102 // Trigger a certificate load. If a certificate loading task is already in | 96 // Trigger a certificate load. If a certificate loading task is already in |
| 103 // progress, will start a reload once the current task is finished. | 97 // progress, will start a reload once the current task is finished. |
| 104 void LoadCertificates(); | 98 void LoadCertificates(); |
| 105 | 99 |
| 106 // Called if a certificate load task is finished. | 100 // Called if a certificate load task is finished. |
| 107 void UpdateCertificates(net::CertificateList* cert_list); | 101 void UpdateCertificates(scoped_ptr<net::CertificateList> cert_list); |
| 108 | 102 |
| 109 void NotifyCertificatesLoaded(bool initial_load); | 103 void NotifyCertificatesLoaded(bool initial_load); |
| 110 | 104 |
| 111 // net::CertDatabase::Observer | 105 // net::CertDatabase::Observer |
| 112 virtual void OnCACertChanged(const net::X509Certificate* cert) OVERRIDE; | 106 virtual void OnCACertChanged(const net::X509Certificate* cert) OVERRIDE; |
| 113 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE; | 107 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE; |
| 114 virtual void OnCertRemoved(const net::X509Certificate* cert) OVERRIDE; | 108 virtual void OnCertRemoved(const net::X509Certificate* cert) OVERRIDE; |
| 115 | 109 |
| 116 ObserverList<Observer> observers_; | 110 ObserverList<Observer> observers_; |
| 117 | 111 |
| 118 // Flags describing current CertLoader state. | 112 // Flags describing current CertLoader state. |
| 119 bool certificates_loaded_; | 113 bool certificates_loaded_; |
| 120 bool certificates_update_required_; | 114 bool certificates_update_required_; |
| 121 bool certificates_update_running_; | 115 bool certificates_update_running_; |
| 122 | 116 |
| 123 // The user-specific NSS certificate database from which the certificates | 117 // The user-specific NSS certificate database from which the certificates |
| 124 // should be loaded. | 118 // should be loaded. |
| 125 net::NSSCertDatabase* database_; | 119 net::NSSCertDatabase* database_; |
| 126 | 120 |
| 127 // Set during tests if |IsHardwareBacked()| should always return true. | 121 // Set during tests if |IsHardwareBacked()| should always return true. |
| 128 bool force_hardware_backed_for_test_; | 122 bool force_hardware_backed_for_test_; |
| 129 | 123 |
| 130 // Cached Certificates loaded from the database. | 124 // Cached Certificates loaded from the database. |
| 131 net::CertificateList cert_list_; | 125 net::CertificateList cert_list_; |
| 132 | 126 |
| 133 base::ThreadChecker thread_checker_; | 127 base::ThreadChecker thread_checker_; |
| 134 | 128 |
| 135 // TaskRunner that, if set, replaces base::WorkerPool. Should only be set in | |
| 136 // tests. | |
| 137 scoped_refptr<base::TaskRunner> slow_task_runner_for_test_; | |
| 138 | |
| 139 base::WeakPtrFactory<CertLoader> weak_factory_; | 129 base::WeakPtrFactory<CertLoader> weak_factory_; |
| 140 | 130 |
| 141 DISALLOW_COPY_AND_ASSIGN(CertLoader); | 131 DISALLOW_COPY_AND_ASSIGN(CertLoader); |
| 142 }; | 132 }; |
| 143 | 133 |
| 144 } // namespace chromeos | 134 } // namespace chromeos |
| 145 | 135 |
| 146 #endif // CHROMEOS_CERT_LOADER_H_ | 136 #endif // CHROMEOS_CERT_LOADER_H_ |
| OLD | NEW |