| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 NET_BASE_DEFAULT_ORIGIN_BOUND_CERT_STORE_H_ | 5 #ifndef NET_BASE_DEFAULT_ORIGIN_BOUND_CERT_STORE_H_ |
| 6 #define NET_BASE_DEFAULT_ORIGIN_BOUND_CERT_STORE_H_ | 6 #define NET_BASE_DEFAULT_ORIGIN_BOUND_CERT_STORE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // This class is the system for storing and retrieving origin bound certs. | 24 // This class is the system for storing and retrieving origin bound certs. |
| 25 // Modelled after the CookieMonster class, it has an in-memory cert store, | 25 // Modelled after the CookieMonster class, it has an in-memory cert store, |
| 26 // and synchronizes origin bound certs to an optional permanent storage that | 26 // and synchronizes origin bound certs to an optional permanent storage that |
| 27 // implements the PersistentStore interface. The use case is described in | 27 // implements the PersistentStore interface. The use case is described in |
| 28 // http://balfanz.github.com/tls-obc-spec/draft-balfanz-tls-obc-00.html | 28 // http://balfanz.github.com/tls-obc-spec/draft-balfanz-tls-obc-00.html |
| 29 // | 29 // |
| 30 // This class can be accessed by multiple threads. For example, it can be used | 30 // This class can be accessed by multiple threads. For example, it can be used |
| 31 // by IO and origin bound cert management UI. | 31 // by IO and origin bound cert management UI. |
| 32 class NET_EXPORT DefaultOriginBoundCertStore : public OriginBoundCertStore { | 32 class NET_EXPORT DefaultOriginBoundCertStore : public OriginBoundCertStore { |
| 33 public: | 33 public: |
| 34 class OriginBoundCert; | |
| 35 class PersistentStore; | 34 class PersistentStore; |
| 36 | 35 |
| 37 // The key for each OriginBoundCert* in OriginBoundCertMap is the | 36 // The key for each OriginBoundCert* in OriginBoundCertMap is the |
| 38 // corresponding origin. | 37 // corresponding origin. |
| 39 typedef std::map<std::string, OriginBoundCert*> OriginBoundCertMap; | 38 typedef std::map<std::string, OriginBoundCert*> OriginBoundCertMap; |
| 40 | 39 |
| 41 // The store passed in should not have had Init() called on it yet. This | 40 // The store passed in should not have had Init() called on it yet. This |
| 42 // class will take care of initializing it. The backing store is NOT owned by | 41 // class will take care of initializing it. The backing store is NOT owned by |
| 43 // this class, but it must remain valid for the duration of the | 42 // this class, but it must remain valid for the duration of the |
| 44 // DefaultOriginBoundCertStore's existence. If |store| is NULL, then no | 43 // DefaultOriginBoundCertStore's existence. If |store| is NULL, then no |
| 45 // backing store will be updated. | 44 // backing store will be updated. |
| 46 explicit DefaultOriginBoundCertStore(PersistentStore* store); | 45 explicit DefaultOriginBoundCertStore(PersistentStore* store); |
| 47 | 46 |
| 48 virtual ~DefaultOriginBoundCertStore(); | 47 virtual ~DefaultOriginBoundCertStore(); |
| 49 | 48 |
| 50 // Flush the backing store (if any) to disk and post the given task when done. | 49 // Flush the backing store (if any) to disk and post the given task when done. |
| 51 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. | 50 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. |
| 52 // It may be posted to the current thread, or it may run on the thread that | 51 // It may be posted to the current thread, or it may run on the thread that |
| 53 // actually does the flushing. Your Task should generally post a notification | 52 // actually does the flushing. Your Task should generally post a notification |
| 54 // to the thread you actually want to be notified on. | 53 // to the thread you actually want to be notified on. |
| 55 void FlushStore(const base::Closure& completion_task); | 54 void FlushStore(const base::Closure& completion_task); |
| 56 | 55 |
| 57 // OriginBoundCertStore implementation. | 56 // OriginBoundCertStore implementation. |
| 58 virtual bool GetOriginBoundCert(const std::string& origin, | 57 virtual bool GetOriginBoundCert( |
| 59 std::string* private_key_result, | 58 const std::string& origin, |
| 60 std::string* cert_result) OVERRIDE; | 59 SSLClientCertType* type, |
| 61 virtual void SetOriginBoundCert(const std::string& origin, | 60 std::string* private_key_result, |
| 62 const std::string& private_key, | 61 std::string* cert_result) OVERRIDE; |
| 63 const std::string& cert) OVERRIDE; | 62 virtual void SetOriginBoundCert( |
| 63 const std::string& origin, |
| 64 SSLClientCertType type, |
| 65 const std::string& private_key, |
| 66 const std::string& cert) OVERRIDE; |
| 64 virtual void DeleteOriginBoundCert(const std::string& origin) OVERRIDE; | 67 virtual void DeleteOriginBoundCert(const std::string& origin) OVERRIDE; |
| 65 virtual void DeleteAll() OVERRIDE; | 68 virtual void DeleteAll() OVERRIDE; |
| 66 virtual void GetAllOriginBoundCerts( | 69 virtual void GetAllOriginBoundCerts( |
| 67 std::vector<OriginBoundCertInfo>* origin_bound_certs) OVERRIDE; | 70 std::vector<OriginBoundCert>* origin_bound_certs) OVERRIDE; |
| 68 virtual int GetCertCount() OVERRIDE; | 71 virtual int GetCertCount() OVERRIDE; |
| 69 | 72 |
| 70 private: | 73 private: |
| 71 static const size_t kMaxCerts; | 74 static const size_t kMaxCerts; |
| 72 | 75 |
| 73 // Deletes all of the certs. Does not delete them from |store_|. | 76 // Deletes all of the certs. Does not delete them from |store_|. |
| 74 void DeleteAllInMemory(); | 77 void DeleteAllInMemory(); |
| 75 | 78 |
| 76 // Called by all non-static functions to ensure that the cert store has | 79 // Called by all non-static functions to ensure that the cert store has |
| 77 // been initialized. This is not done during creating so it doesn't block | 80 // been initialized. This is not done during creating so it doesn't block |
| (...skipping 28 matching lines...) Expand all Loading... |
| 106 scoped_refptr<PersistentStore> store_; | 109 scoped_refptr<PersistentStore> store_; |
| 107 | 110 |
| 108 OriginBoundCertMap origin_bound_certs_; | 111 OriginBoundCertMap origin_bound_certs_; |
| 109 | 112 |
| 110 // Lock for thread-safety | 113 // Lock for thread-safety |
| 111 base::Lock lock_; | 114 base::Lock lock_; |
| 112 | 115 |
| 113 DISALLOW_COPY_AND_ASSIGN(DefaultOriginBoundCertStore); | 116 DISALLOW_COPY_AND_ASSIGN(DefaultOriginBoundCertStore); |
| 114 }; | 117 }; |
| 115 | 118 |
| 116 // The OriginBoundCert class contains a private key in addition to the origin | |
| 117 // and the cert. | |
| 118 class NET_EXPORT DefaultOriginBoundCertStore::OriginBoundCert { | |
| 119 public: | |
| 120 OriginBoundCert(); | |
| 121 OriginBoundCert(const std::string& origin, | |
| 122 const std::string& privatekey, | |
| 123 const std::string& cert); | |
| 124 | |
| 125 const std::string& origin() const { return origin_; } | |
| 126 const std::string& private_key() const { return private_key_; } | |
| 127 const std::string& cert() const { return cert_; } | |
| 128 | |
| 129 private: | |
| 130 std::string origin_; | |
| 131 std::string private_key_; | |
| 132 std::string cert_; | |
| 133 }; | |
| 134 | |
| 135 typedef base::RefCountedThreadSafe<DefaultOriginBoundCertStore::PersistentStore> | 119 typedef base::RefCountedThreadSafe<DefaultOriginBoundCertStore::PersistentStore> |
| 136 RefcountedPersistentStore; | 120 RefcountedPersistentStore; |
| 137 | 121 |
| 138 class NET_EXPORT DefaultOriginBoundCertStore::PersistentStore | 122 class NET_EXPORT DefaultOriginBoundCertStore::PersistentStore |
| 139 : public RefcountedPersistentStore { | 123 : public RefcountedPersistentStore { |
| 140 public: | 124 public: |
| 141 virtual ~PersistentStore() {} | 125 virtual ~PersistentStore() {} |
| 142 | 126 |
| 143 // Initializes the store and retrieves the existing certs. This will be | 127 // Initializes the store and retrieves the existing certs. This will be |
| 144 // called only once at startup. Note that the certs are individually allocated | 128 // called only once at startup. Note that the certs are individually allocated |
| 145 // and that ownership is transferred to the caller upon return. | 129 // and that ownership is transferred to the caller upon return. |
| 146 virtual bool Load( | 130 virtual bool Load( |
| 147 std::vector<DefaultOriginBoundCertStore::OriginBoundCert*>* certs) = 0; | 131 std::vector<OriginBoundCert*>* certs) = 0; |
| 148 | 132 |
| 149 virtual void AddOriginBoundCert(const OriginBoundCert& cert) = 0; | 133 virtual void AddOriginBoundCert(const OriginBoundCert& cert) = 0; |
| 150 | 134 |
| 151 virtual void DeleteOriginBoundCert(const OriginBoundCert& cert) = 0; | 135 virtual void DeleteOriginBoundCert(const OriginBoundCert& cert) = 0; |
| 152 | 136 |
| 153 // Sets the value of the user preference whether the persistent storage | 137 // Sets the value of the user preference whether the persistent storage |
| 154 // must be deleted upon destruction. | 138 // must be deleted upon destruction. |
| 155 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; | 139 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; |
| 156 | 140 |
| 157 // Flush the store and post the given Task when complete. | 141 // Flush the store and post the given Task when complete. |
| 158 virtual void Flush(const base::Closure& completion_task) = 0; | 142 virtual void Flush(const base::Closure& completion_task) = 0; |
| 159 | 143 |
| 160 protected: | 144 protected: |
| 161 PersistentStore(); | 145 PersistentStore(); |
| 162 | 146 |
| 163 private: | 147 private: |
| 164 DISALLOW_COPY_AND_ASSIGN(PersistentStore); | 148 DISALLOW_COPY_AND_ASSIGN(PersistentStore); |
| 165 }; | 149 }; |
| 166 | 150 |
| 167 } // namespace net | 151 } // namespace net |
| 168 | 152 |
| 169 #endif // NET_DEFAULT_ORIGIN_BOUND_CERT_STORE_H_ | 153 #endif // NET_DEFAULT_ORIGIN_BOUND_CERT_STORE_H_ |
| OLD | NEW |