OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2017 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 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (dest == dest_) { | 79 if (dest == dest_) { |
80 return; | 80 return; |
81 } | 81 } |
82 RTC_DCHECK(!dest || !dest_) | 82 RTC_DCHECK(!dest || !dest_) |
83 << "Changing fake destination from one to another is not supported."; | 83 << "Changing fake destination from one to another is not supported."; |
84 if (dest && !dest_) { | 84 if (dest && !dest_) { |
85 // This simulates the DTLS handshake. | 85 // This simulates the DTLS handshake. |
86 dest_ = dest; | 86 dest_ = dest; |
87 if (local_cert_ && dest_->local_cert_) { | 87 if (local_cert_ && dest_->local_cert_) { |
88 do_dtls_ = true; | 88 do_dtls_ = true; |
89 NegotiateSrtpCiphers(); | |
90 } | 89 } |
91 SetWritable(true); | 90 SetWritable(true); |
92 if (!asymmetric) { | 91 if (!asymmetric) { |
93 dest->SetDestination(this, true); | 92 dest->SetDestination(this, true); |
94 } | 93 } |
95 ice_transport_->SetDestination( | 94 ice_transport_->SetDestination( |
96 static_cast<FakeIceTransport*>(dest->ice_transport()), asymmetric); | 95 static_cast<FakeIceTransport*>(dest->ice_transport()), asymmetric); |
97 } else { | 96 } else { |
98 // Simulates loss of connectivity, by asymmetrically forgetting dest_. | 97 // Simulates loss of connectivity, by asymmetrically forgetting dest_. |
99 dest_ = nullptr; | 98 dest_ = nullptr; |
(...skipping 25 matching lines...) Expand all Loading... |
125 } | 124 } |
126 bool SetLocalCertificate( | 125 bool SetLocalCertificate( |
127 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { | 126 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { |
128 local_cert_ = certificate; | 127 local_cert_ = certificate; |
129 return true; | 128 return true; |
130 } | 129 } |
131 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) { | 130 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) { |
132 remote_cert_ = cert; | 131 remote_cert_ = cert; |
133 } | 132 } |
134 bool IsDtlsActive() const override { return do_dtls_; } | 133 bool IsDtlsActive() const override { return do_dtls_; } |
135 bool SetSrtpCryptoSuites(const std::vector<int>& ciphers) override { | |
136 srtp_ciphers_ = ciphers; | |
137 return true; | |
138 } | |
139 bool GetSrtpCryptoSuite(int* crypto_suite) override { | 134 bool GetSrtpCryptoSuite(int* crypto_suite) override { |
140 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { | 135 *crypto_suite = rtc::SRTP_AES128_CM_SHA1_80; |
141 *crypto_suite = chosen_crypto_suite_; | |
142 return true; | |
143 } | |
144 return false; | 136 return false; |
145 } | 137 } |
146 bool GetSslCipherSuite(int* cipher_suite) override { return false; } | 138 bool GetSslCipherSuite(int* cipher_suite) override { return false; } |
147 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override { | 139 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override { |
148 return local_cert_; | 140 return local_cert_; |
149 } | 141 } |
150 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate() | 142 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate() |
151 const override { | 143 const override { |
152 return remote_cert_ ? std::unique_ptr<rtc::SSLCertificate>( | 144 return remote_cert_ ? std::unique_ptr<rtc::SSLCertificate>( |
153 remote_cert_->GetReference()) | 145 remote_cert_->GetReference()) |
154 : nullptr; | 146 : nullptr; |
155 } | 147 } |
156 bool ExportKeyingMaterial(const std::string& label, | 148 bool ExportKeyingMaterial(const std::string& label, |
157 const uint8_t* context, | 149 const uint8_t* context, |
158 size_t context_len, | 150 size_t context_len, |
159 bool use_context, | 151 bool use_context, |
160 uint8_t* result, | 152 uint8_t* result, |
161 size_t result_len) override { | 153 size_t result_len) override { |
162 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { | 154 if (!do_dtls_) { |
163 memset(result, 0xff, result_len); | 155 return false; |
164 return true; | |
165 } | 156 } |
166 | 157 memset(result, 0xff, result_len); |
167 return false; | 158 return true; |
168 } | 159 } |
169 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { | 160 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { |
170 ssl_max_version_ = version; | 161 ssl_max_version_ = version; |
171 } | 162 } |
172 rtc::SSLProtocolVersion ssl_max_protocol_version() const { | 163 rtc::SSLProtocolVersion ssl_max_protocol_version() const { |
173 return ssl_max_version_; | 164 return ssl_max_version_; |
174 } | 165 } |
175 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override { | |
176 std::vector<int> crypto_suites; | |
177 for (const auto cipher : ciphers) { | |
178 crypto_suites.push_back(rtc::SrtpCryptoSuiteFromName(cipher)); | |
179 } | |
180 return SetSrtpCryptoSuites(crypto_suites); | |
181 } | |
182 | 166 |
183 IceTransportInternal* ice_transport() override { return ice_transport_; } | 167 IceTransportInternal* ice_transport() override { return ice_transport_; } |
184 | 168 |
185 // PacketTransportInternal implementation, which passes through to fake ICE | 169 // PacketTransportInternal implementation, which passes through to fake ICE |
186 // transport for sending actual packets. | 170 // transport for sending actual packets. |
187 bool writable() const override { return writable_; } | 171 bool writable() const override { return writable_; } |
188 bool receiving() const override { return receiving_; } | 172 bool receiving() const override { return receiving_; } |
189 int SendPacket(const char* data, | 173 int SendPacket(const char* data, |
190 size_t len, | 174 size_t len, |
191 const rtc::PacketOptions& options, | 175 const rtc::PacketOptions& options, |
(...skipping 14 matching lines...) Expand all Loading... |
206 | 190 |
207 private: | 191 private: |
208 void OnIceTransportReadPacket(PacketTransportInternal* ice_, | 192 void OnIceTransportReadPacket(PacketTransportInternal* ice_, |
209 const char* data, | 193 const char* data, |
210 size_t len, | 194 size_t len, |
211 const rtc::PacketTime& time, | 195 const rtc::PacketTime& time, |
212 int flags) { | 196 int flags) { |
213 SignalReadPacket(this, data, len, time, flags); | 197 SignalReadPacket(this, data, len, time, flags); |
214 } | 198 } |
215 | 199 |
216 void NegotiateSrtpCiphers() { | |
217 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin(); | |
218 it1 != srtp_ciphers_.end(); ++it1) { | |
219 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin(); | |
220 it2 != dest_->srtp_ciphers_.end(); ++it2) { | |
221 if (*it1 == *it2) { | |
222 chosen_crypto_suite_ = *it1; | |
223 return; | |
224 } | |
225 } | |
226 } | |
227 } | |
228 | |
229 void set_receiving(bool receiving) { | 200 void set_receiving(bool receiving) { |
230 if (receiving_ == receiving) { | 201 if (receiving_ == receiving) { |
231 return; | 202 return; |
232 } | 203 } |
233 receiving_ = receiving; | 204 receiving_ = receiving; |
234 SignalReceivingState(this); | 205 SignalReceivingState(this); |
235 } | 206 } |
236 | 207 |
237 void set_writable(bool writable) { | 208 void set_writable(bool writable) { |
238 if (writable_ == writable) { | 209 if (writable_ == writable) { |
239 return; | 210 return; |
240 } | 211 } |
241 writable_ = writable; | 212 writable_ = writable; |
242 if (writable_) { | 213 if (writable_) { |
243 SignalReadyToSend(this); | 214 SignalReadyToSend(this); |
244 } | 215 } |
245 SignalWritableState(this); | 216 SignalWritableState(this); |
246 } | 217 } |
247 | 218 |
248 FakeIceTransport* ice_transport_; | 219 FakeIceTransport* ice_transport_; |
249 std::unique_ptr<FakeIceTransport> owned_ice_transport_; | 220 std::unique_ptr<FakeIceTransport> owned_ice_transport_; |
250 std::string transport_name_; | 221 std::string transport_name_; |
251 int component_; | 222 int component_; |
252 FakeDtlsTransport* dest_ = nullptr; | 223 FakeDtlsTransport* dest_ = nullptr; |
253 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; | 224 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; |
254 rtc::FakeSSLCertificate* remote_cert_ = nullptr; | 225 rtc::FakeSSLCertificate* remote_cert_ = nullptr; |
255 bool do_dtls_ = false; | 226 bool do_dtls_ = false; |
256 std::vector<int> srtp_ciphers_; | |
257 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; | |
258 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; | 227 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; |
259 rtc::SSLFingerprint dtls_fingerprint_; | 228 rtc::SSLFingerprint dtls_fingerprint_; |
260 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT; | 229 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT; |
261 | 230 |
262 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; | 231 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; |
263 | 232 |
264 bool receiving_ = false; | 233 bool receiving_ = false; |
265 bool writable_ = false; | 234 bool writable_ = false; |
266 }; | 235 }; |
267 | 236 |
268 } // namespace cricket | 237 } // namespace cricket |
269 | 238 |
270 #endif // WEBRTC_P2P_BASE_FAKEDTLSTRANSPORT_H_ | 239 #endif // WEBRTC_P2P_BASE_FAKEDTLSTRANSPORT_H_ |
OLD | NEW |