OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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_P2P_BASE_DTLSTRANSPORT_H_ | 11 #ifndef WEBRTC_P2P_BASE_DTLSTRANSPORT_H_ |
12 #define WEBRTC_P2P_BASE_DTLSTRANSPORT_H_ | 12 #define WEBRTC_P2P_BASE_DTLSTRANSPORT_H_ |
13 | 13 |
14 #include "webrtc/p2p/base/dtlstransportchannel.h" | 14 #include "webrtc/p2p/base/dtlstransportchannel.h" |
15 #include "webrtc/p2p/base/transport.h" | 15 #include "webrtc/p2p/base/transport.h" |
16 | 16 |
17 namespace rtc { | 17 namespace rtc { |
18 class SSLIdentity; | 18 class SSLIdentity; |
19 } | 19 } |
20 | 20 |
21 namespace cricket { | 21 namespace cricket { |
22 | 22 |
23 class PortAllocator; | 23 class PortAllocator; |
24 | 24 |
25 // Base should be a descendant of cricket::Transport | 25 // Base should be a descendant of cricket::Transport |
26 template<class Base> | 26 template<class Base> |
27 class DtlsTransport : public Base { | 27 class DtlsTransport : public Base { |
pthatcher1
2015/08/10 20:40:17
Can you comment that everything in this class shou
Taylor Brandstetter
2015/08/11 01:20:07
Done. Added comment to its base class (Transport)
| |
28 public: | 28 public: |
29 DtlsTransport(rtc::Thread* signaling_thread, | 29 DtlsTransport(const std::string& content_name, |
30 rtc::Thread* worker_thread, | |
31 const std::string& content_name, | |
32 PortAllocator* allocator, | 30 PortAllocator* allocator, |
33 rtc::SSLIdentity* identity) | 31 rtc::SSLIdentity* identity) |
34 : Base(signaling_thread, worker_thread, content_name, allocator), | 32 : Base(content_name, allocator), |
35 identity_(identity), | 33 identity_(identity), |
36 secure_role_(rtc::SSL_CLIENT), | 34 secure_role_(rtc::SSL_CLIENT), |
37 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10) { | 35 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10) { |
38 } | 36 } |
39 | 37 |
40 ~DtlsTransport() { | 38 ~DtlsTransport() { |
41 Base::DestroyAllChannels(); | 39 Base::DestroyAllChannels(); |
42 } | 40 } |
43 virtual void SetIdentity_w(rtc::SSLIdentity* identity) { | 41 |
42 virtual void SetIdentity(rtc::SSLIdentity* identity) { | |
44 identity_ = identity; | 43 identity_ = identity; |
45 } | 44 } |
46 virtual bool GetIdentity_w(rtc::SSLIdentity** identity) { | 45 virtual bool GetIdentity(rtc::SSLIdentity** identity) { |
47 if (!identity_) | 46 if (!identity_) |
48 return false; | 47 return false; |
49 | 48 |
50 *identity = identity_->GetReference(); | 49 *identity = identity_->GetReference(); |
51 return true; | 50 return true; |
52 } | 51 } |
53 | 52 |
54 virtual bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version) { | 53 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) { |
55 ssl_max_version_ = version; | 54 ssl_max_version_ = version; |
56 return true; | 55 return true; |
57 } | 56 } |
58 | 57 |
59 virtual bool ApplyLocalTransportDescription_w(TransportChannelImpl* channel, | 58 virtual bool ApplyLocalTransportDescription(TransportChannelImpl* channel, |
60 std::string* error_desc) { | 59 std::string* error_desc) { |
61 rtc::SSLFingerprint* local_fp = | 60 rtc::SSLFingerprint* local_fp = |
62 Base::local_description()->identity_fingerprint.get(); | 61 Base::local_description()->identity_fingerprint.get(); |
63 | 62 |
64 if (local_fp) { | 63 if (local_fp) { |
65 // Sanity check local fingerprint. | 64 // Sanity check local fingerprint. |
66 if (identity_) { | 65 if (identity_) { |
67 rtc::scoped_ptr<rtc::SSLFingerprint> local_fp_tmp( | 66 rtc::scoped_ptr<rtc::SSLFingerprint> local_fp_tmp( |
68 rtc::SSLFingerprint::Create(local_fp->algorithm, | 67 rtc::SSLFingerprint::Create(local_fp->algorithm, |
69 identity_)); | 68 identity_)); |
(...skipping 13 matching lines...) Expand all Loading... | |
83 } else { | 82 } else { |
84 identity_ = NULL; | 83 identity_ = NULL; |
85 } | 84 } |
86 | 85 |
87 if (!channel->SetLocalIdentity(identity_)) { | 86 if (!channel->SetLocalIdentity(identity_)) { |
88 return BadTransportDescription("Failed to set local identity.", | 87 return BadTransportDescription("Failed to set local identity.", |
89 error_desc); | 88 error_desc); |
90 } | 89 } |
91 | 90 |
92 // Apply the description in the base class. | 91 // Apply the description in the base class. |
93 return Base::ApplyLocalTransportDescription_w(channel, error_desc); | 92 return Base::ApplyLocalTransportDescription(channel, error_desc); |
94 } | 93 } |
95 | 94 |
96 virtual bool NegotiateTransportDescription_w(ContentAction local_role, | 95 virtual bool NegotiateTransportDescription(ContentAction local_role, |
97 std::string* error_desc) { | 96 std::string* error_desc) { |
98 if (!Base::local_description() || !Base::remote_description()) { | 97 if (!Base::local_description() || !Base::remote_description()) { |
99 const std::string msg = "Local and Remote description must be set before " | 98 const std::string msg = "Local and Remote description must be set before " |
100 "transport descriptions are negotiated"; | 99 "transport descriptions are negotiated"; |
101 return BadTransportDescription(msg, error_desc); | 100 return BadTransportDescription(msg, error_desc); |
102 } | 101 } |
103 | 102 |
104 rtc::SSLFingerprint* local_fp = | 103 rtc::SSLFingerprint* local_fp = |
105 Base::local_description()->identity_fingerprint.get(); | 104 Base::local_description()->identity_fingerprint.get(); |
106 rtc::SSLFingerprint* remote_fp = | 105 rtc::SSLFingerprint* remote_fp = |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 return BadTransportDescription( | 183 return BadTransportDescription( |
185 "Local fingerprint supplied when caller didn't offer DTLS.", | 184 "Local fingerprint supplied when caller didn't offer DTLS.", |
186 error_desc); | 185 error_desc); |
187 } else { | 186 } else { |
188 // We are not doing DTLS | 187 // We are not doing DTLS |
189 remote_fingerprint_.reset(new rtc::SSLFingerprint( | 188 remote_fingerprint_.reset(new rtc::SSLFingerprint( |
190 "", NULL, 0)); | 189 "", NULL, 0)); |
191 } | 190 } |
192 | 191 |
193 // Now run the negotiation for the base class. | 192 // Now run the negotiation for the base class. |
194 return Base::NegotiateTransportDescription_w(local_role, error_desc); | 193 return Base::NegotiateTransportDescription(local_role, error_desc); |
195 } | 194 } |
196 | 195 |
197 virtual DtlsTransportChannelWrapper* CreateTransportChannel(int component) { | 196 virtual DtlsTransportChannelWrapper* CreateTransportChannel(int component) { |
198 DtlsTransportChannelWrapper* channel = new DtlsTransportChannelWrapper( | 197 DtlsTransportChannelWrapper* channel = new DtlsTransportChannelWrapper( |
199 this, Base::CreateTransportChannel(component)); | 198 this, Base::CreateTransportChannel(component)); |
200 channel->SetSslMaxProtocolVersion(ssl_max_version_); | 199 channel->SetSslMaxProtocolVersion(ssl_max_version_); |
201 return channel; | 200 return channel; |
202 } | 201 } |
203 | 202 |
204 virtual void DestroyTransportChannel(TransportChannelImpl* channel) { | 203 virtual void DestroyTransportChannel(TransportChannelImpl* channel) { |
205 // Kind of ugly, but this lets us do the exact inverse of the create. | 204 // Kind of ugly, but this lets us do the exact inverse of the create. |
206 DtlsTransportChannelWrapper* dtls_channel = | 205 DtlsTransportChannelWrapper* dtls_channel = |
207 static_cast<DtlsTransportChannelWrapper*>(channel); | 206 static_cast<DtlsTransportChannelWrapper*>(channel); |
208 TransportChannelImpl* base_channel = dtls_channel->channel(); | 207 TransportChannelImpl* base_channel = dtls_channel->channel(); |
209 delete dtls_channel; | 208 delete dtls_channel; |
210 Base::DestroyTransportChannel(base_channel); | 209 Base::DestroyTransportChannel(base_channel); |
211 } | 210 } |
212 | 211 |
213 virtual bool GetSslRole_w(rtc::SSLRole* ssl_role) const { | 212 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { |
214 ASSERT(ssl_role != NULL); | 213 ASSERT(ssl_role != NULL); |
215 *ssl_role = secure_role_; | 214 *ssl_role = secure_role_; |
216 return true; | 215 return true; |
217 } | 216 } |
218 | 217 |
219 private: | 218 bool ApplyNegotiatedTransportDescription( |
220 virtual bool ApplyNegotiatedTransportDescription_w( | |
221 TransportChannelImpl* channel, | 219 TransportChannelImpl* channel, |
222 std::string* error_desc) { | 220 std::string* error_desc) override { |
223 // Set ssl role. Role must be set before fingerprint is applied, which | 221 // Set ssl role. Role must be set before fingerprint is applied, which |
224 // initiates DTLS setup. | 222 // initiates DTLS setup. |
225 if (!channel->SetSslRole(secure_role_)) { | 223 if (!channel->SetSslRole(secure_role_)) { |
226 return BadTransportDescription("Failed to set ssl role for the channel.", | 224 return BadTransportDescription("Failed to set ssl role for the channel.", |
227 error_desc); | 225 error_desc); |
228 } | 226 } |
229 // Apply remote fingerprint. | 227 // Apply remote fingerprint. |
230 if (!channel->SetRemoteFingerprint( | 228 if (!channel->SetRemoteFingerprint( |
231 remote_fingerprint_->algorithm, | 229 remote_fingerprint_->algorithm, |
232 reinterpret_cast<const uint8*>(remote_fingerprint_->digest.data()), | 230 reinterpret_cast<const uint8*>(remote_fingerprint_->digest.data()), |
233 remote_fingerprint_->digest.size())) { | 231 remote_fingerprint_->digest.size())) { |
234 return BadTransportDescription("Failed to apply remote fingerprint.", | 232 return BadTransportDescription("Failed to apply remote fingerprint.", |
235 error_desc); | 233 error_desc); |
236 } | 234 } |
237 return Base::ApplyNegotiatedTransportDescription_w(channel, error_desc); | 235 return Base::ApplyNegotiatedTransportDescription(channel, error_desc); |
238 } | 236 } |
239 | 237 |
238 private: | |
240 rtc::SSLIdentity* identity_; | 239 rtc::SSLIdentity* identity_; |
241 rtc::SSLRole secure_role_; | 240 rtc::SSLRole secure_role_; |
242 rtc::SSLProtocolVersion ssl_max_version_; | 241 rtc::SSLProtocolVersion ssl_max_version_; |
243 rtc::scoped_ptr<rtc::SSLFingerprint> remote_fingerprint_; | 242 rtc::scoped_ptr<rtc::SSLFingerprint> remote_fingerprint_; |
244 }; | 243 }; |
245 | 244 |
246 } // namespace cricket | 245 } // namespace cricket |
247 | 246 |
248 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORT_H_ | 247 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORT_H_ |
OLD | NEW |