| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 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 #include "webrtc/p2p/quic/quictransportchannel.h" | 11 #include "webrtc/p2p/quic/quictransportchannel.h" |
| 12 | 12 |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "net/quic/crypto/proof_source.h" | 15 #include "net/quic/crypto/proof_source.h" |
| 16 #include "net/quic/crypto/proof_verifier.h" | 16 #include "net/quic/crypto/proof_verifier.h" |
| 17 #include "net/quic/crypto/quic_crypto_client_config.h" | 17 #include "net/quic/crypto/quic_crypto_client_config.h" |
| 18 #include "net/quic/crypto/quic_crypto_server_config.h" | 18 #include "net/quic/crypto/quic_crypto_server_config.h" |
| 19 #include "net/quic/quic_connection.h" | 19 #include "net/quic/quic_connection.h" |
| 20 #include "net/quic/quic_crypto_client_stream.h" | 20 #include "net/quic/quic_crypto_client_stream.h" |
| 21 #include "net/quic/quic_crypto_server_stream.h" | 21 #include "net/quic/quic_crypto_server_stream.h" |
| 22 #include "net/quic/quic_packet_writer.h" |
| 22 #include "net/quic/quic_protocol.h" | 23 #include "net/quic/quic_protocol.h" |
| 23 #include "webrtc/base/checks.h" | 24 #include "webrtc/base/checks.h" |
| 24 #include "webrtc/base/helpers.h" | 25 #include "webrtc/base/helpers.h" |
| 25 #include "webrtc/base/logging.h" | 26 #include "webrtc/base/logging.h" |
| 26 #include "webrtc/base/socket.h" | 27 #include "webrtc/base/socket.h" |
| 27 #include "webrtc/base/thread.h" | 28 #include "webrtc/base/thread.h" |
| 28 #include "webrtc/p2p/base/common.h" | 29 #include "webrtc/p2p/base/common.h" |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // QUIC public header constants for net::QuicConnection. These are arbitrary | 33 // QUIC public header constants for net::QuicConnection. These are arbitrary |
| 33 // given that |channel_| only receives packets specific to this channel, | 34 // 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 // in which case we already know the QUIC packets have the correct destination. |
| 35 const net::QuicConnectionId kConnectionId = 0; | 36 const net::QuicConnectionId kConnectionId = 0; |
| 36 const net::IPAddressNumber kConnectionIpAddress(net::kIPv4AddressSize, 0); | 37 const net::IPAddress kConnectionIpAddress(0, 0, 0, 0); |
| 37 const net::IPEndPoint kConnectionIpEndpoint(kConnectionIpAddress, 0); | 38 const net::IPEndPoint kConnectionIpEndpoint(kConnectionIpAddress, 0); |
| 38 | 39 |
| 39 // Arbitrary server port number for net::QuicCryptoClientConfig. | 40 // Arbitrary server port number for net::QuicCryptoClientConfig. |
| 40 const int kQuicServerPort = 0; | 41 const int kQuicServerPort = 0; |
| 41 | 42 |
| 42 // QUIC connection timeout. This is large so that |channel_| can | 43 // QUIC connection timeout. This is large so that |channel_| can |
| 43 // be responsible for connection timeout. | 44 // be responsible for connection timeout. |
| 44 const int kIdleConnectionStateLifetime = 1000; // seconds | 45 const int kIdleConnectionStateLifetime = 1000; // seconds |
| 45 | 46 |
| 46 // Length of HKDF input keying material, equal to its number of bytes. | 47 // Length of HKDF input keying material, equal to its number of bytes. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 66 } | 67 } |
| 67 | 68 |
| 68 // Used by QuicCryptoServerConfig to provide dummy proof credentials. | 69 // Used by QuicCryptoServerConfig to provide dummy proof credentials. |
| 69 // TODO(mikescarlett): Remove when secure P2P QUIC handshake is possible. | 70 // TODO(mikescarlett): Remove when secure P2P QUIC handshake is possible. |
| 70 class DummyProofSource : public net::ProofSource { | 71 class DummyProofSource : public net::ProofSource { |
| 71 public: | 72 public: |
| 72 DummyProofSource() {} | 73 DummyProofSource() {} |
| 73 ~DummyProofSource() override {} | 74 ~DummyProofSource() override {} |
| 74 | 75 |
| 75 // ProofSource override. | 76 // ProofSource override. |
| 76 bool GetProof(const net::IPAddressNumber& server_ip, | 77 bool GetProof(const net::IPAddress& server_ip, |
| 77 const std::string& hostname, | 78 const std::string& hostname, |
| 78 const std::string& server_config, | 79 const std::string& server_config, |
| 80 net::QuicVersion quic_version, |
| 81 base::StringPiece chlo_hash, |
| 79 bool ecdsa_ok, | 82 bool ecdsa_ok, |
| 80 const std::vector<std::string>** out_certs, | 83 scoped_refptr<net::ProofSource::Chain>* out_chain, |
| 81 std::string* out_signature, | 84 std::string* out_signature, |
| 82 std::string* out_leaf_cert_sct) override { | 85 std::string* out_leaf_cert_sct) override { |
| 83 LOG(INFO) << "GetProof() providing dummy credentials for insecure QUIC"; | 86 LOG(LS_INFO) << "GetProof() providing dummy credentials for insecure QUIC"; |
| 84 std::vector<std::string>* certs = new std::vector<std::string>(); | 87 std::vector<std::string> certs; |
| 85 certs->push_back("Dummy cert"); | 88 certs.push_back("Dummy cert"); |
| 86 std::string signature("Dummy signature"); | 89 *out_chain = new ProofSource::Chain(certs); |
| 87 | 90 *out_signature = "Dummy signature"; |
| 88 *out_certs = certs; | 91 *out_leaf_cert_sct = "Dummy timestamp"; |
| 89 *out_signature = signature; | |
| 90 | |
| 91 return true; | 92 return true; |
| 92 } | 93 } |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 // Used by QuicCryptoClientConfig to ignore the peer's credentials | 96 // Used by QuicCryptoClientConfig to ignore the peer's credentials |
| 96 // and establish an insecure QUIC connection. | 97 // and establish an insecure QUIC connection. |
| 97 // TODO(mikescarlett): Remove when secure P2P QUIC handshake is possible. | 98 // TODO(mikescarlett): Remove when secure P2P QUIC handshake is possible. |
| 98 class InsecureProofVerifier : public net::ProofVerifier { | 99 class InsecureProofVerifier : public net::ProofVerifier { |
| 99 public: | 100 public: |
| 100 InsecureProofVerifier() {} | 101 InsecureProofVerifier() {} |
| 101 ~InsecureProofVerifier() override {} | 102 ~InsecureProofVerifier() override {} |
| 102 | 103 |
| 103 // ProofVerifier override. | 104 // ProofVerifier override. |
| 104 net::QuicAsyncStatus VerifyProof( | 105 net::QuicAsyncStatus VerifyProof( |
| 105 const std::string& hostname, | 106 const std::string& hostname, |
| 106 const std::string& server_config, | 107 const std::string& server_config, |
| 107 const std::vector<std::string>& certs, | 108 const std::vector<std::string>& certs, |
| 108 const std::string& cert_sct, | 109 const std::string& cert_sct, |
| 109 const std::string& signature, | 110 const std::string& signature, |
| 110 const net::ProofVerifyContext* verify_context, | 111 const net::ProofVerifyContext* verify_context, |
| 111 std::string* error_details, | 112 std::string* error_details, |
| 112 scoped_ptr<net::ProofVerifyDetails>* verify_details, | 113 scoped_ptr<net::ProofVerifyDetails>* verify_details, |
| 113 net::ProofVerifierCallback* callback) override { | 114 net::ProofVerifierCallback* callback) override { |
| 114 LOG(INFO) << "VerifyProof() ignoring credentials and returning success"; | 115 LOG(LS_INFO) << "VerifyProof() ignoring credentials and returning success"; |
| 115 return net::QUIC_SUCCESS; | 116 return net::QUIC_SUCCESS; |
| 116 } | 117 } |
| 117 }; | 118 }; |
| 118 | 119 |
| 119 } // namespace | 120 } // namespace |
| 120 | 121 |
| 121 namespace cricket { | 122 namespace cricket { |
| 122 | 123 |
| 123 QuicTransportChannel::QuicTransportChannel(TransportChannelImpl* channel) | 124 QuicTransportChannel::QuicTransportChannel(TransportChannelImpl* channel) |
| 124 : TransportChannelImpl(channel->transport_name(), channel->component()), | 125 : TransportChannelImpl(channel->transport_name(), channel->component()), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 150 net::QuicTime::Delta::FromSeconds(kIdleConnectionStateLifetime)); | 151 net::QuicTime::Delta::FromSeconds(kIdleConnectionStateLifetime)); |
| 151 // Set the bytes reserved for the QUIC connection ID to zero. | 152 // Set the bytes reserved for the QUIC connection ID to zero. |
| 152 config_.SetBytesForConnectionIdToSend(0); | 153 config_.SetBytesForConnectionIdToSend(0); |
| 153 } | 154 } |
| 154 | 155 |
| 155 QuicTransportChannel::~QuicTransportChannel() {} | 156 QuicTransportChannel::~QuicTransportChannel() {} |
| 156 | 157 |
| 157 bool QuicTransportChannel::SetLocalCertificate( | 158 bool QuicTransportChannel::SetLocalCertificate( |
| 158 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { | 159 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
| 159 if (!certificate) { | 160 if (!certificate) { |
| 160 LOG_J(ERROR, this) << "No local certificate was supplied. Not doing QUIC."; | 161 LOG_J(LS_ERROR, this) |
| 162 << "No local certificate was supplied. Not doing QUIC."; |
| 161 return false; | 163 return false; |
| 162 } | 164 } |
| 163 if (!local_certificate_) { | 165 if (!local_certificate_) { |
| 164 local_certificate_ = certificate; | 166 local_certificate_ = certificate; |
| 165 return true; | 167 return true; |
| 166 } | 168 } |
| 167 if (certificate == local_certificate_) { | 169 if (certificate == local_certificate_) { |
| 168 // This may happen during renegotiation. | 170 // This may happen during renegotiation. |
| 169 LOG_J(INFO, this) << "Ignoring identical certificate"; | 171 LOG_J(LS_INFO, this) << "Ignoring identical certificate"; |
| 170 return true; | 172 return true; |
| 171 } | 173 } |
| 172 LOG_J(ERROR, this) << "Local certificate of the QUIC connection already set. " | 174 LOG_J(LS_ERROR, this) |
| 173 "Can't change the local certificate once it's active."; | 175 << "Local certificate of the QUIC connection already set. " |
| 176 "Can't change the local certificate once it's active."; |
| 174 return false; | 177 return false; |
| 175 } | 178 } |
| 176 | 179 |
| 177 rtc::scoped_refptr<rtc::RTCCertificate> | 180 rtc::scoped_refptr<rtc::RTCCertificate> |
| 178 QuicTransportChannel::GetLocalCertificate() const { | 181 QuicTransportChannel::GetLocalCertificate() const { |
| 179 return local_certificate_; | 182 return local_certificate_; |
| 180 } | 183 } |
| 181 | 184 |
| 182 bool QuicTransportChannel::SetSslRole(rtc::SSLRole role) { | 185 bool QuicTransportChannel::SetSslRole(rtc::SSLRole role) { |
| 183 if (ssl_role_ && *ssl_role_ == role) { | 186 if (ssl_role_ && *ssl_role_ == role) { |
| 184 LOG_J(WARNING, this) << "Ignoring SSL Role identical to current role."; | 187 LOG_J(LS_WARNING, this) << "Ignoring SSL Role identical to current role."; |
| 185 return true; | 188 return true; |
| 186 } | 189 } |
| 187 if (quic_state_ != QUIC_TRANSPORT_CONNECTED) { | 190 if (quic_state_ != QUIC_TRANSPORT_CONNECTED) { |
| 188 ssl_role_ = rtc::Optional<rtc::SSLRole>(role); | 191 ssl_role_ = rtc::Optional<rtc::SSLRole>(role); |
| 189 return true; | 192 return true; |
| 190 } | 193 } |
| 191 LOG_J(ERROR, this) | 194 LOG_J(LS_ERROR, this) |
| 192 << "SSL Role can't be reversed after the session is setup."; | 195 << "SSL Role can't be reversed after the session is setup."; |
| 193 return false; | 196 return false; |
| 194 } | 197 } |
| 195 | 198 |
| 196 bool QuicTransportChannel::GetSslRole(rtc::SSLRole* role) const { | 199 bool QuicTransportChannel::GetSslRole(rtc::SSLRole* role) const { |
| 197 if (!ssl_role_) { | 200 if (!ssl_role_) { |
| 198 return false; | 201 return false; |
| 199 } | 202 } |
| 200 *role = *ssl_role_; | 203 *role = *ssl_role_; |
| 201 return true; | 204 return true; |
| 202 } | 205 } |
| 203 | 206 |
| 204 bool QuicTransportChannel::SetRemoteFingerprint(const std::string& digest_alg, | 207 bool QuicTransportChannel::SetRemoteFingerprint(const std::string& digest_alg, |
| 205 const uint8_t* digest, | 208 const uint8_t* digest, |
| 206 size_t digest_len) { | 209 size_t digest_len) { |
| 207 if (digest_alg.empty()) { | 210 if (digest_alg.empty()) { |
| 208 RTC_DCHECK(!digest_len); | 211 RTC_DCHECK(!digest_len); |
| 209 LOG_J(ERROR, this) << "Remote peer doesn't support digest algorithm."; | 212 LOG_J(LS_ERROR, this) << "Remote peer doesn't support digest algorithm."; |
| 210 return false; | 213 return false; |
| 211 } | 214 } |
| 212 std::string remote_fingerprint_value(reinterpret_cast<const char*>(digest), | 215 std::string remote_fingerprint_value(reinterpret_cast<const char*>(digest), |
| 213 digest_len); | 216 digest_len); |
| 214 // Once we have the local certificate, the same remote fingerprint can be set | 217 // Once we have the local certificate, the same remote fingerprint can be set |
| 215 // multiple times. This may happen during renegotiation. | 218 // multiple times. This may happen during renegotiation. |
| 216 if (remote_fingerprint_ && | 219 if (remote_fingerprint_ && |
| 217 remote_fingerprint_->value == remote_fingerprint_value && | 220 remote_fingerprint_->value == remote_fingerprint_value && |
| 218 remote_fingerprint_->algorithm == digest_alg) { | 221 remote_fingerprint_->algorithm == digest_alg) { |
| 219 LOG_J(INFO, this) << "Ignoring identical remote fingerprint and algorithm"; | 222 LOG_J(LS_INFO, this) |
| 223 << "Ignoring identical remote fingerprint and algorithm"; |
| 220 return true; | 224 return true; |
| 221 } | 225 } |
| 222 remote_fingerprint_ = rtc::Optional<RemoteFingerprint>(RemoteFingerprint()); | 226 remote_fingerprint_ = rtc::Optional<RemoteFingerprint>(RemoteFingerprint()); |
| 223 remote_fingerprint_->value = remote_fingerprint_value; | 227 remote_fingerprint_->value = remote_fingerprint_value; |
| 224 remote_fingerprint_->algorithm = digest_alg; | 228 remote_fingerprint_->algorithm = digest_alg; |
| 225 return true; | 229 return true; |
| 226 } | 230 } |
| 227 | 231 |
| 228 bool QuicTransportChannel::ExportKeyingMaterial(const std::string& label, | 232 bool QuicTransportChannel::ExportKeyingMaterial(const std::string& label, |
| 229 const uint8_t* context, | 233 const uint8_t* context, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 247 } | 251 } |
| 248 | 252 |
| 249 // Called from upper layers to send a media packet. | 253 // Called from upper layers to send a media packet. |
| 250 int QuicTransportChannel::SendPacket(const char* data, | 254 int QuicTransportChannel::SendPacket(const char* data, |
| 251 size_t size, | 255 size_t size, |
| 252 const rtc::PacketOptions& options, | 256 const rtc::PacketOptions& options, |
| 253 int flags) { | 257 int flags) { |
| 254 if ((flags & PF_SRTP_BYPASS) && IsRtpPacket(data, size)) { | 258 if ((flags & PF_SRTP_BYPASS) && IsRtpPacket(data, size)) { |
| 255 return channel_->SendPacket(data, size, options); | 259 return channel_->SendPacket(data, size, options); |
| 256 } | 260 } |
| 257 LOG(ERROR) << "Failed to send an invalid SRTP bypass packet using QUIC."; | 261 LOG(LS_ERROR) << "Failed to send an invalid SRTP bypass packet using QUIC."; |
| 258 return -1; | 262 return -1; |
| 259 } | 263 } |
| 260 | 264 |
| 261 // The state transition logic here is as follows: | 265 // The state transition logic here is as follows: |
| 262 // - Before the QUIC handshake is complete, the QUIC channel is unwritable. | 266 // - Before the QUIC handshake is complete, the QUIC channel is unwritable. |
| 263 // - When |channel_| goes writable we start the QUIC handshake. | 267 // - When |channel_| goes writable we start the QUIC handshake. |
| 264 // - Once the QUIC handshake completes, the state is that of the | 268 // - Once the QUIC handshake completes, the state is that of the |
| 265 // |channel_| again. | 269 // |channel_| again. |
| 266 void QuicTransportChannel::OnWritableState(TransportChannel* channel) { | 270 void QuicTransportChannel::OnWritableState(TransportChannel* channel) { |
| 267 ASSERT(rtc::Thread::Current() == worker_thread_); | 271 ASSERT(rtc::Thread::Current() == worker_thread_); |
| 268 ASSERT(channel == channel_); | 272 ASSERT(channel == channel_); |
| 269 LOG_J(VERBOSE, this) | 273 LOG_J(LS_VERBOSE, this) |
| 270 << "QuicTransportChannel: channel writable state changed to " | 274 << "QuicTransportChannel: channel writable state changed to " |
| 271 << channel_->writable(); | 275 << channel_->writable(); |
| 272 switch (quic_state_) { | 276 switch (quic_state_) { |
| 273 case QUIC_TRANSPORT_NEW: | 277 case QUIC_TRANSPORT_NEW: |
| 274 // Start the QUIC handshake when |channel_| is writable. | 278 // Start the QUIC handshake when |channel_| is writable. |
| 275 // This will fail if the SSL role or remote fingerprint are not set. | 279 // This will fail if the SSL role or remote fingerprint are not set. |
| 276 // Otherwise failure could result from network or QUIC errors. | 280 // Otherwise failure could result from network or QUIC errors. |
| 277 MaybeStartQuic(); | 281 MaybeStartQuic(); |
| 278 break; | 282 break; |
| 279 case QUIC_TRANSPORT_CONNECTED: | 283 case QUIC_TRANSPORT_CONNECTED: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 293 case QUIC_TRANSPORT_CLOSED: | 297 case QUIC_TRANSPORT_CLOSED: |
| 294 // TODO(mikescarlett): Allow the QUIC connection to be reset if it drops | 298 // TODO(mikescarlett): Allow the QUIC connection to be reset if it drops |
| 295 // due to a non-failure. | 299 // due to a non-failure. |
| 296 break; | 300 break; |
| 297 } | 301 } |
| 298 } | 302 } |
| 299 | 303 |
| 300 void QuicTransportChannel::OnReceivingState(TransportChannel* channel) { | 304 void QuicTransportChannel::OnReceivingState(TransportChannel* channel) { |
| 301 ASSERT(rtc::Thread::Current() == worker_thread_); | 305 ASSERT(rtc::Thread::Current() == worker_thread_); |
| 302 ASSERT(channel == channel_); | 306 ASSERT(channel == channel_); |
| 303 LOG_J(VERBOSE, this) | 307 LOG_J(LS_VERBOSE, this) |
| 304 << "QuicTransportChannel: channel receiving state changed to " | 308 << "QuicTransportChannel: channel receiving state changed to " |
| 305 << channel_->receiving(); | 309 << channel_->receiving(); |
| 306 if (quic_state_ == QUIC_TRANSPORT_CONNECTED) { | 310 if (quic_state_ == QUIC_TRANSPORT_CONNECTED) { |
| 307 // Note: SignalReceivingState fired by set_receiving. | 311 // Note: SignalReceivingState fired by set_receiving. |
| 308 set_receiving(channel_->receiving()); | 312 set_receiving(channel_->receiving()); |
| 309 } | 313 } |
| 310 } | 314 } |
| 311 | 315 |
| 312 void QuicTransportChannel::OnReadPacket(TransportChannel* channel, | 316 void QuicTransportChannel::OnReadPacket(TransportChannel* channel, |
| 313 const char* data, | 317 const char* data, |
| 314 size_t size, | 318 size_t size, |
| 315 const rtc::PacketTime& packet_time, | 319 const rtc::PacketTime& packet_time, |
| 316 int flags) { | 320 int flags) { |
| 317 ASSERT(rtc::Thread::Current() == worker_thread_); | 321 ASSERT(rtc::Thread::Current() == worker_thread_); |
| 318 ASSERT(channel == channel_); | 322 ASSERT(channel == channel_); |
| 319 ASSERT(flags == 0); | 323 ASSERT(flags == 0); |
| 320 | 324 |
| 321 switch (quic_state_) { | 325 switch (quic_state_) { |
| 322 case QUIC_TRANSPORT_NEW: | 326 case QUIC_TRANSPORT_NEW: |
| 323 // This would occur if other peer is ready to start QUIC but this peer | 327 // This would occur if other peer is ready to start QUIC but this peer |
| 324 // hasn't started QUIC. | 328 // hasn't started QUIC. |
| 325 LOG_J(INFO, this) << "Dropping packet received before QUIC started."; | 329 LOG_J(LS_INFO, this) << "Dropping packet received before QUIC started."; |
| 326 break; | 330 break; |
| 327 case QUIC_TRANSPORT_CONNECTING: | 331 case QUIC_TRANSPORT_CONNECTING: |
| 328 case QUIC_TRANSPORT_CONNECTED: | 332 case QUIC_TRANSPORT_CONNECTED: |
| 329 // We should only get QUIC or SRTP packets; STUN's already been demuxed. | 333 // We should only get QUIC or SRTP packets; STUN's already been demuxed. |
| 330 // Is this potentially a QUIC packet? | 334 // Is this potentially a QUIC packet? |
| 331 if (IsQuicPacket(data, size)) { | 335 if (IsQuicPacket(data, size)) { |
| 332 if (!HandleQuicPacket(data, size)) { | 336 if (!HandleQuicPacket(data, size)) { |
| 333 LOG_J(ERROR, this) << "Failed to handle QUIC packet."; | 337 LOG_J(LS_ERROR, this) << "Failed to handle QUIC packet."; |
| 334 return; | 338 return; |
| 335 } | 339 } |
| 336 } else { | 340 } else { |
| 337 // If this is an RTP packet, signal upwards as a bypass packet. | 341 // If this is an RTP packet, signal upwards as a bypass packet. |
| 338 if (!IsRtpPacket(data, size)) { | 342 if (!IsRtpPacket(data, size)) { |
| 339 LOG_J(ERROR, this) << "Received unexpected non-QUIC, non-RTP packet."; | 343 LOG_J(LS_ERROR, this) |
| 344 << "Received unexpected non-QUIC, non-RTP packet."; |
| 340 return; | 345 return; |
| 341 } | 346 } |
| 342 SignalReadPacket(this, data, size, packet_time, PF_SRTP_BYPASS); | 347 SignalReadPacket(this, data, size, packet_time, PF_SRTP_BYPASS); |
| 343 } | 348 } |
| 344 break; | 349 break; |
| 345 case QUIC_TRANSPORT_CLOSED: | 350 case QUIC_TRANSPORT_CLOSED: |
| 346 // This shouldn't be happening. Drop the packet. | 351 // This shouldn't be happening. Drop the packet. |
| 347 break; | 352 break; |
| 348 } | 353 } |
| 349 } | 354 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 SignalRouteChange(this, candidate); | 387 SignalRouteChange(this, candidate); |
| 383 } | 388 } |
| 384 | 389 |
| 385 void QuicTransportChannel::OnConnectionRemoved(TransportChannelImpl* channel) { | 390 void QuicTransportChannel::OnConnectionRemoved(TransportChannelImpl* channel) { |
| 386 ASSERT(channel == channel_); | 391 ASSERT(channel == channel_); |
| 387 SignalConnectionRemoved(this); | 392 SignalConnectionRemoved(this); |
| 388 } | 393 } |
| 389 | 394 |
| 390 bool QuicTransportChannel::MaybeStartQuic() { | 395 bool QuicTransportChannel::MaybeStartQuic() { |
| 391 if (!channel_->writable()) { | 396 if (!channel_->writable()) { |
| 392 LOG_J(ERROR, this) << "Couldn't start QUIC handshake."; | 397 LOG_J(LS_ERROR, this) << "Couldn't start QUIC handshake."; |
| 393 return false; | 398 return false; |
| 394 } | 399 } |
| 395 if (!CreateQuicSession() || !StartQuicHandshake()) { | 400 if (!CreateQuicSession() || !StartQuicHandshake()) { |
| 396 LOG_J(WARNING, this) << "Underlying channel is writable but cannot start " | 401 LOG_J(LS_WARNING, this) |
| 397 "the QUIC handshake."; | 402 << "Underlying channel is writable but cannot start " |
| 403 "the QUIC handshake."; |
| 398 return false; | 404 return false; |
| 399 } | 405 } |
| 400 // Verify connection is not closed due to QUIC bug or network failure. | 406 // Verify connection is not closed due to QUIC bug or network failure. |
| 401 // A closed connection should not happen since |channel_| is writable. | 407 // A closed connection should not happen since |channel_| is writable. |
| 402 if (!quic_->connection()->connected()) { | 408 if (!quic_->connection()->connected()) { |
| 403 LOG_J(ERROR, this) << "QUIC connection should not be closed if underlying " | 409 LOG_J(LS_ERROR, this) |
| 404 "channel is writable."; | 410 << "QUIC connection should not be closed if underlying " |
| 411 "channel is writable."; |
| 405 return false; | 412 return false; |
| 406 } | 413 } |
| 407 // Indicate that |quic_| is ready to receive QUIC packets. | 414 // Indicate that |quic_| is ready to receive QUIC packets. |
| 408 set_quic_state(QUIC_TRANSPORT_CONNECTING); | 415 set_quic_state(QUIC_TRANSPORT_CONNECTING); |
| 409 return true; | 416 return true; |
| 410 } | 417 } |
| 411 | 418 |
| 412 bool QuicTransportChannel::CreateQuicSession() { | 419 bool QuicTransportChannel::CreateQuicSession() { |
| 413 if (!ssl_role_ || !remote_fingerprint_) { | 420 if (!ssl_role_ || !remote_fingerprint_) { |
| 414 return false; | 421 return false; |
| 415 } | 422 } |
| 416 net::Perspective perspective = (*ssl_role_ == rtc::SSL_CLIENT) | 423 net::Perspective perspective = (*ssl_role_ == rtc::SSL_CLIENT) |
| 417 ? net::Perspective::IS_CLIENT | 424 ? net::Perspective::IS_CLIENT |
| 418 : net::Perspective::IS_SERVER; | 425 : net::Perspective::IS_SERVER; |
| 419 bool owns_writer = false; | 426 bool owns_writer = false; |
| 420 scoped_ptr<net::QuicConnection> connection(new net::QuicConnection( | 427 rtc::scoped_ptr<net::QuicConnection> connection(new net::QuicConnection( |
| 421 kConnectionId, kConnectionIpEndpoint, &helper_, this, owns_writer, | 428 kConnectionId, kConnectionIpEndpoint, &helper_, this, owns_writer, |
| 422 perspective, net::QuicSupportedVersions())); | 429 perspective, net::QuicSupportedVersions())); |
| 423 quic_.reset(new QuicSession(std::move(connection), config_)); | 430 quic_.reset(new QuicSession(std::move(connection), config_)); |
| 424 quic_->SignalHandshakeComplete.connect( | 431 quic_->SignalHandshakeComplete.connect( |
| 425 this, &QuicTransportChannel::OnHandshakeComplete); | 432 this, &QuicTransportChannel::OnHandshakeComplete); |
| 426 quic_->SignalConnectionClosed.connect( | 433 quic_->SignalConnectionClosed.connect( |
| 427 this, &QuicTransportChannel::OnConnectionClosed); | 434 this, &QuicTransportChannel::OnConnectionClosed); |
| 428 return true; | 435 return true; |
| 429 } | 436 } |
| 430 | 437 |
| 431 bool QuicTransportChannel::StartQuicHandshake() { | 438 bool QuicTransportChannel::StartQuicHandshake() { |
| 432 if (*ssl_role_ == rtc::SSL_CLIENT) { | 439 if (*ssl_role_ == rtc::SSL_CLIENT) { |
| 433 // Unique identifier for remote peer. | 440 // Unique identifier for remote peer. |
| 434 net::QuicServerId server_id(remote_fingerprint_->value, kQuicServerPort); | 441 net::QuicServerId server_id(remote_fingerprint_->value, kQuicServerPort); |
| 435 // Perform authentication of remote peer; owned by QuicCryptoClientConfig. | 442 // Perform authentication of remote peer; owned by QuicCryptoClientConfig. |
| 436 // TODO(mikescarlett): Actually verify proof. | 443 // TODO(mikescarlett): Actually verify proof. |
| 437 net::ProofVerifier* proof_verifier = new InsecureProofVerifier(); | 444 net::ProofVerifier* proof_verifier = new InsecureProofVerifier(); |
| 438 quic_crypto_client_config_.reset( | 445 quic_crypto_client_config_.reset( |
| 439 new net::QuicCryptoClientConfig(proof_verifier)); | 446 new net::QuicCryptoClientConfig(proof_verifier)); |
| 440 net::QuicCryptoClientStream* crypto_stream = | 447 net::QuicCryptoClientStream* crypto_stream = |
| 441 new net::QuicCryptoClientStream(server_id, quic_.get(), | 448 new net::QuicCryptoClientStream(server_id, quic_.get(), |
| 442 new net::ProofVerifyContext(), | 449 new net::ProofVerifyContext(), |
| 443 quic_crypto_client_config_.get(), this); | 450 quic_crypto_client_config_.get(), this); |
| 444 quic_->StartClientHandshake(crypto_stream); | 451 quic_->StartClientHandshake(crypto_stream); |
| 445 LOG_J(INFO, this) << "QuicTransportChannel: Started client handshake."; | 452 LOG_J(LS_INFO, this) << "QuicTransportChannel: Started client handshake."; |
| 446 } else { | 453 } else { |
| 447 RTC_DCHECK_EQ(*ssl_role_, rtc::SSL_SERVER); | 454 RTC_DCHECK_EQ(*ssl_role_, rtc::SSL_SERVER); |
| 448 // Provide credentials to remote peer; owned by QuicCryptoServerConfig. | 455 // Provide credentials to remote peer; owned by QuicCryptoServerConfig. |
| 449 // TODO(mikescarlett): Actually provide credentials. | 456 // TODO(mikescarlett): Actually provide credentials. |
| 450 net::ProofSource* proof_source = new DummyProofSource(); | 457 net::ProofSource* proof_source = new DummyProofSource(); |
| 451 // Input keying material to HKDF, per http://tools.ietf.org/html/rfc5869. | 458 // Input keying material to HKDF, per http://tools.ietf.org/html/rfc5869. |
| 452 // This is pseudorandom so that HKDF-Extract outputs a pseudorandom key, | 459 // This is pseudorandom so that HKDF-Extract outputs a pseudorandom key, |
| 453 // since QuicCryptoServerConfig does not use a salt value. | 460 // since QuicCryptoServerConfig does not use a salt value. |
| 454 std::string source_address_token_secret; | 461 std::string source_address_token_secret; |
| 455 if (!rtc::CreateRandomString(kInputKeyingMaterialLength, | 462 if (!rtc::CreateRandomString(kInputKeyingMaterialLength, |
| 456 &source_address_token_secret)) { | 463 &source_address_token_secret)) { |
| 457 LOG_J(ERROR, this) << "Error generating input keying material for HKDF."; | 464 LOG_J(LS_ERROR, this) |
| 465 << "Error generating input keying material for HKDF."; |
| 458 return false; | 466 return false; |
| 459 } | 467 } |
| 460 quic_crypto_server_config_.reset(new net::QuicCryptoServerConfig( | 468 quic_crypto_server_config_.reset(new net::QuicCryptoServerConfig( |
| 461 source_address_token_secret, helper_.GetRandomGenerator(), | 469 source_address_token_secret, helper_.GetRandomGenerator(), |
| 462 proof_source)); | 470 proof_source)); |
| 463 // Provide server with serialized config string to prove ownership. | 471 // Provide server with serialized config string to prove ownership. |
| 464 net::QuicCryptoServerConfig::ConfigOptions options; | 472 net::QuicCryptoServerConfig::ConfigOptions options; |
| 465 quic_crypto_server_config_->AddDefaultConfig(helper_.GetRandomGenerator(), | 473 quic_crypto_server_config_->AddDefaultConfig(helper_.GetRandomGenerator(), |
| 466 helper_.GetClock(), options); | 474 helper_.GetClock(), options); |
| 467 net::QuicCryptoServerStream* crypto_stream = | 475 net::QuicCryptoServerStream* crypto_stream = |
| 468 new net::QuicCryptoServerStream(quic_crypto_server_config_.get(), | 476 new net::QuicCryptoServerStream(quic_crypto_server_config_.get(), |
| 469 quic_.get()); | 477 quic_.get()); |
| 470 quic_->StartServerHandshake(crypto_stream); | 478 quic_->StartServerHandshake(crypto_stream); |
| 471 LOG_J(INFO, this) << "QuicTransportChannel: Started server handshake."; | 479 LOG_J(LS_INFO, this) << "QuicTransportChannel: Started server handshake."; |
| 472 } | 480 } |
| 473 return true; | 481 return true; |
| 474 } | 482 } |
| 475 | 483 |
| 476 bool QuicTransportChannel::HandleQuicPacket(const char* data, size_t size) { | 484 bool QuicTransportChannel::HandleQuicPacket(const char* data, size_t size) { |
| 477 ASSERT(rtc::Thread::Current() == worker_thread_); | 485 ASSERT(rtc::Thread::Current() == worker_thread_); |
| 478 return quic_->OnReadPacket(data, size); | 486 return quic_->OnReadPacket(data, size); |
| 479 } | 487 } |
| 480 | 488 |
| 481 net::WriteResult QuicTransportChannel::WritePacket( | 489 net::WriteResult QuicTransportChannel::WritePacket( |
| 482 const char* buffer, | 490 const char* buffer, |
| 483 size_t buf_len, | 491 size_t buf_len, |
| 484 const net::IPAddressNumber& self_address, | 492 const net::IPAddress& self_address, |
| 485 const net::IPEndPoint& peer_address) { | 493 const net::IPEndPoint& peer_address, |
| 494 net::PerPacketOptions* options) { |
| 486 // QUIC should never call this if IsWriteBlocked, but just in case... | 495 // QUIC should never call this if IsWriteBlocked, but just in case... |
| 487 if (IsWriteBlocked()) { | 496 if (IsWriteBlocked()) { |
| 488 return net::WriteResult(net::WRITE_STATUS_BLOCKED, EWOULDBLOCK); | 497 return net::WriteResult(net::WRITE_STATUS_BLOCKED, EWOULDBLOCK); |
| 489 } | 498 } |
| 490 // TODO(mikescarlett): Figure out how to tell QUIC "I dropped your packet, but | 499 // TODO(mikescarlett): Figure out how to tell QUIC "I dropped your packet, but |
| 491 // don't block" without the QUIC connection tearing itself down. | 500 // don't block" without the QUIC connection tearing itself down. |
| 492 int sent = channel_->SendPacket(buffer, buf_len, rtc::PacketOptions()); | 501 int sent = channel_->SendPacket(buffer, buf_len, rtc::PacketOptions()); |
| 493 int bytes_written = sent > 0 ? sent : 0; | 502 int bytes_written = sent > 0 ? sent : 0; |
| 494 return net::WriteResult(net::WRITE_STATUS_OK, bytes_written); | 503 return net::WriteResult(net::WRITE_STATUS_OK, bytes_written); |
| 495 } | 504 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 507 set_writable(true); | 516 set_writable(true); |
| 508 // OnReceivingState might have been called before the QUIC channel was | 517 // OnReceivingState might have been called before the QUIC channel was |
| 509 // connected, in which case the QUIC channel is now receiving. | 518 // connected, in which case the QUIC channel is now receiving. |
| 510 if (channel_->receiving()) { | 519 if (channel_->receiving()) { |
| 511 set_receiving(true); | 520 set_receiving(true); |
| 512 } | 521 } |
| 513 } | 522 } |
| 514 | 523 |
| 515 void QuicTransportChannel::OnConnectionClosed(net::QuicErrorCode error, | 524 void QuicTransportChannel::OnConnectionClosed(net::QuicErrorCode error, |
| 516 bool from_peer) { | 525 bool from_peer) { |
| 517 LOG_J(INFO, this) << "Connection closed by " << (from_peer ? "other" : "this") | 526 LOG_J(LS_INFO, this) << "Connection closed by " |
| 518 << " peer " | 527 << (from_peer ? "other" : "this") << " peer " |
| 519 << "with QUIC error " << error; | 528 << "with QUIC error " << error; |
| 520 // TODO(mikescarlett): Allow the QUIC session to be reset when the connection | 529 // TODO(mikescarlett): Allow the QUIC session to be reset when the connection |
| 521 // does not close due to failure. | 530 // does not close due to failure. |
| 522 set_quic_state(QUIC_TRANSPORT_CLOSED); | 531 set_quic_state(QUIC_TRANSPORT_CLOSED); |
| 523 set_writable(false); | 532 set_writable(false); |
| 524 } | 533 } |
| 525 | 534 |
| 526 void QuicTransportChannel::OnProofValid( | 535 void QuicTransportChannel::OnProofValid( |
| 527 const net::QuicCryptoClientConfig::CachedState& cached) { | 536 const net::QuicCryptoClientConfig::CachedState& cached) { |
| 528 LOG_J(INFO, this) << "Cached proof marked valid"; | 537 LOG_J(LS_INFO, this) << "Cached proof marked valid"; |
| 529 } | 538 } |
| 530 | 539 |
| 531 void QuicTransportChannel::OnProofVerifyDetailsAvailable( | 540 void QuicTransportChannel::OnProofVerifyDetailsAvailable( |
| 532 const net::ProofVerifyDetails& verify_details) { | 541 const net::ProofVerifyDetails& verify_details) { |
| 533 LOG_J(INFO, this) << "Proof verify details available from" | 542 LOG_J(LS_INFO, this) << "Proof verify details available from" |
| 534 << " QuicCryptoClientStream"; | 543 << " QuicCryptoClientStream"; |
| 535 } | 544 } |
| 536 | 545 |
| 537 bool QuicTransportChannel::HasDataToWrite() const { | 546 bool QuicTransportChannel::HasDataToWrite() const { |
| 538 return quic_ && quic_->HasDataToWrite(); | 547 return quic_ && quic_->HasDataToWrite(); |
| 539 } | 548 } |
| 540 | 549 |
| 541 void QuicTransportChannel::OnCanWrite() { | 550 void QuicTransportChannel::OnCanWrite() { |
| 542 RTC_DCHECK(quic_ != nullptr); | 551 RTC_DCHECK(quic_ != nullptr); |
| 543 quic_->connection()->OnCanWrite(); | 552 quic_->connection()->OnCanWrite(); |
| 544 } | 553 } |
| 545 | 554 |
| 546 void QuicTransportChannel::set_quic_state(QuicTransportState state) { | 555 void QuicTransportChannel::set_quic_state(QuicTransportState state) { |
| 547 LOG_J(VERBOSE, this) << "set_quic_state from:" << quic_state_ << " to " | 556 LOG_J(LS_VERBOSE, this) << "set_quic_state from:" << quic_state_ << " to " |
| 548 << state; | 557 << state; |
| 549 quic_state_ = state; | 558 quic_state_ = state; |
| 550 } | 559 } |
| 551 | 560 |
| 552 } // namespace cricket | 561 } // namespace cricket |
| OLD | NEW |