Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: webrtc/api/dtlsidentitystore.h

Issue 2028033002: Remove DtlsIdentityStoreImpl and RTCCertificateGeneratorStoreWrapper. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added TODO and rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/api_tests.gyp ('k') | webrtc/api/dtlsidentitystore.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_API_DTLSIDENTITYSTORE_H_ 11 #ifndef WEBRTC_API_DTLSIDENTITYSTORE_H_
12 #define WEBRTC_API_DTLSIDENTITYSTORE_H_ 12 #define WEBRTC_API_DTLSIDENTITYSTORE_H_
13 13
14 #include <memory> 14 #include <memory>
15 #include <queue> 15 #include <queue>
16 #include <string> 16 #include <string>
17 #include <utility> 17 #include <utility>
18 18
19 #include "webrtc/base/messagehandler.h" 19 #include "webrtc/base/messagehandler.h"
20 #include "webrtc/base/messagequeue.h" 20 #include "webrtc/base/messagequeue.h"
21 #include "webrtc/base/optional.h" 21 #include "webrtc/base/optional.h"
22 #include "webrtc/base/refcount.h" 22 #include "webrtc/base/refcount.h"
23 #include "webrtc/base/rtccertificategenerator.h" 23 #include "webrtc/base/rtccertificategenerator.h"
24 #include "webrtc/base/scoped_ref_ptr.h" 24 #include "webrtc/base/scoped_ref_ptr.h"
25 #include "webrtc/base/sslidentity.h" 25 #include "webrtc/base/sslidentity.h"
26 #include "webrtc/base/thread.h" 26 #include "webrtc/base/thread.h"
27 27
28 namespace webrtc { 28 namespace webrtc {
29 29
30 // Passed to SSLIdentity::Generate. 30 // TODO(hbos): Remove this constant (and dtlsidentitystore.cc) after
31 // RTCPeerConnectionInterface.mm stops using it.
32 // bugs.webrtc.org/5707, bugs.webrtc.org/5708
31 extern const char kIdentityName[]; 33 extern const char kIdentityName[];
32 34
33 class SSLIdentity; 35 class SSLIdentity;
34 class Thread; 36 class Thread;
35 37
36 // Used to receive callbacks of DTLS identity requests. 38 // Used to receive callbacks of DTLS identity requests.
37 class DtlsIdentityRequestObserver : public rtc::RefCountInterface { 39 class DtlsIdentityRequestObserver : public rtc::RefCountInterface {
38 public: 40 public:
39 virtual void OnFailure(int error) = 0; 41 virtual void OnFailure(int error) = 0;
40 // TODO(hbos): Unify the OnSuccess method once Chrome code is updated. 42 // TODO(hbos): Unify the OnSuccess method once Chrome code is updated.
(...skipping 16 matching lines...) Expand all
57 virtual ~DtlsIdentityStoreInterface() { } 59 virtual ~DtlsIdentityStoreInterface() { }
58 60
59 // The |observer| will be called when the requested identity is ready, or when 61 // The |observer| will be called when the requested identity is ready, or when
60 // identity generation fails. 62 // identity generation fails.
61 virtual void RequestIdentity( 63 virtual void RequestIdentity(
62 const rtc::KeyParams& key_params, 64 const rtc::KeyParams& key_params,
63 const rtc::Optional<uint64_t>& expires_ms, 65 const rtc::Optional<uint64_t>& expires_ms,
64 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) = 0; 66 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) = 0;
65 }; 67 };
66 68
67 // The WebRTC default implementation of DtlsIdentityStoreInterface.
68 // Identity generation is performed on the worker thread.
69 class DtlsIdentityStoreImpl : public DtlsIdentityStoreInterface,
70 public rtc::MessageHandler {
71 public:
72 // This will start to preemptively generating an RSA identity in the
73 // background if the worker thread is not the same as the signaling thread.
74 DtlsIdentityStoreImpl(rtc::Thread* signaling_thread,
75 rtc::Thread* worker_thread);
76 ~DtlsIdentityStoreImpl() override;
77
78 // DtlsIdentityStoreInterface override;
79 void RequestIdentity(
80 const rtc::KeyParams& key_params,
81 const rtc::Optional<uint64_t>& expires_ms,
82 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) override;
83
84 // rtc::MessageHandler override;
85 void OnMessage(rtc::Message* msg) override;
86
87 // Returns true if there is a free RSA identity, used for unit tests.
88 bool HasFreeIdentityForTesting(rtc::KeyType key_type) const;
89
90 private:
91 void GenerateIdentity(
92 rtc::KeyType key_type,
93 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer);
94 void OnIdentityGenerated(rtc::KeyType key_type,
95 std::unique_ptr<rtc::SSLIdentity> identity);
96
97 class WorkerTask;
98 typedef rtc::ScopedMessageData<DtlsIdentityStoreImpl::WorkerTask>
99 WorkerTaskMessageData;
100
101 // A key type-identity pair.
102 struct IdentityResult {
103 IdentityResult(rtc::KeyType key_type,
104 std::unique_ptr<rtc::SSLIdentity> identity)
105 : key_type_(key_type), identity_(std::move(identity)) {}
106
107 rtc::KeyType key_type_;
108 std::unique_ptr<rtc::SSLIdentity> identity_;
109 };
110
111 typedef rtc::ScopedMessageData<IdentityResult> IdentityResultMessageData;
112
113 sigslot::signal0<> SignalDestroyed;
114
115 rtc::Thread* const signaling_thread_;
116 // TODO(hbos): RSA generation is slow and would be VERY slow if we switch over
117 // to 2048, DtlsIdentityStore should use a new thread and not the "general
118 // purpose" worker thread.
119 rtc::Thread* const worker_thread_;
120
121 struct RequestInfo {
122 RequestInfo()
123 : request_observers_(), gen_in_progress_counts_(0), free_identity_() {}
124
125 std::queue<rtc::scoped_refptr<DtlsIdentityRequestObserver>>
126 request_observers_;
127 size_t gen_in_progress_counts_;
128 std::unique_ptr<rtc::SSLIdentity> free_identity_;
129 };
130
131 // One RequestInfo per KeyType. Only touch on the |signaling_thread_|.
132 RequestInfo request_info_[rtc::KT_LAST];
133 };
134
135 // Implements the |RTCCertificateGeneratorInterface| using the old |SSLIdentity|
136 // generator API, |DtlsIdentityStoreInterface|. This will be used while
137 // transitioning from store to generator, see bugs.webrtc.org/5707,
138 // bugs.webrtc.org/5708. Once those bugs have been fixed, this will be removed.
139 class RTCCertificateGeneratorStoreWrapper
140 : public rtc::RTCCertificateGeneratorInterface {
141 public:
142 RTCCertificateGeneratorStoreWrapper(
143 std::unique_ptr<DtlsIdentityStoreInterface> store);
144
145 // |RTCCertificateGeneratorInterface| overrides.
146 void GenerateCertificateAsync(
147 const rtc::KeyParams& key_params,
148 const rtc::Optional<uint64_t>& expires_ms,
149 const rtc::scoped_refptr<rtc::RTCCertificateGeneratorCallback>& callback)
150 override;
151
152 private:
153 const std::unique_ptr<DtlsIdentityStoreInterface> store_;
154 };
155
156 } // namespace webrtc 69 } // namespace webrtc
157 70
158 #endif // WEBRTC_API_DTLSIDENTITYSTORE_H_ 71 #endif // WEBRTC_API_DTLSIDENTITYSTORE_H_
OLDNEW
« no previous file with comments | « webrtc/api/api_tests.gyp ('k') | webrtc/api/dtlsidentitystore.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698