Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: net/quic/test_tools/crypto_test_utils.cc

Issue 12806002: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor comment fix Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.h ('k') | net/quic/test_tools/quic_connection_peer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_piece.h"
8 #include "net/quic/crypto/quic_decrypter.h"
9 #include "net/quic/crypto/quic_encrypter.h"
7 #include "net/quic/quic_crypto_client_stream.h" 10 #include "net/quic/quic_crypto_client_stream.h"
8 #include "net/quic/quic_crypto_server_stream.h" 11 #include "net/quic/quic_crypto_server_stream.h"
9 #include "net/quic/quic_crypto_stream.h" 12 #include "net/quic/quic_crypto_stream.h"
10 #include "net/quic/test_tools/quic_test_utils.h" 13 #include "net/quic/test_tools/quic_test_utils.h"
11 #include "net/quic/test_tools/simple_quic_framer.h" 14 #include "net/quic/test_tools/simple_quic_framer.h"
12 15
16 using base::StringPiece;
17
13 namespace net { 18 namespace net {
14 namespace test { 19 namespace test {
15 20
16 namespace { 21 namespace {
17 22
18 class TestSession : public QuicSession { 23 class TestSession : public QuicSession {
19 public: 24 public:
20 TestSession(QuicConnection* connection, bool is_server) 25 TestSession(QuicConnection* connection, bool is_server)
21 : QuicSession(connection, is_server) { 26 : QuicSession(connection, is_server) {
22 } 27 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 scoped_ptr<CryptoHandshakeMessage> b_msg(framer->HandshakeMessage(0)); 59 scoped_ptr<CryptoHandshakeMessage> b_msg(framer->HandshakeMessage(0));
55 a->OnHandshakeMessage(*(b_msg.get())); 60 a->OnHandshakeMessage(*(b_msg.get()));
56 } 61 }
57 } 62 }
58 63
59 } // anonymous namespace 64 } // anonymous namespace
60 65
61 // static 66 // static
62 void CryptoTestUtils::HandshakeWithFakeServer( 67 void CryptoTestUtils::HandshakeWithFakeServer(
63 PacketSavingConnection* client_conn, 68 PacketSavingConnection* client_conn,
64 QuicCryptoStream* client) { 69 QuicCryptoClientStream* client) {
65 QuicGuid guid(1); 70 QuicGuid guid(1);
66 IPAddressNumber ip; 71 IPAddressNumber ip;
67 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); 72 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip));
68 IPEndPoint addr = IPEndPoint(ip, 1); 73 IPEndPoint addr = IPEndPoint(ip, 1);
69 PacketSavingConnection* server_conn = 74 PacketSavingConnection* server_conn =
70 new PacketSavingConnection(guid, addr); 75 new PacketSavingConnection(guid, addr, true);
71 TestSession server_session(server_conn, true); 76 TestSession server_session(server_conn, true);
72 QuicCryptoServerStream server(&server_session); 77 QuicCryptoServerStream server(&server_session);
73 78
74 // The client's handshake must have been started already. 79 // The client's handshake must have been started already.
75 CHECK_NE(0u, client_conn->packets_.size()); 80 CHECK_NE(0u, client_conn->packets_.size());
76 81
77 CommunicateHandshakeMessages(client_conn, client, server_conn, &server); 82 CommunicateHandshakeMessages(client_conn, client, server_conn, &server);
83
84 CompareClientAndServerKeys(client, &server);
78 } 85 }
79 86
80 // static 87 // static
81 void CryptoTestUtils::HandshakeWithFakeClient( 88 void CryptoTestUtils::HandshakeWithFakeClient(
82 PacketSavingConnection* server_conn, 89 PacketSavingConnection* server_conn,
83 QuicCryptoStream* server) { 90 QuicCryptoServerStream* server) {
84 QuicGuid guid(1); 91 QuicGuid guid(1);
85 IPAddressNumber ip; 92 IPAddressNumber ip;
86 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); 93 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip));
87 IPEndPoint addr = IPEndPoint(ip, 1); 94 IPEndPoint addr = IPEndPoint(ip, 1);
88 PacketSavingConnection* client_conn = 95 PacketSavingConnection* client_conn =
89 new PacketSavingConnection(guid, addr); 96 new PacketSavingConnection(guid, addr, false);
90 TestSession client_session(client_conn, true); 97 TestSession client_session(client_conn, true);
91 QuicCryptoClientStream client(&client_session, "test.example.com"); 98 QuicCryptoClientStream client(&client_session, "test.example.com");
92 99
93 CHECK(client.CryptoConnect()); 100 CHECK(client.CryptoConnect());
94 CHECK_EQ(1u, client_conn->packets_.size()); 101 CHECK_EQ(1u, client_conn->packets_.size());
95 102
96 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); 103 CommunicateHandshakeMessages(client_conn, &client, server_conn, server);
104
105 CompareClientAndServerKeys(&client, server);
106 }
107
108 // static
109 void CryptoTestUtils::CompareClientAndServerKeys(
110 QuicCryptoClientStream* client,
111 QuicCryptoServerStream* server) {
112 StringPiece client_encrypter_key =
113 client->crypto_negotiated_params_.encrypter->GetKey();
114 StringPiece client_encrypter_iv =
115 client->crypto_negotiated_params_.encrypter->GetNoncePrefix();
116 StringPiece client_decrypter_key =
117 client->crypto_negotiated_params_.decrypter->GetKey();
118 StringPiece client_decrypter_iv =
119 client->crypto_negotiated_params_.decrypter->GetNoncePrefix();
120 StringPiece server_encrypter_key =
121 server->crypto_negotiated_params_.encrypter->GetKey();
122 StringPiece server_encrypter_iv =
123 server->crypto_negotiated_params_.encrypter->GetNoncePrefix();
124 StringPiece server_decrypter_key =
125 server->crypto_negotiated_params_.decrypter->GetKey();
126 StringPiece server_decrypter_iv =
127 server->crypto_negotiated_params_.decrypter->GetNoncePrefix();
128 CompareCharArraysWithHexError("client write key",
129 client_encrypter_key.data(),
130 client_encrypter_key.length(),
131 server_decrypter_key.data(),
132 server_decrypter_key.length());
133 CompareCharArraysWithHexError("client write IV",
134 client_encrypter_iv.data(),
135 client_encrypter_iv.length(),
136 server_decrypter_iv.data(),
137 server_decrypter_iv.length());
138 CompareCharArraysWithHexError("server write key",
139 server_encrypter_key.data(),
140 server_encrypter_key.length(),
141 client_decrypter_key.data(),
142 client_decrypter_key.length());
143 CompareCharArraysWithHexError("server write IV",
144 server_encrypter_iv.data(),
145 server_encrypter_iv.length(),
146 client_decrypter_iv.data(),
147 client_decrypter_iv.length());
97 } 148 }
98 } // namespace test 149 } // namespace test
99 } // namespace net 150 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.h ('k') | net/quic/test_tools/quic_connection_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698