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

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

Issue 14651009: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix integer constant is too large for 'unsigned long' type Created 7 years, 7 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_test_utils.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/strings/string_piece.h" 7 #include "net/quic/crypto/common_cert_set.h"
8 #include "net/quic/crypto/crypto_handshake.h" 8 #include "net/quic/crypto/crypto_handshake.h"
9 #include "net/quic/crypto/crypto_server_config.h" 9 #include "net/quic/crypto/crypto_server_config.h"
10 #include "net/quic/crypto/quic_decrypter.h" 10 #include "net/quic/crypto/quic_decrypter.h"
11 #include "net/quic/crypto/quic_encrypter.h" 11 #include "net/quic/crypto/quic_encrypter.h"
12 #include "net/quic/crypto/quic_random.h" 12 #include "net/quic/crypto/quic_random.h"
13 #include "net/quic/quic_clock.h" 13 #include "net/quic/quic_clock.h"
14 #include "net/quic/quic_crypto_client_stream.h" 14 #include "net/quic/quic_crypto_client_stream.h"
15 #include "net/quic/quic_crypto_server_stream.h" 15 #include "net/quic/quic_crypto_server_stream.h"
16 #include "net/quic/quic_crypto_stream.h" 16 #include "net/quic/quic_crypto_stream.h"
17 #include "net/quic/test_tools/quic_test_utils.h" 17 #include "net/quic/test_tools/quic_test_utils.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // static 208 // static
209 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message, 209 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message,
210 CryptoTag tag) { 210 CryptoTag tag) {
211 CryptoTagValueMap::const_iterator it = message.tag_value_map().find(tag); 211 CryptoTagValueMap::const_iterator it = message.tag_value_map().find(tag);
212 if (it == message.tag_value_map().end()) { 212 if (it == message.tag_value_map().end()) {
213 return string(); 213 return string();
214 } 214 }
215 return it->second; 215 return it->second;
216 } 216 }
217 217
218 class MockCommonCertSet : public CommonCertSet {
219 public:
220 MockCommonCertSet(StringPiece cert, uint64 hash, uint32 index)
221 : cert_(cert.as_string()),
222 hash_(hash),
223 index_(index) {
224 }
225
226 virtual StringPiece GetCommonHashes() OVERRIDE {
227 CHECK(false) << "not implemented";
228 return StringPiece();
229 }
230
231 virtual StringPiece GetCert(uint64 hash, uint32 index) OVERRIDE {
232 if (hash == hash_ && index == index_) {
233 return cert_;
234 }
235 return StringPiece();
236 }
237
238 virtual bool MatchCert(StringPiece cert,
239 StringPiece common_set_hashes,
240 uint64* out_hash,
241 uint32* out_index) OVERRIDE {
242 if (cert != cert_) {
243 return false;
244 }
245
246 if (common_set_hashes.size() % sizeof(uint64) != 0) {
247 return false;
248 }
249 bool client_has_set = false;
250 for (size_t i = 0; i < common_set_hashes.size(); i += sizeof(uint64)) {
251 uint64 hash;
252 memcpy(&hash, common_set_hashes.data() + i, sizeof(hash));
253 if (hash == hash_) {
254 client_has_set = true;
255 break;
256 }
257 }
258
259 if (!client_has_set) {
260 return false;
261 }
262
263 *out_hash = hash_;
264 *out_index = index_;
265 return true;
266 }
267
268 private:
269 const string cert_;
270 const uint64 hash_;
271 const uint32 index_;
272 };
273
274 CommonCertSet* CryptoTestUtils::MockCommonCertSet(StringPiece cert,
275 uint64 hash,
276 uint32 index) {
277 return new class MockCommonCertSet(cert, hash, index);
278 }
279
218 void CryptoTestUtils::CompareClientAndServerKeys( 280 void CryptoTestUtils::CompareClientAndServerKeys(
219 QuicCryptoClientStream* client, 281 QuicCryptoClientStream* client,
220 QuicCryptoServerStream* server) { 282 QuicCryptoServerStream* server) {
221 const QuicEncrypter* client_encrypter( 283 const QuicEncrypter* client_encrypter(
222 client->session()->connection()->encrypter(ENCRYPTION_INITIAL)); 284 client->session()->connection()->encrypter(ENCRYPTION_INITIAL));
223 // Normally we would expect the client's INITIAL decrypter to have latched 285 // Normally we would expect the client's INITIAL decrypter to have latched
224 // from the receipt of the server hello. However, when using a 286 // from the receipt of the server hello. However, when using a
225 // PacketSavingConnection (at the tests do) we don't actually encrypt with 287 // PacketSavingConnection (at the tests do) we don't actually encrypt with
226 // the correct encrypter. 288 // the correct encrypter.
227 // TODO(agl): make the tests more realistic. 289 // TODO(agl): make the tests more realistic.
(...skipping 29 matching lines...) Expand all
257 client_decrypter_key.data(), 319 client_decrypter_key.data(),
258 client_decrypter_key.length()); 320 client_decrypter_key.length());
259 CompareCharArraysWithHexError("server write IV", 321 CompareCharArraysWithHexError("server write IV",
260 server_encrypter_iv.data(), 322 server_encrypter_iv.data(),
261 server_encrypter_iv.length(), 323 server_encrypter_iv.length(),
262 client_decrypter_iv.data(), 324 client_decrypter_iv.data(),
263 client_decrypter_iv.length()); 325 client_decrypter_iv.length());
264 } 326 }
265 } // namespace test 327 } // namespace test
266 } // namespace net 328 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.h ('k') | net/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698