| 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/channel_id.h" | 7 #include "net/quic/crypto/channel_id.h" |
| 8 #include "net/quic/crypto/common_cert_set.h" | 8 #include "net/quic/crypto/common_cert_set.h" |
| 9 #include "net/quic/crypto/crypto_handshake.h" | 9 #include "net/quic/crypto/crypto_handshake.h" |
| 10 #include "net/quic/crypto/quic_crypto_server_config.h" | 10 #include "net/quic/crypto/quic_crypto_server_config.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 const vector<CryptoHandshakeMessage>& messages() const { | 55 const vector<CryptoHandshakeMessage>& messages() const { |
| 56 return messages_; | 56 return messages_; |
| 57 } | 57 } |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 bool error_; | 60 bool error_; |
| 61 vector<CryptoHandshakeMessage> messages_; | 61 vector<CryptoHandshakeMessage> messages_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 // MovePackets parses crypto handshake messages from packet number | 64 // MovePackets parses crypto handshake messages from packet number |
| 65 // |*inout_packet_index| through to the last packet and has |dest_stream| | 65 // |*inout_packet_index| through to the last packet (or until a packet fails to |
| 66 // process them. |*inout_packet_index| is updated with an index one greater | 66 // decrypt) and has |dest_stream| process them. |*inout_packet_index| is updated |
| 67 // than the last packet processed. | 67 // with an index one greater than the last packet processed. |
| 68 void MovePackets(PacketSavingConnection* source_conn, | 68 void MovePackets(PacketSavingConnection* source_conn, |
| 69 size_t *inout_packet_index, | 69 size_t *inout_packet_index, |
| 70 QuicCryptoStream* dest_stream, | 70 QuicCryptoStream* dest_stream, |
| 71 PacketSavingConnection* dest_conn) { | 71 PacketSavingConnection* dest_conn) { |
| 72 SimpleQuicFramer framer(source_conn->supported_versions()); | 72 SimpleQuicFramer framer(source_conn->supported_versions()); |
| 73 CryptoFramer crypto_framer; | 73 CryptoFramer crypto_framer; |
| 74 CryptoFramerVisitor crypto_visitor; | 74 CryptoFramerVisitor crypto_visitor; |
| 75 | 75 |
| 76 // In order to properly test the code we need to perform encryption and | 76 // In order to properly test the code we need to perform encryption and |
| 77 // decryption so that the crypters latch when expected. The crypters are in | 77 // decryption so that the crypters latch when expected. The crypters are in |
| 78 // |dest_conn|, but we don't want to try and use them there. Instead we swap | 78 // |dest_conn|, but we don't want to try and use them there. Instead we swap |
| 79 // them into |framer|, perform the decryption with them, and then swap them | 79 // them into |framer|, perform the decryption with them, and then swap them |
| 80 // back. | 80 // back. |
| 81 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer()); | 81 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer()); |
| 82 | 82 |
| 83 crypto_framer.set_visitor(&crypto_visitor); | 83 crypto_framer.set_visitor(&crypto_visitor); |
| 84 | 84 |
| 85 size_t index = *inout_packet_index; | 85 size_t index = *inout_packet_index; |
| 86 for (; index < source_conn->encrypted_packets_.size(); index++) { | 86 for (; index < source_conn->encrypted_packets_.size(); index++) { |
| 87 ASSERT_TRUE(framer.ProcessPacket(*source_conn->encrypted_packets_[index])); | 87 if (!framer.ProcessPacket(*source_conn->encrypted_packets_[index])) { |
| 88 // The framer will be unable to decrypt forward-secure packets sent after |
| 89 // the handshake is complete. Don't treat them as handshake packets. |
| 90 break; |
| 91 } |
| 92 |
| 88 for (vector<QuicStreamFrame>::const_iterator | 93 for (vector<QuicStreamFrame>::const_iterator |
| 89 i = framer.stream_frames().begin(); | 94 i = framer.stream_frames().begin(); |
| 90 i != framer.stream_frames().end(); ++i) { | 95 i != framer.stream_frames().end(); ++i) { |
| 91 scoped_ptr<string> frame_data(i->GetDataAsString()); | 96 scoped_ptr<string> frame_data(i->GetDataAsString()); |
| 92 ASSERT_TRUE(crypto_framer.ProcessInput(*frame_data)); | 97 ASSERT_TRUE(crypto_framer.ProcessInput(*frame_data)); |
| 93 ASSERT_FALSE(crypto_visitor.error()); | 98 ASSERT_FALSE(crypto_visitor.error()); |
| 94 } | 99 } |
| 95 } | 100 } |
| 96 *inout_packet_index = index; | 101 *inout_packet_index = index; |
| 97 | 102 |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); | 629 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); |
| 625 scoped_ptr<CryptoHandshakeMessage> parsed( | 630 scoped_ptr<CryptoHandshakeMessage> parsed( |
| 626 CryptoFramer::ParseMessage(bytes->AsStringPiece())); | 631 CryptoFramer::ParseMessage(bytes->AsStringPiece())); |
| 627 CHECK(parsed.get()); | 632 CHECK(parsed.get()); |
| 628 | 633 |
| 629 return *parsed; | 634 return *parsed; |
| 630 } | 635 } |
| 631 | 636 |
| 632 } // namespace test | 637 } // namespace test |
| 633 } // namespace net | 638 } // namespace net |
| OLD | NEW |