| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/test_tools/crypto_test_utils.h" | 5 #include "net/quic/test_tools/crypto_test_utils.h" |
| 6 | 6 |
| 7 #include "base/strings/string_piece.h" | 7 #include "base/strings/string_piece.h" |
| 8 #include "net/quic/crypto/crypto_handshake.h" |
| 8 #include "net/quic/crypto/quic_decrypter.h" | 9 #include "net/quic/crypto/quic_decrypter.h" |
| 9 #include "net/quic/crypto/quic_encrypter.h" | 10 #include "net/quic/crypto/quic_encrypter.h" |
| 11 #include "net/quic/crypto/quic_random.h" |
| 12 #include "net/quic/quic_clock.h" |
| 10 #include "net/quic/quic_crypto_client_stream.h" | 13 #include "net/quic/quic_crypto_client_stream.h" |
| 11 #include "net/quic/quic_crypto_server_stream.h" | 14 #include "net/quic/quic_crypto_server_stream.h" |
| 12 #include "net/quic/quic_crypto_stream.h" | 15 #include "net/quic/quic_crypto_stream.h" |
| 13 #include "net/quic/test_tools/quic_test_utils.h" | 16 #include "net/quic/test_tools/quic_test_utils.h" |
| 14 #include "net/quic/test_tools/simple_quic_framer.h" | 17 #include "net/quic/test_tools/simple_quic_framer.h" |
| 15 | 18 |
| 16 using base::StringPiece; | 19 using base::StringPiece; |
| 17 using std::string; | 20 using std::string; |
| 18 | 21 |
| 19 namespace net { | 22 namespace net { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void CryptoTestUtils::HandshakeWithFakeServer( | 71 void CryptoTestUtils::HandshakeWithFakeServer( |
| 69 PacketSavingConnection* client_conn, | 72 PacketSavingConnection* client_conn, |
| 70 QuicCryptoClientStream* client) { | 73 QuicCryptoClientStream* client) { |
| 71 QuicGuid guid(1); | 74 QuicGuid guid(1); |
| 72 IPAddressNumber ip; | 75 IPAddressNumber ip; |
| 73 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); | 76 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); |
| 74 IPEndPoint addr = IPEndPoint(ip, 1); | 77 IPEndPoint addr = IPEndPoint(ip, 1); |
| 75 PacketSavingConnection* server_conn = | 78 PacketSavingConnection* server_conn = |
| 76 new PacketSavingConnection(guid, addr, true); | 79 new PacketSavingConnection(guid, addr, true); |
| 77 TestSession server_session(server_conn, true); | 80 TestSession server_session(server_conn, true); |
| 78 QuicCryptoServerStream server(&server_session); | 81 |
| 82 QuicConfig config; |
| 83 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING); |
| 84 SetupCryptoServerConfigForTest( |
| 85 server_session.connection()->clock(), |
| 86 server_session.connection()->random_generator(), |
| 87 &config, &crypto_config); |
| 88 |
| 89 QuicCryptoServerStream server(config, crypto_config, &server_session); |
| 79 | 90 |
| 80 // The client's handshake must have been started already. | 91 // The client's handshake must have been started already. |
| 81 CHECK_NE(0u, client_conn->packets_.size()); | 92 CHECK_NE(0u, client_conn->packets_.size()); |
| 82 | 93 |
| 83 CommunicateHandshakeMessages(client_conn, client, server_conn, &server); | 94 CommunicateHandshakeMessages(client_conn, client, server_conn, &server); |
| 84 | 95 |
| 85 CompareClientAndServerKeys(client, &server); | 96 CompareClientAndServerKeys(client, &server); |
| 86 } | 97 } |
| 87 | 98 |
| 88 // static | 99 // static |
| 89 void CryptoTestUtils::HandshakeWithFakeClient( | 100 void CryptoTestUtils::HandshakeWithFakeClient( |
| 90 PacketSavingConnection* server_conn, | 101 PacketSavingConnection* server_conn, |
| 91 QuicCryptoServerStream* server) { | 102 QuicCryptoServerStream* server) { |
| 92 QuicGuid guid(1); | 103 QuicGuid guid(1); |
| 93 IPAddressNumber ip; | 104 IPAddressNumber ip; |
| 94 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); | 105 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); |
| 95 IPEndPoint addr = IPEndPoint(ip, 1); | 106 IPEndPoint addr = IPEndPoint(ip, 1); |
| 96 PacketSavingConnection* client_conn = | 107 PacketSavingConnection* client_conn = |
| 97 new PacketSavingConnection(guid, addr, false); | 108 new PacketSavingConnection(guid, addr, false); |
| 98 TestSession client_session(client_conn, true); | 109 TestSession client_session(client_conn, true); |
| 99 QuicCryptoClientStream client(&client_session, "test.example.com"); | 110 QuicConfig config; |
| 111 QuicCryptoClientConfig crypto_config; |
| 112 |
| 113 config.SetDefaults(); |
| 114 crypto_config.SetDefaults(); |
| 115 QuicCryptoClientStream client("test.example.com", config, &client_session, |
| 116 &crypto_config); |
| 100 | 117 |
| 101 CHECK(client.CryptoConnect()); | 118 CHECK(client.CryptoConnect()); |
| 102 CHECK_EQ(1u, client_conn->packets_.size()); | 119 CHECK_EQ(1u, client_conn->packets_.size()); |
| 103 | 120 |
| 104 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); | 121 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); |
| 105 | 122 |
| 106 CompareClientAndServerKeys(&client, server); | 123 CompareClientAndServerKeys(&client, server); |
| 107 } | 124 } |
| 108 | 125 |
| 109 // static | 126 // static |
| 127 void CryptoTestUtils::SetupCryptoServerConfigForTest( |
| 128 const QuicClock* clock, |
| 129 QuicRandom* rand, |
| 130 QuicConfig* config, |
| 131 QuicCryptoServerConfig* crypto_config) { |
| 132 config->SetDefaults(); |
| 133 CryptoHandshakeMessage extra_tags; |
| 134 config->ToHandshakeMessage(&extra_tags); |
| 135 |
| 136 scoped_ptr<CryptoHandshakeMessage> scfg( |
| 137 crypto_config->AddDefaultConfig(rand, clock, extra_tags)); |
| 138 if (!config->SetFromHandshakeMessage(*scfg)) { |
| 139 CHECK(false) << "Crypto config could not be parsed by QuicConfig."; |
| 140 } |
| 141 } |
| 142 |
| 143 // static |
| 110 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message, | 144 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message, |
| 111 CryptoTag tag) { | 145 CryptoTag tag) { |
| 112 CryptoTagValueMap::const_iterator it = message.tag_value_map().find(tag); | 146 CryptoTagValueMap::const_iterator it = message.tag_value_map().find(tag); |
| 113 if (it == message.tag_value_map().end()) { | 147 if (it == message.tag_value_map().end()) { |
| 114 return string(); | 148 return string(); |
| 115 } | 149 } |
| 116 return it->second; | 150 return it->second; |
| 117 } | 151 } |
| 118 | 152 |
| 119 void CryptoTestUtils::CompareClientAndServerKeys( | 153 void CryptoTestUtils::CompareClientAndServerKeys( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 client_decrypter_key.data(), | 185 client_decrypter_key.data(), |
| 152 client_decrypter_key.length()); | 186 client_decrypter_key.length()); |
| 153 CompareCharArraysWithHexError("server write IV", | 187 CompareCharArraysWithHexError("server write IV", |
| 154 server_encrypter_iv.data(), | 188 server_encrypter_iv.data(), |
| 155 server_encrypter_iv.length(), | 189 server_encrypter_iv.length(), |
| 156 client_decrypter_iv.data(), | 190 client_decrypter_iv.data(), |
| 157 client_decrypter_iv.length()); | 191 client_decrypter_iv.length()); |
| 158 } | 192 } |
| 159 } // namespace test | 193 } // namespace test |
| 160 } // namespace net | 194 } // namespace net |
| OLD | NEW |