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

Side by Side Diff: webrtc/p2p/base/fakedtlstransport.h

Issue 2815513012: Negotiate the same SRTP crypto suites for every DTLS association formed. (Closed)
Patch Set: Merge with master Created 3 years, 8 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 | « webrtc/p2p/base/dtlstransportinternal.h ('k') | webrtc/p2p/base/faketransportcontroller.h » ('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 * 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
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
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 { 134 bool GetSrtpCryptoSuite(int* crypto_suite) override {
136 srtp_ciphers_ = ciphers; 135 if (!do_dtls_) {
136 return false;
137 }
138 *crypto_suite = rtc::SRTP_AES128_CM_SHA1_80;
137 return true; 139 return true;
138 } 140 }
139 bool GetSrtpCryptoSuite(int* crypto_suite) override {
140 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) {
141 *crypto_suite = chosen_crypto_suite_;
142 return true;
143 }
144 return false;
145 }
146 bool GetSslCipherSuite(int* cipher_suite) override { return false; } 141 bool GetSslCipherSuite(int* cipher_suite) override { return false; }
147 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override { 142 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override {
148 return local_cert_; 143 return local_cert_;
149 } 144 }
150 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate() 145 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate()
151 const override { 146 const override {
152 return remote_cert_ ? std::unique_ptr<rtc::SSLCertificate>( 147 return remote_cert_ ? std::unique_ptr<rtc::SSLCertificate>(
153 remote_cert_->GetReference()) 148 remote_cert_->GetReference())
154 : nullptr; 149 : nullptr;
155 } 150 }
156 bool ExportKeyingMaterial(const std::string& label, 151 bool ExportKeyingMaterial(const std::string& label,
157 const uint8_t* context, 152 const uint8_t* context,
158 size_t context_len, 153 size_t context_len,
159 bool use_context, 154 bool use_context,
160 uint8_t* result, 155 uint8_t* result,
161 size_t result_len) override { 156 size_t result_len) override {
162 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { 157 if (!do_dtls_) {
163 memset(result, 0xff, result_len); 158 return false;
164 return true;
165 } 159 }
166 160 memset(result, 0xff, result_len);
167 return false; 161 return true;
168 } 162 }
169 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { 163 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) {
170 ssl_max_version_ = version; 164 ssl_max_version_ = version;
171 } 165 }
172 rtc::SSLProtocolVersion ssl_max_protocol_version() const { 166 rtc::SSLProtocolVersion ssl_max_protocol_version() const {
173 return ssl_max_version_; 167 return ssl_max_version_;
174 } 168 }
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 169
183 IceTransportInternal* ice_transport() override { return ice_transport_; } 170 IceTransportInternal* ice_transport() override { return ice_transport_; }
184 171
185 // PacketTransportInternal implementation, which passes through to fake ICE 172 // PacketTransportInternal implementation, which passes through to fake ICE
186 // transport for sending actual packets. 173 // transport for sending actual packets.
187 bool writable() const override { return writable_; } 174 bool writable() const override { return writable_; }
188 bool receiving() const override { return receiving_; } 175 bool receiving() const override { return receiving_; }
189 int SendPacket(const char* data, 176 int SendPacket(const char* data,
190 size_t len, 177 size_t len,
191 const rtc::PacketOptions& options, 178 const rtc::PacketOptions& options,
(...skipping 14 matching lines...) Expand all
206 193
207 private: 194 private:
208 void OnIceTransportReadPacket(PacketTransportInternal* ice_, 195 void OnIceTransportReadPacket(PacketTransportInternal* ice_,
209 const char* data, 196 const char* data,
210 size_t len, 197 size_t len,
211 const rtc::PacketTime& time, 198 const rtc::PacketTime& time,
212 int flags) { 199 int flags) {
213 SignalReadPacket(this, data, len, time, flags); 200 SignalReadPacket(this, data, len, time, flags);
214 } 201 }
215 202
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) { 203 void set_receiving(bool receiving) {
230 if (receiving_ == receiving) { 204 if (receiving_ == receiving) {
231 return; 205 return;
232 } 206 }
233 receiving_ = receiving; 207 receiving_ = receiving;
234 SignalReceivingState(this); 208 SignalReceivingState(this);
235 } 209 }
236 210
237 void set_writable(bool writable) { 211 void set_writable(bool writable) {
238 if (writable_ == writable) { 212 if (writable_ == writable) {
239 return; 213 return;
240 } 214 }
241 writable_ = writable; 215 writable_ = writable;
242 if (writable_) { 216 if (writable_) {
243 SignalReadyToSend(this); 217 SignalReadyToSend(this);
244 } 218 }
245 SignalWritableState(this); 219 SignalWritableState(this);
246 } 220 }
247 221
248 FakeIceTransport* ice_transport_; 222 FakeIceTransport* ice_transport_;
249 std::unique_ptr<FakeIceTransport> owned_ice_transport_; 223 std::unique_ptr<FakeIceTransport> owned_ice_transport_;
250 std::string transport_name_; 224 std::string transport_name_;
251 int component_; 225 int component_;
252 FakeDtlsTransport* dest_ = nullptr; 226 FakeDtlsTransport* dest_ = nullptr;
253 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; 227 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_;
254 rtc::FakeSSLCertificate* remote_cert_ = nullptr; 228 rtc::FakeSSLCertificate* remote_cert_ = nullptr;
255 bool do_dtls_ = false; 229 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; 230 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
259 rtc::SSLFingerprint dtls_fingerprint_; 231 rtc::SSLFingerprint dtls_fingerprint_;
260 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT; 232 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT;
261 233
262 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; 234 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW;
263 235
264 bool receiving_ = false; 236 bool receiving_ = false;
265 bool writable_ = false; 237 bool writable_ = false;
266 }; 238 };
267 239
268 } // namespace cricket 240 } // namespace cricket
269 241
270 #endif // WEBRTC_P2P_BASE_FAKEDTLSTRANSPORT_H_ 242 #endif // WEBRTC_P2P_BASE_FAKEDTLSTRANSPORT_H_
OLDNEW
« no previous file with comments | « webrtc/p2p/base/dtlstransportinternal.h ('k') | webrtc/p2p/base/faketransportcontroller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698