| 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 "net/quic/crypto/common_cert_set.h" | 7 #include "base/strings/string_piece.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 Loading... |
| 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 | |
| 280 void CryptoTestUtils::CompareClientAndServerKeys( | 218 void CryptoTestUtils::CompareClientAndServerKeys( |
| 281 QuicCryptoClientStream* client, | 219 QuicCryptoClientStream* client, |
| 282 QuicCryptoServerStream* server) { | 220 QuicCryptoServerStream* server) { |
| 283 const QuicEncrypter* client_encrypter( | 221 const QuicEncrypter* client_encrypter( |
| 284 client->session()->connection()->encrypter(ENCRYPTION_INITIAL)); | 222 client->session()->connection()->encrypter(ENCRYPTION_INITIAL)); |
| 285 // Normally we would expect the client's INITIAL decrypter to have latched | 223 // Normally we would expect the client's INITIAL decrypter to have latched |
| 286 // from the receipt of the server hello. However, when using a | 224 // from the receipt of the server hello. However, when using a |
| 287 // PacketSavingConnection (at the tests do) we don't actually encrypt with | 225 // PacketSavingConnection (at the tests do) we don't actually encrypt with |
| 288 // the correct encrypter. | 226 // the correct encrypter. |
| 289 // TODO(agl): make the tests more realistic. | 227 // TODO(agl): make the tests more realistic. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 319 client_decrypter_key.data(), | 257 client_decrypter_key.data(), |
| 320 client_decrypter_key.length()); | 258 client_decrypter_key.length()); |
| 321 CompareCharArraysWithHexError("server write IV", | 259 CompareCharArraysWithHexError("server write IV", |
| 322 server_encrypter_iv.data(), | 260 server_encrypter_iv.data(), |
| 323 server_encrypter_iv.length(), | 261 server_encrypter_iv.length(), |
| 324 client_decrypter_iv.data(), | 262 client_decrypter_iv.data(), |
| 325 client_decrypter_iv.length()); | 263 client_decrypter_iv.length()); |
| 326 } | 264 } |
| 327 } // namespace test | 265 } // namespace test |
| 328 } // namespace net | 266 } // namespace net |
| OLD | NEW |