| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/quic/test_tools/mock_crypto_client_stream.h" | |
| 6 | |
| 7 #include "net/quic/crypto/quic_decrypter.h" | |
| 8 #include "net/quic/quic_client_session_base.h" | |
| 9 #include "net/quic/quic_server_id.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 using std::string; | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 MockCryptoClientStream::MockCryptoClientStream( | |
| 17 const QuicServerId& server_id, | |
| 18 QuicClientSessionBase* session, | |
| 19 ProofVerifyContext* verify_context, | |
| 20 QuicCryptoClientConfig* crypto_config, | |
| 21 HandshakeMode handshake_mode, | |
| 22 const ProofVerifyDetails* proof_verify_details) | |
| 23 : QuicCryptoClientStream(server_id, session, verify_context, | |
| 24 crypto_config), | |
| 25 handshake_mode_(handshake_mode), | |
| 26 proof_verify_details_(proof_verify_details) { | |
| 27 } | |
| 28 | |
| 29 MockCryptoClientStream::~MockCryptoClientStream() { | |
| 30 } | |
| 31 | |
| 32 void MockCryptoClientStream::OnHandshakeMessage( | |
| 33 const CryptoHandshakeMessage& message) { | |
| 34 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE); | |
| 35 } | |
| 36 | |
| 37 void MockCryptoClientStream::CryptoConnect() { | |
| 38 switch (handshake_mode_) { | |
| 39 case ZERO_RTT: { | |
| 40 encryption_established_ = true; | |
| 41 handshake_confirmed_ = false; | |
| 42 session()->connection()->SetDecrypter(QuicDecrypter::Create(kNULL), | |
| 43 ENCRYPTION_INITIAL); | |
| 44 session()->OnCryptoHandshakeEvent( | |
| 45 QuicSession::ENCRYPTION_FIRST_ESTABLISHED); | |
| 46 break; | |
| 47 } | |
| 48 | |
| 49 case CONFIRM_HANDSHAKE: { | |
| 50 encryption_established_ = true; | |
| 51 handshake_confirmed_ = true; | |
| 52 crypto_negotiated_params_.key_exchange = kC255; | |
| 53 crypto_negotiated_params_.aead = kAESG; | |
| 54 if (proof_verify_details_) { | |
| 55 client_session()->OnProofVerifyDetailsAvailable(*proof_verify_details_); | |
| 56 } | |
| 57 SetConfigNegotiated(); | |
| 58 session()->connection()->SetDecrypter(QuicDecrypter::Create(kNULL), | |
| 59 ENCRYPTION_FORWARD_SECURE); | |
| 60 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED); | |
| 61 break; | |
| 62 } | |
| 63 | |
| 64 case COLD_START: { | |
| 65 handshake_confirmed_ = false; | |
| 66 encryption_established_ = false; | |
| 67 break; | |
| 68 } | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 void MockCryptoClientStream::SendOnCryptoHandshakeEvent( | |
| 73 QuicSession::CryptoHandshakeEvent event) { | |
| 74 encryption_established_ = true; | |
| 75 if (event == QuicSession::HANDSHAKE_CONFIRMED) { | |
| 76 handshake_confirmed_ = true; | |
| 77 SetConfigNegotiated(); | |
| 78 } | |
| 79 session()->OnCryptoHandshakeEvent(event); | |
| 80 } | |
| 81 | |
| 82 void MockCryptoClientStream::SetConfigNegotiated() { | |
| 83 ASSERT_FALSE(session()->config()->negotiated()); | |
| 84 QuicTagVector cgst; | |
| 85 // TODO(rtenneti): Enable the following code after BBR code is checked in. | |
| 86 #if 0 | |
| 87 cgst.push_back(kTBBR); | |
| 88 #endif | |
| 89 cgst.push_back(kQBIC); | |
| 90 QuicConfig config; | |
| 91 config.SetIdleConnectionStateLifetime( | |
| 92 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs), | |
| 93 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs)); | |
| 94 config.SetMaxStreamsPerConnection(kDefaultMaxStreamsPerConnection / 2, | |
| 95 kDefaultMaxStreamsPerConnection / 2); | |
| 96 config.SetBytesForConnectionIdToSend(PACKET_8BYTE_CONNECTION_ID); | |
| 97 | |
| 98 CryptoHandshakeMessage msg; | |
| 99 config.ToHandshakeMessage(&msg); | |
| 100 string error_details; | |
| 101 const QuicErrorCode error = | |
| 102 session()->config()->ProcessPeerHello(msg, CLIENT, &error_details); | |
| 103 ASSERT_EQ(QUIC_NO_ERROR, error); | |
| 104 ASSERT_TRUE(session()->config()->negotiated()); | |
| 105 session()->OnConfigNegotiated(); | |
| 106 } | |
| 107 | |
| 108 QuicClientSessionBase* MockCryptoClientStream::client_session() { | |
| 109 return reinterpret_cast<QuicClientSessionBase*>(session()); | |
| 110 } | |
| 111 | |
| 112 } // namespace net | |
| OLD | NEW |