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

Side by Side Diff: webrtc/p2p/quic/quictransportchannel.cc

Issue 1721673004: Create QuicTransportChannel (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/p2p/quic/quictransportchannel.h"
12
13 #include <utility>
14
15 #include "net/quic/crypto/proof_source.h"
16 #include "net/quic/crypto/proof_verifier.h"
17 #include "net/quic/crypto/quic_crypto_client_config.h"
18 #include "net/quic/crypto/quic_crypto_server_config.h"
19 #include "net/quic/quic_connection.h"
20 #include "net/quic/quic_crypto_client_stream.h"
21 #include "net/quic/quic_crypto_server_stream.h"
22 #include "net/quic/quic_protocol.h"
23 #include "webrtc/base/checks.h"
24 #include "webrtc/base/helpers.h"
25 #include "webrtc/base/logging.h"
26 #include "webrtc/base/socket.h"
27 #include "webrtc/base/thread.h"
28 #include "webrtc/p2p/base/common.h"
29
30 namespace {
31
32 // QUIC public header constants for net::QuicConnection. These are arbitrary
33 // given that |channel_| only receives packets specific to this channel,
34 // in which case we already know the QUIC packets have the correct destination.
35 const net::QuicConnectionId kConnectionId = 0;
36 const net::IPAddressNumber kConnectionIpAddress(net::kIPv4AddressSize, 0);
37 const net::IPEndPoint kConnectionIpEndpoint(kConnectionIpAddress, 0);
38
39 // Arbitrary server port number for net::QuicCryptoClientConfig.
40 const int kQuicServerPort = 0;
41
42 // QUIC connection timeout in seconds. This is large so that |channel_| can
43 // be responsible for connection timeout.
44 const int kIdleConnectionStateLifetime = 1000;
pthatcher1 2016/02/25 08:24:25 Is this in ms? If so, I don't think 1000 is long
mikescarlett 2016/02/26 00:54:13 Seconds. This is roughly 16.7 minutes.
pthatcher1 2016/02/27 01:14:19 Ah... that's long enough :). But can you put a co
mikescarlett 2016/03/01 00:02:10 Done.
45
46 // Length of HKDF input keying material, equal to its number of bytes.
47 const size_t kInputKeyingMaterialLength = 32;
pthatcher1 2016/02/25 08:24:25 Where does this come from?
mikescarlett 2016/02/26 00:54:14 I added the link where HKDF input keying material
48
49 // We don't pull the RTP constants from rtputils.h, to avoid a layer violation.
50 const size_t kMinRtpPacketLen = 12;
51
52 bool IsRtpPacket(const char* data, size_t len) {
53 const uint8_t* u = reinterpret_cast<const uint8_t*>(data);
54 return (len >= kMinRtpPacketLen && (u[0] & 0xC0) == 0x80);
55 }
56
57 // Function for detecting QUIC packets based off
58 // https://tools.ietf.org/html/draft-tsvwg-quic-protocol-02#section-6.
59 const size_t kMinQuicPacketLen = 2;
60
61 bool IsQuicPacket(const char* data, size_t len) {
62 const uint8_t* u = reinterpret_cast<const uint8_t*>(data);
63 return (len >= kMinQuicPacketLen && (u[0] & 0x80) == 0);
64 }
65
66 // Used by QuicCryptoServerConfig to provide dummy proof credentials.
67 // TODO(mikescarlett): Remove when secure P2P QUIC handshake is possible.
68 class InsecureProofSource : public net::ProofSource {
pthatcher1 2016/02/25 08:24:24 Might as well call this DummyProofSource
mikescarlett 2016/02/26 00:54:13 Done.
69 public:
70 InsecureProofSource() {}
71 ~InsecureProofSource() override {}
72
73 // ProofSource override.
74 bool GetProof(const net::IPAddressNumber& server_ip,
75 const std::string& hostname,
76 const std::string& server_config,
77 bool ecdsa_ok,
78 const std::vector<std::string>** out_certs,
79 std::string* out_signature,
80 std::string* out_leaf_cert_sct) override {
81 LOG(LS_INFO) << "GetProof() providing dummy credentials for insecure QUIC";
82 std::vector<std::string>* certs = new std::vector<std::string>();
83 certs->push_back("Required to establish handshake");
pthatcher1 2016/02/25 08:24:24 And say "Dummy cert"
mikescarlett 2016/02/26 00:54:14 Done.
84 std::string signature("Signature");
pthatcher1 2016/02/25 08:24:25 And "Dummy signature"
mikescarlett 2016/02/26 00:54:13 Done.
85
86 *out_certs = certs;
87 *out_signature = signature;
88
89 return true;
90 }
91 };
92
93 // Used by QuicCryptoClientConfig to ignore the peer's credentials
94 // and establish an insecure QUIC connection.
95 // TODO(mikescarlett): Remove when secure P2P QUIC handshake is possible.
96 class InsecureProofVerifier : public net::ProofVerifier {
97 public:
98 InsecureProofVerifier() {}
99 ~InsecureProofVerifier() override {}
100
101 // ProofVerifier override.
102 net::QuicAsyncStatus VerifyProof(
103 const std::string& hostname,
104 const std::string& server_config,
105 const std::vector<std::string>& certs,
106 const std::string& cert_sct,
107 const std::string& signature,
108 const net::ProofVerifyContext* verify_context,
109 std::string* error_details,
110 scoped_ptr<net::ProofVerifyDetails>* verify_details,
111 net::ProofVerifierCallback* callback) override {
112 LOG(LS_INFO) << "VerifyProof() ignoring credentials and returning success";
113 return net::QUIC_SUCCESS;
114 }
115 };
116
117 } // namespace
118
119 namespace cricket {
120
121 QuicTransportChannel::QuicTransportChannel(TransportChannelImpl* channel)
122 : TransportChannelImpl(channel->transport_name(), channel->component()),
123 worker_thread_(rtc::Thread::Current()),
124 channel_(channel),
125 helper_(worker_thread_),
126 ssl_role_(rtc::SSL_CLIENT) {
127 channel_->SignalWritableState.connect(this,
128 &QuicTransportChannel::OnWritableState);
129 channel_->SignalReadPacket.connect(this, &QuicTransportChannel::OnReadPacket);
130 channel_->SignalSentPacket.connect(this, &QuicTransportChannel::OnSentPacket);
131 channel_->SignalReadyToSend.connect(this,
132 &QuicTransportChannel::OnReadyToSend);
133 channel_->SignalGatheringState.connect(
134 this, &QuicTransportChannel::OnGatheringState);
135 channel_->SignalCandidateGathered.connect(
136 this, &QuicTransportChannel::OnCandidateGathered);
137 channel_->SignalRoleConflict.connect(this,
138 &QuicTransportChannel::OnRoleConflict);
139 channel_->SignalRouteChange.connect(this,
140 &QuicTransportChannel::OnRouteChange);
141 channel_->SignalConnectionRemoved.connect(
142 this, &QuicTransportChannel::OnConnectionRemoved);
143 channel_->SignalReceivingState.connect(
144 this, &QuicTransportChannel::OnReceivingState);
145
146 config_.SetIdleConnectionStateLifetime(
147 net::QuicTime::Delta::FromSeconds(kIdleConnectionStateLifetime),
148 net::QuicTime::Delta::FromSeconds(kIdleConnectionStateLifetime));
149 config_.SetBytesForConnectionIdToSend(0);
pthatcher1 2016/02/25 08:24:24 What's this?
mikescarlett 2016/02/26 00:54:14 Added a comment. This should set the bytes reserve
150 }
151
152 QuicTransportChannel::~QuicTransportChannel() {}
153
154 void QuicTransportChannel::Connect() {
155 // We should only get a single call to Connect.
156 ASSERT(quic_state() == QUIC_TRANSPORT_NEW);
157 channel_->Connect();
158 }
159
160 bool QuicTransportChannel::SetLocalCertificate(
161 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
162 if (quic_active_) {
163 if (certificate == local_certificate_) {
164 // This may happen during renegotiation.
165 LOG_J(LS_INFO, this) << "Ignoring identical certificate";
pthatcher1 2016/02/25 08:24:24 Just use INFO (like you do ERROR) with no "LS_".
mikescarlett 2016/02/26 00:54:13 Done.
166 return true;
167 } else {
168 LOG_J(ERROR, this) << "Can't change local certificate in this state";
pthatcher1 2016/02/25 08:24:24 This could be a little more details, perhaps somet
mikescarlett 2016/02/26 00:54:14 Done.
169 return false;
170 }
171 }
172 if (certificate) {
173 local_certificate_ = certificate;
174 quic_active_ = true;
175 } else {
176 LOG_J(LS_INFO, this) << "NULL identity supplied. Not doing QUIC.";
pthatcher1 2016/02/25 08:24:25 Should this be WARN instead of INFO? And should i
mikescarlett 2016/02/26 00:54:13 Yes it should. I think ERROR seems more appropriat
177 }
178 return true;
pthatcher1 2016/02/25 08:24:25 The whole method could be rearranged a bit to be m
mikescarlett 2016/02/26 00:54:13 Done.
179 }
180
181 rtc::scoped_refptr<rtc::RTCCertificate>
182 QuicTransportChannel::GetLocalCertificate() const {
183 return local_certificate_;
184 }
185
186 bool QuicTransportChannel::SetSslRole(rtc::SSLRole role) {
187 if (quic_state() == QUIC_TRANSPORT_CONNECTED) {
188 if (ssl_role_ != role) {
189 LOG_J(LS_ERROR, this)
190 << "SSL Role can't be reversed after the session is setup.";
191 return false;
192 }
193 return true;
194 }
195 ssl_role_ = role;
196 set_ssl_role_ = true;
197 return true;
pthatcher1 2016/02/25 08:24:24 Same here with the early returns: if (ssl_role_
mikescarlett 2016/02/26 00:54:13 Done.
198 }
199
200 bool QuicTransportChannel::GetSslRole(rtc::SSLRole* role) const {
201 *role = ssl_role_;
202 return true;
203 }
204
205 bool QuicTransportChannel::SetRemoteFingerprint(const std::string& digest_alg,
206 const uint8_t* digest,
207 size_t digest_len) {
208 std::string remote_fingerprint_value(reinterpret_cast<const char*>(digest),
209 digest_len);
210
211 // Once we have the local certificate, the same remote fingerprint can be set
212 // multiple times.
213 if (quic_active_ && remote_fingerprint_value_ == remote_fingerprint_value &&
214 !digest_alg.empty()) {
pthatcher1 2016/02/25 08:24:24 Wouldn't we ignore an identical remote_fingerprint
mikescarlett 2016/02/26 00:54:14 Yes. Fixed now.
215 // This may happen during renegotiation.
216 LOG_J(LS_INFO, this) << "Ignoring identical remote fingerprint";
217 return true;
218 }
219
220 // If the other side doesn't support digest algorithm, turn off
221 // |quic_active_|.
222 if (digest_alg.empty()) {
223 RTC_DCHECK(!digest_len);
224 LOG_J(LS_INFO, this) << "Other side didn't support digest algorithm.";
225 quic_active_ = false;
226 return true;
227 }
pthatcher1 2016/02/25 08:24:25 I think it would make sense to make this one first
mikescarlett 2016/02/26 00:54:13 Done. Also I think this should log an error and re
228
229 // At this point we know we are doing QUIC
230 remote_fingerprint_value_ = std::move(remote_fingerprint_value);
231 remote_fingerprint_algorithm_ = digest_alg;
232 set_remote_fingerprint_ = true;
233
234 return true;
235 }
236
237 bool QuicTransportChannel::ExportKeyingMaterial(const std::string& label,
238 const uint8_t* context,
239 size_t context_len,
240 bool use_context,
241 uint8_t* result,
242 size_t result_len) {
243 std::string quic_context(reinterpret_cast<const char*>(context), context_len);
244 std::string quic_result;
245 if (!quic_->ExportKeyingMaterial(label, quic_context, result_len,
246 &quic_result)) {
247 return false;
248 }
249 quic_result.copy(reinterpret_cast<char*>(result), result_len);
250 return true;
251 }
252
253 bool QuicTransportChannel::GetSrtpCryptoSuite(int* cipher) {
254 *cipher = rtc::SRTP_AES128_CM_SHA1_80;
255 return true;
256 }
257
258 // Called from upper layers to send a media packet.
259 int QuicTransportChannel::SendPacket(const char* data,
260 size_t size,
261 const rtc::PacketOptions& options,
262 int flags) {
263 if (!quic_active_) {
264 // Not doing QUIC.
265 return channel_->SendPacket(data, size, options);
pthatcher1 2016/02/25 08:24:25 I think we can remove this.
mikescarlett 2016/02/26 00:54:13 Done.
266 }
267
268 switch (quic_state()) {
269 case QUIC_TRANSPORT_NEW:
270 // Can't send data until the connection is active.
271 return -1;
272 case QUIC_TRANSPORT_CONNECTING:
273 // Can't send data until the connection is active.
274 return -1;
pthatcher1 2016/02/25 08:24:25 If it's SRTP_BYPASS, we can, can't we? I think th
mikescarlett 2016/02/26 00:54:14 Done. That seems reasonable since SRTP is always e
275 case QUIC_TRANSPORT_CONNECTED:
276 if (flags & PF_SRTP_BYPASS) {
277 if (!IsRtpPacket(data, size)) {
278 return -1;
279 }
280 return channel_->SendPacket(data, size, options);
281 }
282 return -1;
283 case QUIC_TRANSPORT_FAILED:
284 // Can't send anything when we're closed.
285 return -1;
286 default:
287 ASSERT(false);
288 return -1;
289 }
290 }
291
292 // The state transition logic here is as follows:
293 // (1) If we're not doing QUIC, then the state is equivalent to the
294 // state of |channel_|.
295 // (2) If we're doing QUIC:
296 // - Prior to the QUIC handshake, the state is neither receiving nor
297 // writable.
298 // - When |channel_| goes writable for the first time we
299 // start the QUIC handshake.
300 // - Once the QUIC handshake completes, the state is that of the
301 // |channel_| again.
302 void QuicTransportChannel::OnWritableState(TransportChannel* channel) {
303 ASSERT(rtc::Thread::Current() == worker_thread_);
304 ASSERT(channel == channel_);
305 LOG_J(LS_VERBOSE, this)
306 << "QuicTransportChannel: channel writable state changed to "
307 << channel_->writable();
308
309 if (!quic_active_) {
310 // Not doing QUIC.
311 // Note: SignalWritableState fired by set_writable.
312 set_writable(channel_->writable());
pthatcher1 2016/02/25 08:24:25 I think we can remove this.
mikescarlett 2016/02/26 00:54:13 I removed it. So the QUIC channel is not writable
313 return;
314 }
315
316 switch (quic_state()) {
317 case QUIC_TRANSPORT_NEW:
318 // This should never fail:
319 // Because we are operating in a nonblocking mode and all
320 // incoming packets come in via OnReadPacket(), which rejects
321 // packets in this state, the incoming queue must be empty. We
322 // ignore write errors, thus any errors must be because of
323 // configuration and therefore are our fault.
324 // Note that in non-debug configurations, failure in
325 // MaybeStartQuic() changes the state to QUIC_TRANSPORT_FAILED.
326 VERIFY(MaybeStartQuic());
327 break;
328 case QUIC_TRANSPORT_CONNECTED:
329 // Note: SignalWritableState fired by set_writable.
330 set_writable(channel_->writable());
331 break;
332 case QUIC_TRANSPORT_CONNECTING:
333 // This channel is not writable until QUIC handshake finishes. It might
334 // have been write blocked.
335 if (HasDataToWrite()) {
336 OnCanWrite();
337 }
pthatcher1 2016/02/25 08:24:25 Should we do this for QUIC_TRANSPORT_CONNECTED als
mikescarlett 2016/02/26 00:54:14 Yes. Fixed this.
338 break;
339 case QUIC_TRANSPORT_FAILED:
340 // Should not happen. Do nothing.
341 break;
342 }
343 }
344
345 void QuicTransportChannel::OnReceivingState(TransportChannel* channel) {
346 ASSERT(rtc::Thread::Current() == worker_thread_);
347 ASSERT(channel == channel_);
348 LOG_J(LS_VERBOSE, this)
349 << "QuicTransportChannel: channel receiving state changed to "
350 << channel_->receiving();
351 if (!quic_active_ || quic_state() == QUIC_TRANSPORT_CONNECTED) {
pthatcher1 2016/02/25 08:24:25 I think we can remove the !quic_active_ part of th
mikescarlett 2016/02/26 00:54:14 Done. !quic_active_ would essentially be false sin
352 // Note: SignalReceivingState fired by set_receiving.
353 set_receiving(channel_->receiving());
354 }
355 }
356
357 void QuicTransportChannel::OnReadPacket(TransportChannel* channel,
358 const char* data,
359 size_t size,
360 const rtc::PacketTime& packet_time,
361 int flags) {
362 ASSERT(rtc::Thread::Current() == worker_thread_);
363 ASSERT(channel == channel_);
364 ASSERT(flags == 0);
365
366 if (!quic_active_) {
367 // Not doing QUIC.
368 SignalReadPacket(this, data, size, packet_time, 0);
369 return;
370 }
pthatcher1 2016/02/25 08:24:24 I think we can remove this.
mikescarlett 2016/02/26 00:54:14 Removed.
371
372 switch (quic_state()) {
373 case QUIC_TRANSPORT_NEW:
374 if (set_remote_fingerprint_) {
375 // This would occur if other peer is ready to start QUIC but this peer
376 // hasn't started QUIC.
377 LOG_J(LS_INFO, this) << "Dropping packet received before QUIC started.";
378 } else {
379 // Currently drop the packet, but we might in future
380 // decide to take this as evidence that the other
381 // side is ready to do QUIC and start the handshake
382 // on our end.
383 LOG_J(LS_WARNING, this) << "Received packet before we know if we are "
384 << "doing QUIC or not; dropping.";
385 }
386 break;
387 case QUIC_TRANSPORT_CONNECTING:
388 case QUIC_TRANSPORT_CONNECTED:
389 // We should only get QUIC or SRTP packets; STUN's already been demuxed.
390 // Is this potentially a QUIC packet?
391 if (IsQuicPacket(data, size)) {
392 if (!HandleQuicPacket(data, size)) {
393 LOG_J(ERROR, this) << "Failed to handle QUIC packet.";
394 return;
395 }
396 } else {
397 // Not a QUIC packet; our handshake should be complete.
398 if (quic_state() != QUIC_TRANSPORT_CONNECTED) {
399 LOG_J(ERROR, this) << "Received non-QUIC packet before QUIC "
400 << "complete.";
401 return;
402 }
pthatcher1 2016/02/25 08:24:24 We can probably just pass RTP packet through even
mikescarlett 2016/02/26 00:54:13 True. Removed the extra if statement.
403 // And it had better be a SRTP packet.
404 if (!IsRtpPacket(data, size)) {
405 LOG_J(ERROR, this) << "Received unexpected non-QUIC packet.";
pthatcher1 2016/02/25 08:24:24 non-QUIC, non-RTP packet :).
mikescarlett 2016/02/26 00:54:14 Done.
406 return;
407 }
408 // Signal this upwards as a bypass packet.
409 SignalReadPacket(this, data, size, packet_time, PF_SRTP_BYPASS);
410 }
411 break;
412 case QUIC_TRANSPORT_FAILED:
413 // This shouldn't be happening. Drop the packet.
414 break;
415 }
416 }
417
418 void QuicTransportChannel::OnSentPacket(TransportChannel* channel,
419 const rtc::SentPacket& sent_packet) {
420 ASSERT(rtc::Thread::Current() == worker_thread_);
421 SignalSentPacket(this, sent_packet);
422 }
423
424 void QuicTransportChannel::OnReadyToSend(TransportChannel* channel) {
425 if (writable()) {
426 SignalReadyToSend(this);
427 }
428 }
429
430 void QuicTransportChannel::OnGatheringState(TransportChannelImpl* channel) {
431 ASSERT(channel == channel_);
432 SignalGatheringState(this);
433 }
434
435 void QuicTransportChannel::OnCandidateGathered(TransportChannelImpl* channel,
436 const Candidate& c) {
437 ASSERT(channel == channel_);
438 SignalCandidateGathered(this, c);
439 }
440
441 void QuicTransportChannel::OnRoleConflict(TransportChannelImpl* channel) {
442 ASSERT(channel == channel_);
443 SignalRoleConflict(this);
444 }
445
446 void QuicTransportChannel::OnRouteChange(TransportChannel* channel,
447 const Candidate& candidate) {
448 ASSERT(channel == channel_);
449 SignalRouteChange(this, candidate);
450 }
451
452 void QuicTransportChannel::OnConnectionRemoved(TransportChannelImpl* channel) {
453 ASSERT(channel == channel_);
454 SignalConnectionRemoved(this);
455 }
456
457 bool QuicTransportChannel::MaybeStartQuic() {
458 if (!channel_->writable()) {
pthatcher1 2016/02/25 08:24:25 That seems a bit drastic. Just because we're not
mikescarlett 2016/02/26 00:54:13 Seems fine.
459 LOG_J(ERROR, this) << "Couldn't start QUIC handshake";
460 set_quic_state(QUIC_TRANSPORT_FAILED);
461 return false;
462 }
463 if (!CreateQuicSession() || !StartQuicHandshake()) {
pthatcher1 2016/02/25 08:24:25 This could use a LOG_J(ERROR) or LOG_J(WARN).
mikescarlett 2016/02/26 00:54:13 Done. I agree.
464 return false;
465 }
466 // Verify connection is not closed due to QUIC bug or network failure.
467 // A closed connection should not happen since |channel_| is writable.
468 RTC_DCHECK(quic_->connection()->connected());
pthatcher1 2016/02/25 08:24:25 It seems like it would be a good idea to just log
mikescarlett 2016/02/26 00:54:14 Ok I'll do that so QUIC bugs don't crash everythin
469 // Indicate that |quic_| is ready to receive QUIC packets.
470 set_quic_state(QUIC_TRANSPORT_CONNECTING);
471 return true;
472 }
473
474 bool QuicTransportChannel::CreateQuicSession() {
475 if (!set_ssl_role_) {
476 return false;
477 }
478 net::Perspective perspective = (ssl_role_ == rtc::SSL_CLIENT)
479 ? net::Perspective::IS_CLIENT
480 : net::Perspective::IS_SERVER;
481 bool owns_writer = false;
482 scoped_ptr<net::QuicConnection> connection(new net::QuicConnection(
483 kConnectionId, kConnectionIpEndpoint, &helper_, this, owns_writer,
484 perspective, net::QuicSupportedVersions()));
485 quic_.reset(new QuicSession(std::move(connection), config_));
486 quic_->SignalHandshakeComplete.connect(
487 this, &QuicTransportChannel::OnHandshakeComplete);
488 quic_->SignalConnectionClosed.connect(
489 this, &QuicTransportChannel::OnConnectionClosed);
490 return true;
491 }
492
493 bool QuicTransportChannel::StartQuicHandshake() {
494 if (ssl_role_ == rtc::SSL_CLIENT) {
495 // Unique identifier for remote peer.
496 net::QuicServerId server_id(remote_fingerprint_value_, kQuicServerPort);
497 // Performs authentication of remote peer; owned by QuicCryptoClientConfig.
498 // TODO(mikescarlett): Actually verify proof.
499 net::ProofVerifier* proof_verifier = new InsecureProofVerifier();
500 quic_crypto_client_config_.reset(
501 new net::QuicCryptoClientConfig(proof_verifier));
502 net::QuicCryptoClientStream* crypto_stream =
503 new net::QuicCryptoClientStream(server_id, quic_.get(),
504 new net::ProofVerifyContext(),
505 quic_crypto_client_config_.get(), this);
506 quic_->StartClientHandshake(crypto_stream);
507 LOG_J(LS_INFO, this) << "QuicTransportChannel: Started client handshake.";
508 } else {
509 RTC_DCHECK_EQ(ssl_role_, rtc::SSL_SERVER);
510 // Provides credentials to remote peer; owned by QuicCryptoServerConfig.
511 // TODO(mikescarlett): Actually provide credentials.
512 net::ProofSource* proof_source = new InsecureProofSource();
513 // Input keying material to HKDF, per http://tools.ietf.org/html/rfc5869.
514 // This is pseudorandom so that HKDF-Extract outputs a pseudorandom key,
515 // since QuicCryptoServerConfig does not use a salt value.
516 std::string source_address_token_secret;
517 if (!rtc::CreateRandomString(kInputKeyingMaterialLength,
518 &source_address_token_secret)) {
519 LOG_J(ERROR, this) << "Error generating input keying material for HKDF.";
520 return false;
521 }
522 quic_crypto_server_config_.reset(new net::QuicCryptoServerConfig(
523 source_address_token_secret, helper_.GetRandomGenerator(),
524 proof_source));
525 // Provides server with serialized config string to prove ownership.
526 net::QuicCryptoServerConfig::ConfigOptions options;
527 quic_crypto_server_config_->AddDefaultConfig(helper_.GetRandomGenerator(),
528 helper_.GetClock(), options);
529 net::QuicCryptoServerStream* crypto_stream =
530 new net::QuicCryptoServerStream(quic_crypto_server_config_.get(),
531 quic_.get());
532 quic_->StartServerHandshake(crypto_stream);
533 LOG_J(LS_INFO, this) << "QuicTransportChannel: Started server handshake.";
534 }
535 return true;
536 }
537
538 bool QuicTransportChannel::HandleQuicPacket(const char* data, size_t size) {
539 ASSERT(rtc::Thread::Current() == worker_thread_);
540 return quic_->OnReadPacket(data, size);
541 }
542
543 net::WriteResult QuicTransportChannel::WritePacket(
544 const char* buffer,
545 size_t buf_len,
546 const net::IPAddressNumber& self_address,
547 const net::IPEndPoint& peer_address) {
548 int sent = channel_->SendPacket(buffer, buf_len, rtc::PacketOptions());
549 if (sent <= 0) {
550 int error = GetError();
551 LOG_J(LS_WARNING, this) << "Write failed with socket error " << error;
552 // Since net::WRITE_STATUS_ERROR irreversibly shuts down the QUIC
553 // connection, write status is net::WRITE_STATUS_BLOCKED so that QUIC
554 // packets are queued.
555 return net::WriteResult(net::WRITE_STATUS_BLOCKED, error);
pthatcher1 2016/02/25 08:24:24 There error is only blocking if IsBlockingError(er
mikescarlett 2016/02/26 00:54:13 I believe net::WRITE_STATUS_ERROR was closing the
mikescarlett 2016/02/26 16:52:36 Strangely the QuicSession gets torn down on net::W
556 }
557 return net::WriteResult(net::WRITE_STATUS_OK, sent);
558 }
559
560 // TODO(mikescarlett): |channel_| can be writable but write blocked. Since
561 // channel_->GetError() is not updated when there is no error, the only option
562 // seems to be writing the packet anyway in this case.
563 bool QuicTransportChannel::IsWriteBlocked() const {
564 return !channel_->writable();
565 }
566
567 void QuicTransportChannel::OnHandshakeComplete() {
568 set_quic_state(QUIC_TRANSPORT_CONNECTED);
569 set_writable(true);
570 }
571
572 void QuicTransportChannel::OnConnectionClosed(net::QuicErrorCode error,
573 bool from_peer) {
574 LOG_J(LS_INFO, this) << "Connection closed by "
575 << (from_peer ? "other" : "this") << " peer "
576 << "with QUIC error " << error;
577 set_quic_state(QUIC_TRANSPORT_FAILED);
578 set_writable(false);
579 }
580
581 void QuicTransportChannel::OnProofValid(
582 const net::QuicCryptoClientConfig::CachedState& cached) {
583 LOG_J(LS_INFO, this) << "Cached proof marked valid";
584 }
585
586 void QuicTransportChannel::OnProofVerifyDetailsAvailable(
587 const net::ProofVerifyDetails& verify_details) {
588 LOG_J(LS_INFO, this) << "Proof verify details available from"
589 << " QuicCryptoClientStream";
590 }
591
592 bool QuicTransportChannel::HasDataToWrite() const {
593 return quic_ && quic_->HasDataToWrite();
594 }
595
596 void QuicTransportChannel::OnCanWrite() {
597 RTC_DCHECK(quic_ != nullptr);
598 quic_->connection()->OnCanWrite();
599 }
600
601 void QuicTransportChannel::set_quic_state(QuicTransportState state) {
602 LOG_J(LS_VERBOSE, this) << "set_quic_state from:" << quic_state_ << " to "
603 << state;
604 quic_state_ = state;
605 }
606
607 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698