OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 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_DTLSTRANSPORTCHANNEL_H_ | 11 #ifndef WEBRTC_P2P_BASE_DTLSTRANSPORT_H_ |
12 #define WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ | 12 #define WEBRTC_P2P_BASE_DTLSTRANSPORT_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/p2p/base/dtlstransportinternal.h" | 18 #include "webrtc/p2p/base/dtlstransportinternal.h" |
19 #include "webrtc/p2p/base/icetransportinternal.h" | 19 #include "webrtc/p2p/base/icetransportinternal.h" |
20 #include "webrtc/rtc_base/buffer.h" | 20 #include "webrtc/rtc_base/buffer.h" |
21 #include "webrtc/rtc_base/bufferqueue.h" | 21 #include "webrtc/rtc_base/bufferqueue.h" |
22 #include "webrtc/rtc_base/constructormagic.h" | 22 #include "webrtc/rtc_base/constructormagic.h" |
(...skipping 28 matching lines...) Expand all Loading... |
51 int* error) override; | 51 int* error) override; |
52 | 52 |
53 private: | 53 private: |
54 IceTransportInternal* ice_transport_; // owned by DtlsTransport | 54 IceTransportInternal* ice_transport_; // owned by DtlsTransport |
55 rtc::StreamState state_; | 55 rtc::StreamState state_; |
56 rtc::BufferQueue packets_; | 56 rtc::BufferQueue packets_; |
57 | 57 |
58 RTC_DISALLOW_COPY_AND_ASSIGN(StreamInterfaceChannel); | 58 RTC_DISALLOW_COPY_AND_ASSIGN(StreamInterfaceChannel); |
59 }; | 59 }; |
60 | 60 |
61 | |
62 // This class provides a DTLS SSLStreamAdapter inside a TransportChannel-style | 61 // This class provides a DTLS SSLStreamAdapter inside a TransportChannel-style |
63 // packet-based interface, wrapping an existing TransportChannel instance | 62 // packet-based interface, wrapping an existing TransportChannel instance |
64 // (e.g a P2PTransportChannel) | 63 // (e.g a P2PTransportChannel) |
65 // Here's the way this works: | 64 // Here's the way this works: |
66 // | 65 // |
67 // DtlsTransport { | 66 // DtlsTransport { |
68 // SSLStreamAdapter* dtls_ { | 67 // SSLStreamAdapter* dtls_ { |
69 // StreamInterfaceChannel downward_ { | 68 // StreamInterfaceChannel downward_ { |
70 // IceTransportInternal* ice_transport_; | 69 // IceTransportInternal* ice_transport_; |
71 // } | 70 // } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 bool IsDtlsActive() const override { return dtls_active_; } | 108 bool IsDtlsActive() const override { return dtls_active_; } |
110 | 109 |
111 bool SetLocalCertificate( | 110 bool SetLocalCertificate( |
112 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; | 111 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; |
113 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override; | 112 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override; |
114 | 113 |
115 bool SetRemoteFingerprint(const std::string& digest_alg, | 114 bool SetRemoteFingerprint(const std::string& digest_alg, |
116 const uint8_t* digest, | 115 const uint8_t* digest, |
117 size_t digest_len) override; | 116 size_t digest_len) override; |
118 | 117 |
119 | |
120 // Called to send a packet (via DTLS, if turned on). | 118 // Called to send a packet (via DTLS, if turned on). |
121 int SendPacket(const char* data, | 119 int SendPacket(const char* data, |
122 size_t size, | 120 size_t size, |
123 const rtc::PacketOptions& options, | 121 const rtc::PacketOptions& options, |
124 int flags) override; | 122 int flags) override; |
125 | 123 |
126 bool GetOption(rtc::Socket::Option opt, int* value) override { | 124 bool GetOption(rtc::Socket::Option opt, int* value) override { |
127 return ice_transport_->GetOption(opt, value); | 125 return ice_transport_->GetOption(opt, value); |
128 } | 126 } |
129 | 127 |
(...skipping 15 matching lines...) Expand all Loading... |
145 // Once DTLS has established (i.e., this ice_transport is writable), this | 143 // Once DTLS has established (i.e., this ice_transport is writable), this |
146 // method extracts the keys negotiated during the DTLS handshake, for use in | 144 // method extracts the keys negotiated during the DTLS handshake, for use in |
147 // external encryption. DTLS-SRTP uses this to extract the needed SRTP keys. | 145 // external encryption. DTLS-SRTP uses this to extract the needed SRTP keys. |
148 // See the SSLStreamAdapter documentation for info on the specific parameters. | 146 // See the SSLStreamAdapter documentation for info on the specific parameters. |
149 bool ExportKeyingMaterial(const std::string& label, | 147 bool ExportKeyingMaterial(const std::string& label, |
150 const uint8_t* context, | 148 const uint8_t* context, |
151 size_t context_len, | 149 size_t context_len, |
152 bool use_context, | 150 bool use_context, |
153 uint8_t* result, | 151 uint8_t* result, |
154 size_t result_len) override { | 152 size_t result_len) override { |
155 return (dtls_.get()) ? dtls_->ExportKeyingMaterial(label, context, | 153 return (dtls_.get()) |
156 context_len, | 154 ? dtls_->ExportKeyingMaterial(label, context, context_len, |
157 use_context, | 155 use_context, result, result_len) |
158 result, result_len) | 156 : false; |
159 : false; | |
160 } | 157 } |
161 | 158 |
162 IceTransportInternal* ice_transport() override { return ice_transport_; } | 159 IceTransportInternal* ice_transport() override { return ice_transport_; } |
163 | 160 |
164 // For informational purposes. Tells if the DTLS handshake has finished. | 161 // For informational purposes. Tells if the DTLS handshake has finished. |
165 // This may be true even if writable() is false, if the remote fingerprint | 162 // This may be true even if writable() is false, if the remote fingerprint |
166 // has not yet been verified. | 163 // has not yet been verified. |
167 bool IsDtlsConnected(); | 164 bool IsDtlsConnected(); |
168 | 165 |
169 bool receiving() const override { return receiving_; } | 166 bool receiving() const override { return receiving_; } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 207 |
211 std::string transport_name_; | 208 std::string transport_name_; |
212 int component_; | 209 int component_; |
213 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; | 210 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; |
214 rtc::Thread* network_thread_; // Everything should occur on this thread. | 211 rtc::Thread* network_thread_; // Everything should occur on this thread. |
215 // Underlying ice_transport, not owned by this class. | 212 // Underlying ice_transport, not owned by this class. |
216 IceTransportInternal* const ice_transport_; | 213 IceTransportInternal* const ice_transport_; |
217 std::unique_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream | 214 std::unique_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream |
218 StreamInterfaceChannel* | 215 StreamInterfaceChannel* |
219 downward_; // Wrapper for ice_transport_, owned by dtls_. | 216 downward_; // Wrapper for ice_transport_, owned by dtls_. |
220 std::vector<int> srtp_ciphers_; // SRTP ciphers to use with DTLS. | 217 std::vector<int> srtp_ciphers_; // SRTP ciphers to use with DTLS. |
221 bool dtls_active_ = false; | 218 bool dtls_active_ = false; |
222 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; | 219 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; |
223 rtc::SSLRole ssl_role_; | 220 rtc::SSLRole ssl_role_; |
224 rtc::SSLProtocolVersion ssl_max_version_; | 221 rtc::SSLProtocolVersion ssl_max_version_; |
225 rtc::CryptoOptions crypto_options_; | 222 rtc::CryptoOptions crypto_options_; |
226 rtc::Buffer remote_fingerprint_value_; | 223 rtc::Buffer remote_fingerprint_value_; |
227 std::string remote_fingerprint_algorithm_; | 224 std::string remote_fingerprint_algorithm_; |
228 | 225 |
229 // Cached DTLS ClientHello packet that was received before we started the | 226 // Cached DTLS ClientHello packet that was received before we started the |
230 // DTLS handshake. This could happen if the hello was received before the | 227 // DTLS handshake. This could happen if the hello was received before the |
231 // ice transport became writable, or before a remote fingerprint was received. | 228 // ice transport became writable, or before a remote fingerprint was received. |
232 rtc::Buffer cached_client_hello_; | 229 rtc::Buffer cached_client_hello_; |
233 | 230 |
234 bool receiving_ = false; | 231 bool receiving_ = false; |
235 bool writable_ = false; | 232 bool writable_ = false; |
236 | 233 |
237 RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransport); | 234 RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransport); |
238 }; | 235 }; |
239 | 236 |
240 } // namespace cricket | 237 } // namespace cricket |
241 | 238 |
242 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTCHANNEL_H_ | 239 #endif // WEBRTC_P2P_BASE_DTLSTRANSPORT_H_ |
OLD | NEW |