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

Side by Side Diff: talk/app/webrtc/dtlsidentitystore.h

Issue 1176383004: DtlsIdentityStore[Interface/Impl] updated, DtlsIdentityService to be removed (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merge with master Created 5 years, 4 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 | « talk/app/webrtc/dtlsidentityservice.cc ('k') | talk/app/webrtc/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 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 10 matching lines...) Expand all
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #ifndef TALK_APP_WEBRTC_DTLSIDENTITYSTORE_H_ 28 #ifndef TALK_APP_WEBRTC_DTLSIDENTITYSTORE_H_
29 #define TALK_APP_WEBRTC_DTLSIDENTITYSTORE_H_ 29 #define TALK_APP_WEBRTC_DTLSIDENTITYSTORE_H_
30 30
31 #include <queue> 31 #include <list>
32 #include <string> 32 #include <string>
33 33
34 #include "talk/app/webrtc/peerconnectioninterface.h"
35 #include "webrtc/base/messagehandler.h" 34 #include "webrtc/base/messagehandler.h"
36 #include "webrtc/base/messagequeue.h" 35 #include "webrtc/base/messagequeue.h"
36 #include "webrtc/base/refcount.h"
37 #include "webrtc/base/scoped_ptr.h" 37 #include "webrtc/base/scoped_ptr.h"
38 #include "webrtc/base/scoped_ref_ptr.h" 38 #include "webrtc/base/scoped_ref_ptr.h"
39 #include "webrtc/base/sslidentity.h"
40 #include "webrtc/base/thread.h"
39 41
40 namespace webrtc { 42 namespace webrtc {
41 class DTLSIdentityRequestObserver; 43
42 class SSLIdentity; 44 class SSLIdentity;
43 class Thread; 45 class Thread;
44 46
45 // This class implements an in-memory DTLS identity store, which generates the 47 // Used to receive callbacks of DTLS identity requests.
46 // DTLS identity on the worker thread. 48 class DtlsIdentityRequestObserver : public rtc::RefCountInterface {
49 public:
50 virtual void OnFailure(int error) = 0;
51 // TODO(hbos): Unify the OnSuccess method once Chrome code is updated.
52 virtual void OnSuccess(const std::string& der_cert,
53 const std::string& der_private_key) = 0;
54 // |identity| is a scoped_ptr because rtc::SSLIdentity is not copyable and the
55 // client has to get the ownership of the object to make use of it.
56 virtual void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) = 0;
57
58 protected:
59 virtual ~DtlsIdentityRequestObserver() {}
60 };
61
62 // This interface defines an in-memory DTLS identity store, which generates DTLS
63 // identities.
47 // APIs calls must be made on the signaling thread and the callbacks are also 64 // APIs calls must be made on the signaling thread and the callbacks are also
48 // called on the signaling thread. 65 // called on the signaling thread.
49 class DtlsIdentityStore : public rtc::MessageHandler { 66 class DtlsIdentityStoreInterface {
50 public: 67 public:
51 static const char kIdentityName[]; 68 virtual ~DtlsIdentityStoreInterface() { }
52
53 DtlsIdentityStore(rtc::Thread* signaling_thread,
54 rtc::Thread* worker_thread);
55 virtual ~DtlsIdentityStore();
56
57 // Initialize will start generating the free identity in the background.
58 void Initialize();
59 69
60 // The |observer| will be called when the requested identity is ready, or when 70 // The |observer| will be called when the requested identity is ready, or when
61 // identity generation fails. 71 // identity generation fails.
62 void RequestIdentity(webrtc::DTLSIdentityRequestObserver* observer); 72 virtual void RequestIdentity(
73 rtc::KeyType key_type,
74 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) = 0;
75 };
76
77 // The standard implementation of DtlsIdentityStoreInterface.
78 // Identity generation is performed on the worker thread.
79 class DtlsIdentityStoreImpl : public DtlsIdentityStoreInterface,
80 public rtc::MessageHandler {
81 public:
82 // This will start to preemptively generating an RSA identity in the
83 // background if the worker thread is not the same as the signaling thread.
84 DtlsIdentityStoreImpl(rtc::Thread* signaling_thread,
85 rtc::Thread* worker_thread);
86 ~DtlsIdentityStoreImpl() override;
87
88 // DtlsIdentityStoreInterface override;
89 void RequestIdentity(
90 rtc::KeyType key_type,
91 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) override;
63 92
64 // rtc::MessageHandler override; 93 // rtc::MessageHandler override;
65 void OnMessage(rtc::Message* msg) override; 94 void OnMessage(rtc::Message* msg) override;
66 95
67 // Returns true if there is a free identity, used for unit tests. 96 // Returns true if there is a free RSA identity, used for unit tests.
68 bool HasFreeIdentityForTesting() const; 97 bool HasFreeIdentityForTesting(rtc::KeyType key_type) const;
69 98
70 private: 99 private:
100 void GenerateIdentity(
101 rtc::KeyType key_type,
102 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer);
103 void OnIdentityGenerated(rtc::KeyType key_type,
104 rtc::scoped_ptr<rtc::SSLIdentity> identity);
105
106 class WorkerTask;
107 typedef rtc::ScopedMessageData<DtlsIdentityStoreImpl::WorkerTask>
108 WorkerTaskMessageData;
109
110 // A key type-identity pair.
111 struct IdentityResult {
112 IdentityResult(rtc::KeyType key_type,
113 rtc::scoped_ptr<rtc::SSLIdentity> identity)
114 : key_type_(key_type), identity_(identity.Pass()) {}
115
116 rtc::KeyType key_type_;
117 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
118 };
119
120 typedef rtc::ScopedMessageData<IdentityResult> IdentityResultMessageData;
121
71 sigslot::signal0<> SignalDestroyed; 122 sigslot::signal0<> SignalDestroyed;
72 class WorkerTask;
73 typedef rtc::ScopedMessageData<DtlsIdentityStore::WorkerTask>
74 IdentityTaskMessageData;
75
76 void GenerateIdentity();
77 void OnIdentityGenerated(rtc::scoped_ptr<rtc::SSLIdentity> identity);
78 void ReturnIdentity(rtc::scoped_ptr<rtc::SSLIdentity> identity);
79
80 void PostGenerateIdentityResult_w(rtc::scoped_ptr<rtc::SSLIdentity> identity);
81 123
82 rtc::Thread* const signaling_thread_; 124 rtc::Thread* const signaling_thread_;
125 // TODO(hbos): RSA generation is slow and would be VERY slow if we switch over
126 // to 2048, DtlsIdentityStore should use a new thread and not the "general
127 // purpose" worker thread.
83 rtc::Thread* const worker_thread_; 128 rtc::Thread* const worker_thread_;
84 129
85 // These members should be accessed on the signaling thread only. 130 struct RequestInfo {
86 int pending_jobs_; 131 RequestInfo()
87 rtc::scoped_ptr<rtc::SSLIdentity> free_identity_; 132 : request_observers_(), gen_in_progress_counts_(0), free_identity_() {}
88 typedef std::queue<rtc::scoped_refptr<webrtc::DTLSIdentityRequestObserver>> 133
89 ObserverList; 134 std::list<rtc::scoped_refptr<DtlsIdentityRequestObserver>>
magjed_webrtc 2015/07/29 09:31:57 Why not use a queue?
hbos 2015/08/04 11:38:49 At one point I thought I needed to iterate it so I
90 ObserverList pending_observers_; 135 request_observers_;
136 size_t gen_in_progress_counts_;
137 rtc::scoped_ptr<rtc::SSLIdentity> free_identity_;
138 };
139
140 // One RequestInfo per KeyType. Only touch on the |signaling_thread_|.
141 RequestInfo request_info_[rtc::KT_LAST];
91 }; 142 };
92 143
93 } // namespace webrtc 144 } // namespace webrtc
94 145
95 #endif // TALK_APP_WEBRTC_DTLSIDENTITYSTORE_H_ 146 #endif // TALK_APP_WEBRTC_DTLSIDENTITYSTORE_H_
OLDNEW
« no previous file with comments | « talk/app/webrtc/dtlsidentityservice.cc ('k') | talk/app/webrtc/dtlsidentitystore.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698