| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "webrtc/p2p/quic/reliablequicstream.h" | 29 #include "webrtc/p2p/quic/reliablequicstream.h" |
| 30 | 30 |
| 31 using net::IPAddress; | 31 using net::IPAddress; |
| 32 using net::IPEndPoint; | 32 using net::IPEndPoint; |
| 33 using net::PerPacketOptions; | 33 using net::PerPacketOptions; |
| 34 using net::Perspective; | 34 using net::Perspective; |
| 35 using net::ProofVerifyContext; | 35 using net::ProofVerifyContext; |
| 36 using net::ProofVerifyDetails; | 36 using net::ProofVerifyDetails; |
| 37 using net::QuicByteCount; | 37 using net::QuicByteCount; |
| 38 using net::QuicClock; | 38 using net::QuicClock; |
| 39 using net::QuicCompressedCertsCache; |
| 39 using net::QuicConfig; | 40 using net::QuicConfig; |
| 40 using net::QuicConnection; | 41 using net::QuicConnection; |
| 41 using net::QuicCryptoClientConfig; | 42 using net::QuicCryptoClientConfig; |
| 42 using net::QuicCryptoServerConfig; | 43 using net::QuicCryptoServerConfig; |
| 43 using net::QuicCryptoClientStream; | 44 using net::QuicCryptoClientStream; |
| 44 using net::QuicCryptoServerStream; | 45 using net::QuicCryptoServerStream; |
| 45 using net::QuicCryptoStream; | 46 using net::QuicCryptoStream; |
| 46 using net::QuicErrorCode; | 47 using net::QuicErrorCode; |
| 47 using net::QuicPacketWriter; | 48 using net::QuicPacketWriter; |
| 48 using net::QuicRandom; | 49 using net::QuicRandom; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 105 |
| 105 // Used by QuicCryptoClientConfig to verify server credentials, returning a | 106 // Used by QuicCryptoClientConfig to verify server credentials, returning a |
| 106 // canned response of QUIC_SUCCESS if |success| is true. | 107 // canned response of QUIC_SUCCESS if |success| is true. |
| 107 class FakeProofVerifier : public net::ProofVerifier { | 108 class FakeProofVerifier : public net::ProofVerifier { |
| 108 public: | 109 public: |
| 109 explicit FakeProofVerifier(bool success) : success_(success) {} | 110 explicit FakeProofVerifier(bool success) : success_(success) {} |
| 110 | 111 |
| 111 // ProofVerifier override | 112 // ProofVerifier override |
| 112 net::QuicAsyncStatus VerifyProof( | 113 net::QuicAsyncStatus VerifyProof( |
| 113 const std::string& hostname, | 114 const std::string& hostname, |
| 115 const uint16_t port, |
| 114 const std::string& server_config, | 116 const std::string& server_config, |
| 117 net::QuicVersion quic_version, |
| 118 base::StringPiece chlo_hash, |
| 115 const std::vector<std::string>& certs, | 119 const std::vector<std::string>& certs, |
| 116 const std::string& cert_sct, | 120 const std::string& cert_sct, |
| 117 const std::string& signature, | 121 const std::string& signature, |
| 118 const net::ProofVerifyContext* verify_context, | 122 const ProofVerifyContext* context, |
| 119 std::string* error_details, | 123 std::string* error_details, |
| 120 scoped_ptr<net::ProofVerifyDetails>* verify_details, | 124 std::unique_ptr<ProofVerifyDetails>* details, |
| 121 net::ProofVerifierCallback* callback) override { | 125 net::ProofVerifierCallback* callback) override { |
| 122 return success_ ? net::QUIC_SUCCESS : net::QUIC_FAILURE; | 126 return success_ ? net::QUIC_SUCCESS : net::QUIC_FAILURE; |
| 123 } | 127 } |
| 124 | 128 |
| 125 private: | 129 private: |
| 126 // Whether or not proof verification succeeds. | 130 // Whether or not proof verification succeeds. |
| 127 bool success_; | 131 bool success_; |
| 128 }; | 132 }; |
| 129 | 133 |
| 130 // Writes QUIC packets to a fake transport channel that simulates a network. | 134 // Writes QUIC packets to a fake transport channel that simulates a network. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // Stores data received by peer once it is sent from the other peer. | 227 // Stores data received by peer once it is sent from the other peer. |
| 224 std::string last_received_data_; | 228 std::string last_received_data_; |
| 225 // Handles incoming streams from sender. | 229 // Handles incoming streams from sender. |
| 226 ReliableQuicStream* last_incoming_stream_ = nullptr; | 230 ReliableQuicStream* last_incoming_stream_ = nullptr; |
| 227 }; | 231 }; |
| 228 | 232 |
| 229 // Simulates data transfer between two peers using QUIC. | 233 // Simulates data transfer between two peers using QUIC. |
| 230 class QuicSessionTest : public ::testing::Test, | 234 class QuicSessionTest : public ::testing::Test, |
| 231 public QuicCryptoClientStream::ProofHandler { | 235 public QuicCryptoClientStream::ProofHandler { |
| 232 public: | 236 public: |
| 233 QuicSessionTest() : quic_helper_(rtc::Thread::Current()) {} | 237 QuicSessionTest() |
| 238 : quic_helper_(rtc::Thread::Current()), |
| 239 quic_compressed_certs_cache_( |
| 240 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) {} |
| 234 | 241 |
| 235 // Instantiates |client_peer_| and |server_peer_|. | 242 // Instantiates |client_peer_| and |server_peer_|. |
| 236 void CreateClientAndServerSessions(); | 243 void CreateClientAndServerSessions(); |
| 237 | 244 |
| 238 rtc::scoped_ptr<QuicSessionForTest> CreateSession( | 245 rtc::scoped_ptr<QuicSessionForTest> CreateSession( |
| 239 rtc::scoped_ptr<FakeTransportChannel> channel, | 246 rtc::scoped_ptr<FakeTransportChannel> channel, |
| 240 Perspective perspective); | 247 Perspective perspective); |
| 241 | 248 |
| 242 QuicCryptoClientStream* CreateCryptoClientStream(QuicSessionForTest* session, | 249 QuicCryptoClientStream* CreateCryptoClientStream(QuicSessionForTest* session, |
| 243 bool handshake_success); | 250 bool handshake_success); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 260 // QuicCryptoClientStream::ProofHelper overrides. | 267 // QuicCryptoClientStream::ProofHelper overrides. |
| 261 void OnProofValid( | 268 void OnProofValid( |
| 262 const QuicCryptoClientConfig::CachedState& cached) override {} | 269 const QuicCryptoClientConfig::CachedState& cached) override {} |
| 263 void OnProofVerifyDetailsAvailable( | 270 void OnProofVerifyDetailsAvailable( |
| 264 const ProofVerifyDetails& verify_details) override {} | 271 const ProofVerifyDetails& verify_details) override {} |
| 265 | 272 |
| 266 protected: | 273 protected: |
| 267 QuicConnectionHelper quic_helper_; | 274 QuicConnectionHelper quic_helper_; |
| 268 QuicConfig config_; | 275 QuicConfig config_; |
| 269 QuicClock clock_; | 276 QuicClock clock_; |
| 277 QuicCompressedCertsCache quic_compressed_certs_cache_; |
| 270 | 278 |
| 271 rtc::scoped_ptr<QuicSessionForTest> client_peer_; | 279 rtc::scoped_ptr<QuicSessionForTest> client_peer_; |
| 272 rtc::scoped_ptr<QuicSessionForTest> server_peer_; | 280 rtc::scoped_ptr<QuicSessionForTest> server_peer_; |
| 273 }; | 281 }; |
| 274 | 282 |
| 275 // Initializes "client peer" who begins crypto handshake and "server peer" who | 283 // Initializes "client peer" who begins crypto handshake and "server peer" who |
| 276 // establishes encryption with client. | 284 // establishes encryption with client. |
| 277 void QuicSessionTest::CreateClientAndServerSessions() { | 285 void QuicSessionTest::CreateClientAndServerSessions() { |
| 278 rtc::scoped_ptr<FakeTransportChannel> channel1( | 286 rtc::scoped_ptr<FakeTransportChannel> channel1( |
| 279 new FakeTransportChannel("channel1", 0)); | 287 new FakeTransportChannel("channel1", 0)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 QuicSessionForTest* session, | 324 QuicSessionForTest* session, |
| 317 bool handshake_success) { | 325 bool handshake_success) { |
| 318 QuicCryptoServerConfig* server_config = | 326 QuicCryptoServerConfig* server_config = |
| 319 new QuicCryptoServerConfig("TESTING", QuicRandom::GetInstance(), | 327 new QuicCryptoServerConfig("TESTING", QuicRandom::GetInstance(), |
| 320 new FakeProofSource(handshake_success)); | 328 new FakeProofSource(handshake_success)); |
| 321 // Provide server with serialized config string to prove ownership. | 329 // Provide server with serialized config string to prove ownership. |
| 322 QuicCryptoServerConfig::ConfigOptions options; | 330 QuicCryptoServerConfig::ConfigOptions options; |
| 323 QuicServerConfigProtobuf* primary_config = server_config->GenerateConfig( | 331 QuicServerConfigProtobuf* primary_config = server_config->GenerateConfig( |
| 324 QuicRandom::GetInstance(), &clock_, options); | 332 QuicRandom::GetInstance(), &clock_, options); |
| 325 server_config->AddConfig(primary_config, clock_.WallNow()); | 333 server_config->AddConfig(primary_config, clock_.WallNow()); |
| 326 return new QuicCryptoServerStream(server_config, session); | 334 bool use_stateless_rejects_if_peer_supported = false; |
| 335 return new QuicCryptoServerStream( |
| 336 server_config, &quic_compressed_certs_cache_, |
| 337 use_stateless_rejects_if_peer_supported, session); |
| 327 } | 338 } |
| 328 | 339 |
| 329 rtc::scoped_ptr<QuicConnection> QuicSessionTest::CreateConnection( | 340 rtc::scoped_ptr<QuicConnection> QuicSessionTest::CreateConnection( |
| 330 FakeTransportChannel* channel, | 341 FakeTransportChannel* channel, |
| 331 Perspective perspective) { | 342 Perspective perspective) { |
| 332 FakeQuicPacketWriter* writer = new FakeQuicPacketWriter(channel); | 343 FakeQuicPacketWriter* writer = new FakeQuicPacketWriter(channel); |
| 333 | 344 |
| 334 IPAddress ip(0, 0, 0, 0); | 345 IPAddress ip(0, 0, 0, 0); |
| 335 bool owns_writer = true; | 346 bool owns_writer = true; |
| 336 | 347 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 350 void QuicSessionTest::TestStreamConnection(QuicSessionForTest* from_session, | 361 void QuicSessionTest::TestStreamConnection(QuicSessionForTest* from_session, |
| 351 QuicSessionForTest* to_session) { | 362 QuicSessionForTest* to_session) { |
| 352 // Wait for crypto handshake to finish then check if encryption established. | 363 // Wait for crypto handshake to finish then check if encryption established. |
| 353 ASSERT_TRUE_WAIT(from_session->IsCryptoHandshakeConfirmed() && | 364 ASSERT_TRUE_WAIT(from_session->IsCryptoHandshakeConfirmed() && |
| 354 to_session->IsCryptoHandshakeConfirmed(), | 365 to_session->IsCryptoHandshakeConfirmed(), |
| 355 kTimeoutMs); | 366 kTimeoutMs); |
| 356 | 367 |
| 357 ASSERT_TRUE(from_session->IsEncryptionEstablished()); | 368 ASSERT_TRUE(from_session->IsEncryptionEstablished()); |
| 358 ASSERT_TRUE(to_session->IsEncryptionEstablished()); | 369 ASSERT_TRUE(to_session->IsEncryptionEstablished()); |
| 359 | 370 |
| 360 string from_key; | 371 std::string from_key; |
| 361 string to_key; | 372 std::string to_key; |
| 362 | 373 |
| 363 bool from_success = from_session->ExportKeyingMaterial( | 374 bool from_success = from_session->ExportKeyingMaterial( |
| 364 kExporterLabel, kExporterContext, kExporterContextLen, &from_key); | 375 kExporterLabel, kExporterContext, kExporterContextLen, &from_key); |
| 365 ASSERT_TRUE(from_success); | 376 ASSERT_TRUE(from_success); |
| 366 bool to_success = to_session->ExportKeyingMaterial( | 377 bool to_success = to_session->ExportKeyingMaterial( |
| 367 kExporterLabel, kExporterContext, kExporterContextLen, &to_key); | 378 kExporterLabel, kExporterContext, kExporterContextLen, &to_key); |
| 368 ASSERT_TRUE(to_success); | 379 ASSERT_TRUE(to_success); |
| 369 | 380 |
| 370 EXPECT_EQ(from_key.size(), kExporterContextLen); | 381 EXPECT_EQ(from_key.size(), kExporterContextLen); |
| 371 EXPECT_EQ(from_key, to_key); | 382 EXPECT_EQ(from_key, to_key); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 StartHandshake(true, true); | 468 StartHandshake(true, true); |
| 458 ASSERT_TRUE_WAIT(client_peer_->IsCryptoHandshakeConfirmed() && | 469 ASSERT_TRUE_WAIT(client_peer_->IsCryptoHandshakeConfirmed() && |
| 459 server_peer_->IsCryptoHandshakeConfirmed(), | 470 server_peer_->IsCryptoHandshakeConfirmed(), |
| 460 kTimeoutMs); | 471 kTimeoutMs); |
| 461 ReliableQuicStream* stream = client_peer_->CreateOutgoingDynamicStream(5); | 472 ReliableQuicStream* stream = client_peer_->CreateOutgoingDynamicStream(5); |
| 462 ASSERT_NE(nullptr, stream); | 473 ASSERT_NE(nullptr, stream); |
| 463 EXPECT_FALSE(client_peer_->IsClosedStream(stream->id())); | 474 EXPECT_FALSE(client_peer_->IsClosedStream(stream->id())); |
| 464 stream->Close(); | 475 stream->Close(); |
| 465 EXPECT_TRUE(client_peer_->IsClosedStream(stream->id())); | 476 EXPECT_TRUE(client_peer_->IsClosedStream(stream->id())); |
| 466 } | 477 } |
| OLD | NEW |