Chromium Code Reviews| 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 // expexts it to stay alive at least until the shutdown of the main thread. | |
|
mattm
2014/01/30 04:34:37
expects
mattm
2014/01/30 04:34:37
This doesn't seem true, or maybe just confusingly
tbarzic
2014/02/03 23:42:05
Not worded precisely enough. It should be:
"it exp
tbarzic
2014/02/03 23:42:05
Done.
| |
| 68 void StartWithNSSDB(net::NSSCertDatabase* database); | 65 void StartWithNSSDB(net::NSSCertDatabase* database); |
| 69 | 66 |
| 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); | 67 void AddObserver(CertLoader::Observer* observer); |
| 76 void RemoveObserver(CertLoader::Observer* observer); | 68 void RemoveObserver(CertLoader::Observer* observer); |
| 77 | 69 |
| 78 int TPMTokenSlotID() const; | 70 int TPMTokenSlotID() const; |
| 79 bool IsHardwareBacked() const; | 71 bool IsHardwareBacked() const; |
| 80 | 72 |
| 81 // Whether the certificate is hardware backed. Returns false if the CertLoader | 73 // Whether the certificate is hardware backed. Returns false if the CertLoader |
| 82 // was not yet started (both |CertificatesLoading()| and | 74 // was not yet started (both |CertificatesLoading()| and |
| 83 // |certificates_loaded()| are false). | 75 // |certificates_loaded()| are false). |
| 84 bool IsCertificateHardwareBacked(const net::X509Certificate* cert) const; | 76 bool IsCertificateHardwareBacked(const net::X509Certificate* cert) const; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 97 | 89 |
| 98 private: | 90 private: |
| 99 CertLoader(); | 91 CertLoader(); |
| 100 virtual ~CertLoader(); | 92 virtual ~CertLoader(); |
| 101 | 93 |
| 102 // Trigger a certificate load. If a certificate loading task is already in | 94 // Trigger a certificate load. If a certificate loading task is already in |
| 103 // progress, will start a reload once the current task is finished. | 95 // progress, will start a reload once the current task is finished. |
| 104 void LoadCertificates(); | 96 void LoadCertificates(); |
| 105 | 97 |
| 106 // Called if a certificate load task is finished. | 98 // Called if a certificate load task is finished. |
| 107 void UpdateCertificates(net::CertificateList* cert_list); | 99 void UpdateCertificates(scoped_ptr<net::CertificateList> cert_list); |
| 108 | 100 |
| 109 void NotifyCertificatesLoaded(bool initial_load); | 101 void NotifyCertificatesLoaded(bool initial_load); |
| 110 | 102 |
| 111 // net::CertDatabase::Observer | 103 // net::CertDatabase::Observer |
| 112 virtual void OnCACertChanged(const net::X509Certificate* cert) OVERRIDE; | 104 virtual void OnCACertChanged(const net::X509Certificate* cert) OVERRIDE; |
| 113 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE; | 105 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE; |
| 114 virtual void OnCertRemoved(const net::X509Certificate* cert) OVERRIDE; | 106 virtual void OnCertRemoved(const net::X509Certificate* cert) OVERRIDE; |
| 115 | 107 |
| 116 ObserverList<Observer> observers_; | 108 ObserverList<Observer> observers_; |
| 117 | 109 |
| 118 // Flags describing current CertLoader state. | 110 // Flags describing current CertLoader state. |
| 119 bool certificates_loaded_; | 111 bool certificates_loaded_; |
| 120 bool certificates_update_required_; | 112 bool certificates_update_required_; |
| 121 bool certificates_update_running_; | 113 bool certificates_update_running_; |
| 122 | 114 |
| 123 // The user-specific NSS certificate database from which the certificates | 115 // The user-specific NSS certificate database from which the certificates |
| 124 // should be loaded. | 116 // should be loaded. |
| 125 net::NSSCertDatabase* database_; | 117 net::NSSCertDatabase* database_; |
| 126 | 118 |
| 127 // Set during tests if |IsHardwareBacked()| should always return true. | 119 // Set during tests if |IsHardwareBacked()| should always return true. |
| 128 bool force_hardware_backed_for_test_; | 120 bool force_hardware_backed_for_test_; |
| 129 | 121 |
| 130 // Cached Certificates loaded from the database. | 122 // Cached Certificates loaded from the database. |
| 131 net::CertificateList cert_list_; | 123 net::CertificateList cert_list_; |
| 132 | 124 |
| 133 base::ThreadChecker thread_checker_; | 125 base::ThreadChecker thread_checker_; |
| 134 | 126 |
| 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_; | 127 base::WeakPtrFactory<CertLoader> weak_factory_; |
| 140 | 128 |
| 141 DISALLOW_COPY_AND_ASSIGN(CertLoader); | 129 DISALLOW_COPY_AND_ASSIGN(CertLoader); |
| 142 }; | 130 }; |
| 143 | 131 |
| 144 } // namespace chromeos | 132 } // namespace chromeos |
| 145 | 133 |
| 146 #endif // CHROMEOS_CERT_LOADER_H_ | 134 #endif // CHROMEOS_CERT_LOADER_H_ |
| OLD | NEW |