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