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_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 | 12 |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
15 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
16 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
18 #include "net/base/origin_bound_cert_type.h" | |
17 | 19 |
18 namespace net { | 20 namespace net { |
19 | 21 |
20 class OriginBoundCertServiceJob; | 22 class OriginBoundCertServiceJob; |
21 class OriginBoundCertServiceWorker; | 23 class OriginBoundCertServiceWorker; |
22 class OriginBoundCertStore; | 24 class OriginBoundCertStore; |
23 | 25 |
24 // A class for creating and fetching origin bound certs. | 26 // A class for creating and fetching origin bound certs. |
25 // Inherits from NonThreadSafe in order to use the function | 27 // Inherits from NonThreadSafe in order to use the function |
26 // |CalledOnValidThread|. | 28 // |CalledOnValidThread|. |
27 class NET_EXPORT OriginBoundCertService | 29 class NET_EXPORT OriginBoundCertService |
28 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 30 : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
29 public: | 31 public: |
30 // Opaque type used to cancel a request. | 32 // Opaque type used to cancel a request. |
31 typedef void* RequestHandle; | 33 typedef void* RequestHandle; |
32 | 34 |
35 // Password used on EncryptedPrivateKeyInfo data stored in EC private_key | |
36 // values. (This is not used to provide any security, but to workaround an | |
37 // NSS issue.) | |
wtc
2011/11/30 23:23:40
Please include the NSS bug number or provide enoug
mattm
2011/12/02 01:55:59
Done.
| |
38 static const char kEPKIPassword[]; | |
39 | |
33 // This object owns origin_bound_cert_store. | 40 // This object owns origin_bound_cert_store. |
34 explicit OriginBoundCertService( | 41 explicit OriginBoundCertService( |
35 OriginBoundCertStore* origin_bound_cert_store); | 42 OriginBoundCertStore* origin_bound_cert_store); |
36 | 43 |
37 ~OriginBoundCertService(); | 44 ~OriginBoundCertService(); |
38 | 45 |
39 // TODO(rkn): Specify certificate type (RSA or DSA). | 46 // Fetches the origin bound cert for the specified origin of the specified |
47 // type if one exists and creates one otherwise. Returns OK if successful or | |
48 // an error code upon failure. | |
40 // | 49 // |
41 // Fetches the origin bound cert for the specified origin if one exists | 50 // |requested_types| is a list the types of certificates the site will |
42 // and creates one otherwise. Returns OK if successful or an error code upon | 51 // accept, ordered from most preferred to least preferred. |
43 // failure. | |
44 // | 52 // |
45 // On successful completion, |private_key| stores a DER-encoded | 53 // On successful completion, |private_key| stores a DER-encoded |
46 // PrivateKeyInfo struct, and |cert| stores a DER-encoded certificate. | 54 // PrivateKeyInfo struct, and |cert| stores a DER-encoded certificate. |
wtc
2011/11/30 23:23:40
Also document the new |type| output parameter.
mattm
2011/12/02 01:55:59
Done.
| |
47 // | 55 // |
48 // |callback| must not be null. ERR_IO_PENDING is returned if the operation | 56 // |callback| must not be null. ERR_IO_PENDING is returned if the operation |
49 // could not be completed immediately, in which case the result code will | 57 // could not be completed immediately, in which case the result code will |
50 // be passed to the callback when available. | 58 // be passed to the callback when available. |
51 // | 59 // |
52 // If |out_req| is non-NULL, then |*out_req| will be filled with a handle to | 60 // If |out_req| is non-NULL, then |*out_req| will be filled with a handle to |
53 // the async request. This handle is not valid after the request has | 61 // the async request. This handle is not valid after the request has |
54 // completed. | 62 // completed. |
55 int GetOriginBoundCert(const std::string& origin, | 63 int GetOriginBoundCert( |
56 std::string* private_key, | 64 const std::string& origin, |
57 std::string* cert, | 65 const std::vector<OriginBoundCertType>& requested_types, |
58 const CompletionCallback& callback, | 66 OriginBoundCertType* type, |
59 RequestHandle* out_req); | 67 std::string* private_key, |
68 std::string* cert, | |
69 const CompletionCallback& callback, | |
70 RequestHandle* out_req); | |
60 | 71 |
61 // Cancels the specified request. |req| is the handle returned by | 72 // Cancels the specified request. |req| is the handle returned by |
62 // GetOriginBoundCert(). After a request is canceled, its completion | 73 // GetOriginBoundCert(). After a request is canceled, its completion |
63 // callback will not be called. | 74 // callback will not be called. |
64 void CancelRequest(RequestHandle req); | 75 void CancelRequest(RequestHandle req); |
65 | 76 |
66 // Public only for unit testing. | 77 // Public only for unit testing. |
67 int cert_count(); | 78 int cert_count(); |
68 uint64 requests() const { return requests_; } | 79 uint64 requests() const { return requests_; } |
69 uint64 cert_store_hits() const { return cert_store_hits_; } | 80 uint64 cert_store_hits() const { return cert_store_hits_; } |
70 uint64 inflight_joins() const { return inflight_joins_; } | 81 uint64 inflight_joins() const { return inflight_joins_; } |
71 | 82 |
72 private: | 83 private: |
73 friend class OriginBoundCertServiceWorker; // Calls HandleResult. | 84 friend class OriginBoundCertServiceWorker; // Calls HandleResult. |
74 | 85 |
75 // On success, |private_key| stores a DER-encoded PrivateKeyInfo | 86 // On success, |private_key| stores a DER-encoded PrivateKeyInfo |
76 // struct, and |cert| stores a DER-encoded certificate. Returns | 87 // struct, and |cert| stores a DER-encoded certificate. Returns |
77 // OK if successful and an error code otherwise. | 88 // OK if successful and an error code otherwise. |
78 // |serial_number| is passed in because it is created with the function | 89 // |serial_number| is passed in because it is created with the function |
79 // base::RandInt, which opens the file /dev/urandom. /dev/urandom is opened | 90 // base::RandInt, which opens the file /dev/urandom. /dev/urandom is opened |
80 // with a LazyInstance, which is not allowed on a worker thread. | 91 // with a LazyInstance, which is not allowed on a worker thread. |
81 static int GenerateCert(const std::string& origin, | 92 static int GenerateCert(const std::string& origin, |
93 OriginBoundCertType type, | |
82 uint32 serial_number, | 94 uint32 serial_number, |
83 std::string* private_key, | 95 std::string* private_key, |
84 std::string* cert); | 96 std::string* cert); |
85 | 97 |
86 void HandleResult(const std::string& origin, | 98 void HandleResult(const std::string& origin, |
87 int error, | 99 int error, |
100 OriginBoundCertType type, | |
88 const std::string& private_key, | 101 const std::string& private_key, |
89 const std::string& cert); | 102 const std::string& cert); |
90 | 103 |
91 scoped_ptr<OriginBoundCertStore> origin_bound_cert_store_; | 104 scoped_ptr<OriginBoundCertStore> origin_bound_cert_store_; |
92 | 105 |
93 // inflight_ maps from an origin to an active generation which is taking | 106 // inflight_ maps from an origin to an active generation which is taking |
94 // place. | 107 // place. |
95 std::map<std::string, OriginBoundCertServiceJob*> inflight_; | 108 std::map<std::string, OriginBoundCertServiceJob*> inflight_; |
96 | 109 |
97 uint64 requests_; | 110 uint64 requests_; |
98 uint64 cert_store_hits_; | 111 uint64 cert_store_hits_; |
99 uint64 inflight_joins_; | 112 uint64 inflight_joins_; |
100 | 113 |
101 DISALLOW_COPY_AND_ASSIGN(OriginBoundCertService); | 114 DISALLOW_COPY_AND_ASSIGN(OriginBoundCertService); |
102 }; | 115 }; |
103 | 116 |
104 } // namespace net | 117 } // namespace net |
105 | 118 |
106 #endif // NET_BASE_ORIGIN_BOUND_CERT_SERVICE_H_ | 119 #endif // NET_BASE_ORIGIN_BOUND_CERT_SERVICE_H_ |
OLD | NEW |