| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SERVER_BOUND_CERT_SERVICE_H_ | 5 #ifndef NET_BASE_SERVER_BOUND_CERT_SERVICE_H_ |
| 6 #define NET_BASE_SERVER_BOUND_CERT_SERVICE_H_ | 6 #define NET_BASE_SERVER_BOUND_CERT_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
| 18 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
| 19 #include "net/base/server_bound_cert_store.h" | 19 #include "net/base/server_bound_cert_store.h" |
| 20 #include "net/base/ssl_client_cert_type.h" | 20 #include "net/base/ssl_client_cert_type.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class TaskRunner; | 23 class TaskRunner; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 class ServerBoundCertServiceJob; | 28 class ServerBoundCertServiceJob; |
| 29 class ServerBoundCertServiceRequest; |
| 29 class ServerBoundCertServiceWorker; | 30 class ServerBoundCertServiceWorker; |
| 30 | 31 |
| 31 // A class for creating and fetching server bound certs. | 32 // A class for creating and fetching server bound certs. |
| 32 // Inherits from NonThreadSafe in order to use the function | 33 // Inherits from NonThreadSafe in order to use the function |
| 33 // |CalledOnValidThread|. | 34 // |CalledOnValidThread|. |
| 34 class NET_EXPORT ServerBoundCertService | 35 class NET_EXPORT ServerBoundCertService |
| 35 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 36 : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 36 public: | 37 public: |
| 37 // Opaque type used to cancel a request. | 38 class NET_EXPORT RequestHandle { |
| 38 typedef void* RequestHandle; | 39 public: |
| 40 RequestHandle(); |
| 41 ~RequestHandle(); |
| 42 |
| 43 // Cancel the request. Does nothing if the request finished or was already |
| 44 // cancelled. |
| 45 void Cancel(); |
| 46 |
| 47 bool is_active() const { return request_ != NULL; } |
| 48 |
| 49 private: |
| 50 friend class ServerBoundCertService; |
| 51 |
| 52 void RequestStarted(ServerBoundCertService* service, |
| 53 ServerBoundCertServiceRequest* request, |
| 54 const CompletionCallback& callback); |
| 55 |
| 56 void OnRequestComplete(int result); |
| 57 |
| 58 ServerBoundCertService* service_; |
| 59 ServerBoundCertServiceRequest* request_; |
| 60 CompletionCallback callback_; |
| 61 }; |
| 39 | 62 |
| 40 // Password used on EncryptedPrivateKeyInfo data stored in EC private_key | 63 // Password used on EncryptedPrivateKeyInfo data stored in EC private_key |
| 41 // values. (This is not used to provide any security, but to workaround NSS | 64 // values. (This is not used to provide any security, but to workaround NSS |
| 42 // being unable to import unencrypted PrivateKeyInfo for EC keys.) | 65 // being unable to import unencrypted PrivateKeyInfo for EC keys.) |
| 43 static const char kEPKIPassword[]; | 66 static const char kEPKIPassword[]; |
| 44 | 67 |
| 45 // This object owns |server_bound_cert_store|. |task_runner| will | 68 // This object owns |server_bound_cert_store|. |task_runner| will |
| 46 // be used to post certificate generation worker tasks. The tasks are | 69 // be used to post certificate generation worker tasks. The tasks are |
| 47 // safe for use with WorkerPool and SequencedWorkerPool::CONTINUE_ON_SHUTDOWN. | 70 // safe for use with WorkerPool and SequencedWorkerPool::CONTINUE_ON_SHUTDOWN. |
| 48 ServerBoundCertService( | 71 ServerBoundCertService( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 71 // support will be ignored. See ssl_client_cert_type.h. | 94 // support will be ignored. See ssl_client_cert_type.h. |
| 72 // | 95 // |
| 73 // On successful completion, |private_key| stores a DER-encoded | 96 // On successful completion, |private_key| stores a DER-encoded |
| 74 // PrivateKeyInfo struct, and |cert| stores a DER-encoded certificate, and | 97 // PrivateKeyInfo struct, and |cert| stores a DER-encoded certificate, and |
| 75 // |type| specifies the type of certificate that was returned. | 98 // |type| specifies the type of certificate that was returned. |
| 76 // | 99 // |
| 77 // |callback| must not be null. ERR_IO_PENDING is returned if the operation | 100 // |callback| must not be null. ERR_IO_PENDING is returned if the operation |
| 78 // could not be completed immediately, in which case the result code will | 101 // could not be completed immediately, in which case the result code will |
| 79 // be passed to the callback when available. | 102 // be passed to the callback when available. |
| 80 // | 103 // |
| 81 // |*out_req| will be filled with a handle to the async request. This handle | 104 // |*out_req| will be initialized with a handle to the async request. This |
| 82 // is not valid after the request has completed. | 105 // RequestHandle object must be cancelled or destroyed before the |
| 106 // ServerBoundCertService is destroyed. |
| 83 int GetDomainBoundCert( | 107 int GetDomainBoundCert( |
| 84 const std::string& origin, | 108 const std::string& origin, |
| 85 const std::vector<uint8>& requested_types, | 109 const std::vector<uint8>& requested_types, |
| 86 SSLClientCertType* type, | 110 SSLClientCertType* type, |
| 87 std::string* private_key, | 111 std::string* private_key, |
| 88 std::string* cert, | 112 std::string* cert, |
| 89 const CompletionCallback& callback, | 113 const CompletionCallback& callback, |
| 90 RequestHandle* out_req); | 114 RequestHandle* out_req); |
| 91 | 115 |
| 92 // Cancels the specified request. |req| is the handle returned by | |
| 93 // GetDomainBoundCert(). After a request is canceled, its completion | |
| 94 // callback will not be called. | |
| 95 void CancelRequest(RequestHandle req); | |
| 96 | |
| 97 // Returns the backing ServerBoundCertStore. | 116 // Returns the backing ServerBoundCertStore. |
| 98 ServerBoundCertStore* GetCertStore(); | 117 ServerBoundCertStore* GetCertStore(); |
| 99 | 118 |
| 100 // Public only for unit testing. | 119 // Public only for unit testing. |
| 101 int cert_count(); | 120 int cert_count(); |
| 102 uint64 requests() const { return requests_; } | 121 uint64 requests() const { return requests_; } |
| 103 uint64 cert_store_hits() const { return cert_store_hits_; } | 122 uint64 cert_store_hits() const { return cert_store_hits_; } |
| 104 uint64 inflight_joins() const { return inflight_joins_; } | 123 uint64 inflight_joins() const { return inflight_joins_; } |
| 105 | 124 |
| 106 private: | 125 private: |
| 126 // Cancels the specified request. |req| is the handle stored by |
| 127 // GetDomainBoundCert(). After a request is canceled, its completion |
| 128 // callback will not be called. |
| 129 void CancelRequest(ServerBoundCertServiceRequest* req); |
| 130 |
| 107 void HandleResult(const std::string& server_identifier, | 131 void HandleResult(const std::string& server_identifier, |
| 108 int error, | 132 int error, |
| 109 scoped_ptr<ServerBoundCertStore::ServerBoundCert> cert); | 133 scoped_ptr<ServerBoundCertStore::ServerBoundCert> cert); |
| 110 | 134 |
| 111 scoped_ptr<ServerBoundCertStore> server_bound_cert_store_; | 135 scoped_ptr<ServerBoundCertStore> server_bound_cert_store_; |
| 112 scoped_refptr<base::TaskRunner> task_runner_; | 136 scoped_refptr<base::TaskRunner> task_runner_; |
| 113 | 137 |
| 114 // inflight_ maps from a server to an active generation which is taking | 138 // inflight_ maps from a server to an active generation which is taking |
| 115 // place. | 139 // place. |
| 116 std::map<std::string, ServerBoundCertServiceJob*> inflight_; | 140 std::map<std::string, ServerBoundCertServiceJob*> inflight_; |
| 117 base::WeakPtrFactory<ServerBoundCertService> weak_ptr_factory_; | 141 base::WeakPtrFactory<ServerBoundCertService> weak_ptr_factory_; |
| 118 | 142 |
| 119 uint64 requests_; | 143 uint64 requests_; |
| 120 uint64 cert_store_hits_; | 144 uint64 cert_store_hits_; |
| 121 uint64 inflight_joins_; | 145 uint64 inflight_joins_; |
| 122 | 146 |
| 123 bool is_system_time_valid_; | 147 bool is_system_time_valid_; |
| 124 | 148 |
| 125 DISALLOW_COPY_AND_ASSIGN(ServerBoundCertService); | 149 DISALLOW_COPY_AND_ASSIGN(ServerBoundCertService); |
| 126 }; | 150 }; |
| 127 | 151 |
| 128 } // namespace net | 152 } // namespace net |
| 129 | 153 |
| 130 #endif // NET_BASE_SERVER_BOUND_CERT_SERVICE_H_ | 154 #endif // NET_BASE_SERVER_BOUND_CERT_SERVICE_H_ |
| OLD | NEW |