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_ORIGIN_BOUND_CERT_SERVICE_H_ | 5 #ifndef NET_BASE_ORIGIN_BOUND_CERT_SERVICE_H_ |
6 #define NET_BASE_ORIGIN_BOUND_CERT_SERVICE_H_ | 6 #define NET_BASE_ORIGIN_BOUND_CERT_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.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/ssl_client_cert_type.h" | 19 #include "net/base/ssl_client_cert_type.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
23 class OriginBoundCertServiceJob; | 23 class ServerBoundCertServiceJob; |
24 class OriginBoundCertServiceWorker; | 24 class ServerBoundCertServiceWorker; |
25 class OriginBoundCertStore; | 25 class ServerBoundCertStore; |
26 | 26 |
27 // A class for creating and fetching origin bound certs. | 27 // A class for creating and fetching domain bound certs. |
wtc
2012/03/15 23:46:38
Should this be "server bound certs"?
mattm
2012/03/16 22:22:00
Done.
| |
28 // Inherits from NonThreadSafe in order to use the function | 28 // Inherits from NonThreadSafe in order to use the function |
29 // |CalledOnValidThread|. | 29 // |CalledOnValidThread|. |
30 class NET_EXPORT OriginBoundCertService | 30 class NET_EXPORT ServerBoundCertService |
31 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 31 : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
32 public: | 32 public: |
33 // Opaque type used to cancel a request. | 33 // Opaque type used to cancel a request. |
34 typedef void* RequestHandle; | 34 typedef void* RequestHandle; |
35 | 35 |
36 // Password used on EncryptedPrivateKeyInfo data stored in EC private_key | 36 // Password used on EncryptedPrivateKeyInfo data stored in EC private_key |
37 // values. (This is not used to provide any security, but to workaround NSS | 37 // values. (This is not used to provide any security, but to workaround NSS |
38 // being unable to import unencrypted PrivateKeyInfo for EC keys.) | 38 // being unable to import unencrypted PrivateKeyInfo for EC keys.) |
39 static const char kEPKIPassword[]; | 39 static const char kEPKIPassword[]; |
40 | 40 |
41 // This object owns origin_bound_cert_store. | 41 // This object owns server_bound_cert_store. |
42 explicit OriginBoundCertService( | 42 explicit ServerBoundCertService( |
43 OriginBoundCertStore* origin_bound_cert_store); | 43 ServerBoundCertStore* server_bound_cert_store); |
44 | 44 |
45 ~OriginBoundCertService(); | 45 ~ServerBoundCertService(); |
46 | 46 |
47 // Returns the domain to be used for |host|. The domain is the | 47 // Returns the domain to be used for |host|. The domain is the |
48 // "registry controlled domain", or the "ETLD + 1" where one exists, or | 48 // "registry controlled domain", or the "ETLD + 1" where one exists, or |
49 // the origin otherwise. | 49 // the origin otherwise. |
50 static std::string GetDomainForHost(const std::string& host); | 50 static std::string GetDomainForHost(const std::string& host); |
51 | 51 |
52 // Fetches the origin bound cert for the specified origin of the specified | 52 // Fetches the domain bound cert for the specified origin of the specified |
53 // type if one exists and creates one otherwise. Returns OK if successful or | 53 // type if one exists and creates one otherwise. Returns OK if successful or |
54 // an error code upon failure. | 54 // an error code upon failure. |
55 // | 55 // |
56 // |requested_types| is a list of the TLS ClientCertificateTypes the site will | 56 // |requested_types| is a list of the TLS ClientCertificateTypes the site will |
57 // accept, ordered from most preferred to least preferred. Types we don't | 57 // accept, ordered from most preferred to least preferred. Types we don't |
58 // support will be ignored. See ssl_client_cert_type.h. | 58 // support will be ignored. See ssl_client_cert_type.h. |
59 // | 59 // |
60 // On successful completion, |private_key| stores a DER-encoded | 60 // On successful completion, |private_key| stores a DER-encoded |
61 // PrivateKeyInfo struct, and |cert| stores a DER-encoded certificate, and | 61 // PrivateKeyInfo struct, and |cert| stores a DER-encoded certificate, and |
62 // |type| specifies the type of certificate that was returned. | 62 // |type| specifies the type of certificate that was returned. |
63 // | 63 // |
64 // |callback| must not be null. ERR_IO_PENDING is returned if the operation | 64 // |callback| must not be null. ERR_IO_PENDING is returned if the operation |
65 // could not be completed immediately, in which case the result code will | 65 // could not be completed immediately, in which case the result code will |
66 // be passed to the callback when available. | 66 // be passed to the callback when available. |
67 // | 67 // |
68 // |*out_req| will be filled with a handle to the async request. This handle | 68 // |*out_req| will be filled with a handle to the async request. This handle |
69 // is not valid after the request has completed. | 69 // is not valid after the request has completed. |
70 int GetOriginBoundCert( | 70 int GetDomainBoundCert( |
71 const std::string& origin, | 71 const std::string& origin, |
72 const std::vector<uint8>& requested_types, | 72 const std::vector<uint8>& requested_types, |
73 SSLClientCertType* type, | 73 SSLClientCertType* type, |
74 std::string* private_key, | 74 std::string* private_key, |
75 std::string* cert, | 75 std::string* cert, |
76 const CompletionCallback& callback, | 76 const CompletionCallback& callback, |
77 RequestHandle* out_req); | 77 RequestHandle* out_req); |
78 | 78 |
79 // Cancels the specified request. |req| is the handle returned by | 79 // Cancels the specified request. |req| is the handle returned by |
80 // GetOriginBoundCert(). After a request is canceled, its completion | 80 // GetServerBoundCert(). After a request is canceled, its completion |
wtc
2012/03/15 23:46:38
Typo: GetServerBoundCert => GetDomainBoundCert ?
mattm
2012/03/16 22:22:00
Done.
| |
81 // callback will not be called. | 81 // callback will not be called. |
82 void CancelRequest(RequestHandle req); | 82 void CancelRequest(RequestHandle req); |
83 | 83 |
84 // Returns the backing OriginBoundCertStore. | 84 // Returns the backing ServerBoundCertStore. |
85 OriginBoundCertStore* GetCertStore(); | 85 ServerBoundCertStore* GetCertStore(); |
86 | 86 |
87 // Public only for unit testing. | 87 // Public only for unit testing. |
88 int cert_count(); | 88 int cert_count(); |
89 uint64 requests() const { return requests_; } | 89 uint64 requests() const { return requests_; } |
90 uint64 cert_store_hits() const { return cert_store_hits_; } | 90 uint64 cert_store_hits() const { return cert_store_hits_; } |
91 uint64 inflight_joins() const { return inflight_joins_; } | 91 uint64 inflight_joins() const { return inflight_joins_; } |
92 | 92 |
93 private: | 93 private: |
94 friend class OriginBoundCertServiceWorker; // Calls HandleResult. | 94 friend class ServerBoundCertServiceWorker; // Calls HandleResult. |
95 | 95 |
96 // On success, |private_key| stores a DER-encoded PrivateKeyInfo | 96 // On success, |private_key| stores a DER-encoded PrivateKeyInfo |
97 // struct, |cert| stores a DER-encoded certificate, |creation_time| stores the | 97 // struct, |cert| stores a DER-encoded certificate, |creation_time| stores the |
98 // start of the validity period of the certificate and |expiration_time| | 98 // start of the validity period of the certificate and |expiration_time| |
99 // stores the expiration time of the certificate. Returns OK if successful and | 99 // stores the expiration time of the certificate. Returns OK if successful and |
100 // an error code otherwise. | 100 // an error code otherwise. |
101 // |serial_number| is passed in because it is created with the function | 101 // |serial_number| is passed in because it is created with the function |
102 // base::RandInt, which opens the file /dev/urandom. /dev/urandom is opened | 102 // base::RandInt, which opens the file /dev/urandom. /dev/urandom is opened |
103 // with a LazyInstance, which is not allowed on a worker thread. | 103 // with a LazyInstance, which is not allowed on a worker thread. |
wtc
2012/03/15 23:46:38
I suggest renaming 'server' to 'server_name_key' o
mattm
2012/03/16 22:22:00
Done.
| |
104 static int GenerateCert(const std::string& origin, | 104 static int GenerateCert(const std::string& server, |
105 SSLClientCertType type, | 105 SSLClientCertType type, |
106 uint32 serial_number, | 106 uint32 serial_number, |
107 base::Time* creation_time, | 107 base::Time* creation_time, |
108 base::Time* expiration_time, | 108 base::Time* expiration_time, |
109 std::string* private_key, | 109 std::string* private_key, |
110 std::string* cert); | 110 std::string* cert); |
111 | 111 |
112 void HandleResult(const std::string& origin, | 112 void HandleResult(const std::string& server, |
113 int error, | 113 int error, |
114 SSLClientCertType type, | 114 SSLClientCertType type, |
115 base::Time creation_time, | 115 base::Time creation_time, |
116 base::Time expiration_time, | 116 base::Time expiration_time, |
117 const std::string& private_key, | 117 const std::string& private_key, |
118 const std::string& cert); | 118 const std::string& cert); |
119 | 119 |
120 scoped_ptr<OriginBoundCertStore> origin_bound_cert_store_; | 120 scoped_ptr<ServerBoundCertStore> server_bound_cert_store_; |
121 | 121 |
122 // inflight_ maps from an origin to an active generation which is taking | 122 // inflight_ maps from a server to an active generation which is taking |
123 // place. | 123 // place. |
124 std::map<std::string, OriginBoundCertServiceJob*> inflight_; | 124 std::map<std::string, ServerBoundCertServiceJob*> inflight_; |
125 | 125 |
126 uint64 requests_; | 126 uint64 requests_; |
127 uint64 cert_store_hits_; | 127 uint64 cert_store_hits_; |
128 uint64 inflight_joins_; | 128 uint64 inflight_joins_; |
129 | 129 |
130 DISALLOW_COPY_AND_ASSIGN(OriginBoundCertService); | 130 DISALLOW_COPY_AND_ASSIGN(ServerBoundCertService); |
131 }; | 131 }; |
132 | 132 |
133 } // namespace net | 133 } // namespace net |
134 | 134 |
135 #endif // NET_BASE_ORIGIN_BOUND_CERT_SERVICE_H_ | 135 #endif // NET_BASE_ORIGIN_BOUND_CERT_SERVICE_H_ |
OLD | NEW |