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

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: DtlsIdentityStoreImpl made simpler and better and not using any locks. Created 5 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 | « 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(jiayl): 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 OnSuccessWithIdentityObj(
57 rtc::scoped_ptr<rtc::SSLIdentity> identity) = 0;
58
59 protected:
60 virtual ~DtlsIdentityRequestObserver() {}
61 };
62
63 // This interface defines an in-memory DTLS identity store, which generates DTLS
64 // identities.
47 // APIs calls must be made on the signaling thread and the callbacks are also 65 // APIs calls must be made on the signaling thread and the callbacks are also
48 // called on the signaling thread. 66 // called on the signaling thread.
49 class DtlsIdentityStore : public rtc::MessageHandler { 67 class DtlsIdentityStoreInterface {
50 public: 68 public:
51 static const char kIdentityName[]; 69 virtual ~DtlsIdentityStoreInterface() { }
52 70
53 DtlsIdentityStore(rtc::Thread* signaling_thread, 71 // Initializes the store.
54 rtc::Thread* worker_thread); 72 virtual void Initialize() = 0;
55 virtual ~DtlsIdentityStore();
56
57 // Initialize will start generating the free identity in the background.
58 void Initialize();
59 73
60 // The |observer| will be called when the requested identity is ready, or when 74 // The |observer| will be called when the requested identity is ready, or when
61 // identity generation fails. 75 // identity generation fails.
62 void RequestIdentity(webrtc::DTLSIdentityRequestObserver* observer); 76 virtual void RequestIdentity(
77 rtc::KeyType key_type, webrtc::DtlsIdentityRequestObserver* observer) = 0;
78 };
79
80 // The standard implementation of DtlsIdentityStoreInterface.
81 // Identity generation is performed on the worker thread.
82 class DtlsIdentityStoreImpl : public DtlsIdentityStoreInterface,
83 public rtc::MessageHandler {
84 public:
85 // Passed to SSLIdentity::Generate, "WebRTC". Used for the certificates'
86 // subject and issuer name.
87 static const char* common_name_;
88
89 DtlsIdentityStoreImpl(rtc::Thread* signaling_thread,
90 rtc::Thread* worker_thread);
91 ~DtlsIdentityStoreImpl() override;
92
93 // webrtc::DtlsIdentityStoreInterface override;
94 // Initialize will start to preemptively generating an RSA identity in the
95 // background, if the worker thread is not the same as the signaling thread.
96 void Initialize() override;
97 // webrtc::DtlsIdentityStoreInterface override;
98 void RequestIdentity(rtc::KeyType key_type,
99 webrtc::DtlsIdentityRequestObserver* observer) override;
63 100
64 // rtc::MessageHandler override; 101 // rtc::MessageHandler override;
65 void OnMessage(rtc::Message* msg) override; 102 void OnMessage(rtc::Message* msg) override;
66 103
67 // Returns true if there is a free identity, used for unit tests. 104 // Returns true if there is a free RSA identity, used for unit tests.
68 bool HasFreeIdentityForTesting() const; 105 bool HasFreeIdentityForTesting(rtc::KeyType key_type = rtc::KT_RSA) const;
69 106
70 private: 107 private:
108 void GenerateIdentity(rtc::KeyType key_type,
109 webrtc::DtlsIdentityRequestObserver* observer);
110 void OnIdentityGenerated(rtc::KeyType key_type,
111 rtc::scoped_ptr<rtc::SSLIdentity> identity);
112
113 class WorkerTask;
114 typedef rtc::ScopedMessageData<DtlsIdentityStoreImpl::WorkerTask>
115 WorkerTaskMessageData;
116
117 // A key type-identity pair.
118 struct IdentityResult {
119 IdentityResult(rtc::KeyType key_type, rtc::SSLIdentity* identity)
120 : key_type_(key_type), identity_(identity) {}
121
122 rtc::KeyType key_type_;
123 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
124 };
125 typedef rtc::ScopedMessageData<IdentityResult> IdentityResultMessageData;
126
71 sigslot::signal0<> SignalDestroyed; 127 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 128
82 rtc::Thread* const signaling_thread_; 129 rtc::Thread* const signaling_thread_;
130 // TODO(hbos): RSA generation is slow and would be VERY slow if we switch over
131 // to 2048, DtlsIdentityStore should use a new thread and not the "general
132 // purpose" worker thread.
83 rtc::Thread* const worker_thread_; 133 rtc::Thread* const worker_thread_;
84 134
85 // These members should be accessed on the signaling thread only. 135 typedef rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver> RefObserver;
86 int pending_jobs_; 136 std::list<RefObserver> request_observers_[rtc::KT_LAST];
87 rtc::scoped_ptr<rtc::SSLIdentity> free_identity_; 137 int gen_in_progress_counts_[rtc::KT_LAST];
88 typedef std::queue<rtc::scoped_refptr<webrtc::DTLSIdentityRequestObserver>> 138 rtc::scoped_ptr<rtc::SSLIdentity> free_identities_[rtc::KT_LAST];
hbos 2015/06/18 08:43:13 (This makes it easy to support preemptive generati
89 ObserverList;
90 ObserverList pending_observers_;
91 }; 139 };
92 140
93 } // namespace webrtc 141 } // namespace webrtc
94 142
95 #endif // TALK_APP_WEBRTC_DTLSIDENTITYSTORE_H_ 143 #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