OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/crypto/quic_crypto_client_config.h" | 5 #include "net/quic/crypto/quic_crypto_client_config.h" |
6 | 6 |
7 #include "net/quic/crypto/proof_verifier.h" | 7 #include "net/quic/crypto/proof_verifier.h" |
8 #include "net/quic/quic_session_key.h" | 8 #include "net/quic/quic_session_key.h" |
9 #include "net/quic/test_tools/mock_random.h" | 9 #include "net/quic/test_tools/mock_random.h" |
10 #include "net/quic/test_tools/quic_test_utils.h" | 10 #include "net/quic/test_tools/quic_test_utils.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 EXPECT_EQ(state.source_address_token(), other.source_address_token()); | 50 EXPECT_EQ(state.source_address_token(), other.source_address_token()); |
51 EXPECT_EQ(state.certs(), other.certs()); | 51 EXPECT_EQ(state.certs(), other.certs()); |
52 EXPECT_EQ(1u, other.generation_counter()); | 52 EXPECT_EQ(1u, other.generation_counter()); |
53 } | 53 } |
54 | 54 |
55 TEST(QuicCryptoClientConfigTest, InchoateChlo) { | 55 TEST(QuicCryptoClientConfigTest, InchoateChlo) { |
56 QuicCryptoClientConfig::CachedState state; | 56 QuicCryptoClientConfig::CachedState state; |
57 QuicCryptoClientConfig config; | 57 QuicCryptoClientConfig config; |
58 QuicCryptoNegotiatedParameters params; | 58 QuicCryptoNegotiatedParameters params; |
59 CryptoHandshakeMessage msg; | 59 CryptoHandshakeMessage msg; |
60 QuicSessionKey server_key("www.google.com", 80, false, kPrivacyModeDisabled); | 60 QuicSessionKey server_key("www.google.com", 80, false, PRIVACY_MODE_DISABLED); |
61 config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, | 61 config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, |
62 ¶ms, &msg); | 62 ¶ms, &msg); |
63 | 63 |
64 QuicTag cver; | 64 QuicTag cver; |
65 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); | 65 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); |
66 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); | 66 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); |
67 } | 67 } |
68 | 68 |
69 TEST(QuicCryptoClientConfigTest, FillClientHello) { | 69 TEST(QuicCryptoClientConfigTest, FillClientHello) { |
70 QuicCryptoClientConfig::CachedState state; | 70 QuicCryptoClientConfig::CachedState state; |
71 QuicCryptoClientConfig config; | 71 QuicCryptoClientConfig config; |
72 QuicCryptoNegotiatedParameters params; | 72 QuicCryptoNegotiatedParameters params; |
73 QuicConnectionId kConnectionId = 1234; | 73 QuicConnectionId kConnectionId = 1234; |
74 uint32 kInitialFlowControlWindow = 5678; | 74 uint32 kInitialFlowControlWindow = 5678; |
75 string error_details; | 75 string error_details; |
76 MockRandom rand; | 76 MockRandom rand; |
77 CryptoHandshakeMessage chlo; | 77 CryptoHandshakeMessage chlo; |
78 QuicSessionKey server_key("www.google.com", 80, false, kPrivacyModeDisabled); | 78 QuicSessionKey server_key("www.google.com", 80, false, PRIVACY_MODE_DISABLED); |
79 config.FillClientHello(server_key, | 79 config.FillClientHello(server_key, |
80 kConnectionId, | 80 kConnectionId, |
81 QuicVersionMax(), | 81 QuicVersionMax(), |
82 kInitialFlowControlWindow, | 82 kInitialFlowControlWindow, |
83 &state, | 83 &state, |
84 QuicWallTime::Zero(), | 84 QuicWallTime::Zero(), |
85 &rand, | 85 &rand, |
86 ¶ms, | 86 ¶ms, |
87 &chlo, | 87 &chlo, |
88 &error_details); | 88 &error_details); |
89 | 89 |
90 // Verify that certain QuicTags have been set correctly in the CHLO. | 90 // Verify that certain QuicTags have been set correctly in the CHLO. |
91 QuicTag cver; | 91 QuicTag cver; |
92 EXPECT_EQ(QUIC_NO_ERROR, chlo.GetUint32(kVER, &cver)); | 92 EXPECT_EQ(QUIC_NO_ERROR, chlo.GetUint32(kVER, &cver)); |
93 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); | 93 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); |
94 | 94 |
95 QuicTag ifcw; | 95 QuicTag ifcw; |
96 EXPECT_EQ(QUIC_NO_ERROR, chlo.GetUint32(kIFCW, &ifcw)); | 96 EXPECT_EQ(QUIC_NO_ERROR, chlo.GetUint32(kIFCW, &ifcw)); |
97 EXPECT_EQ(kInitialFlowControlWindow, ifcw); | 97 EXPECT_EQ(kInitialFlowControlWindow, ifcw); |
98 } | 98 } |
99 | 99 |
100 TEST(QuicCryptoClientConfigTest, InchoateChloSecure) { | 100 TEST(QuicCryptoClientConfigTest, InchoateChloSecure) { |
101 QuicCryptoClientConfig::CachedState state; | 101 QuicCryptoClientConfig::CachedState state; |
102 QuicCryptoClientConfig config; | 102 QuicCryptoClientConfig config; |
103 QuicCryptoNegotiatedParameters params; | 103 QuicCryptoNegotiatedParameters params; |
104 CryptoHandshakeMessage msg; | 104 CryptoHandshakeMessage msg; |
105 QuicSessionKey server_key("www.google.com", 443, true, kPrivacyModeDisabled); | 105 QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); |
106 config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, | 106 config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, |
107 ¶ms, &msg); | 107 ¶ms, &msg); |
108 | 108 |
109 QuicTag pdmd; | 109 QuicTag pdmd; |
110 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); | 110 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); |
111 EXPECT_EQ(kX509, pdmd); | 111 EXPECT_EQ(kX509, pdmd); |
112 } | 112 } |
113 | 113 |
114 TEST(QuicCryptoClientConfigTest, InchoateChloSecureNoEcdsa) { | 114 TEST(QuicCryptoClientConfigTest, InchoateChloSecureNoEcdsa) { |
115 QuicCryptoClientConfig::CachedState state; | 115 QuicCryptoClientConfig::CachedState state; |
116 QuicCryptoClientConfig config; | 116 QuicCryptoClientConfig config; |
117 config.DisableEcdsa(); | 117 config.DisableEcdsa(); |
118 QuicCryptoNegotiatedParameters params; | 118 QuicCryptoNegotiatedParameters params; |
119 CryptoHandshakeMessage msg; | 119 CryptoHandshakeMessage msg; |
120 QuicSessionKey server_key("www.google.com", 443, true, kPrivacyModeDisabled); | 120 QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); |
121 config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, | 121 config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, |
122 ¶ms, &msg); | 122 ¶ms, &msg); |
123 | 123 |
124 QuicTag pdmd; | 124 QuicTag pdmd; |
125 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); | 125 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); |
126 EXPECT_EQ(kX59R, pdmd); | 126 EXPECT_EQ(kX59R, pdmd); |
127 } | 127 } |
128 | 128 |
129 TEST(QuicCryptoClientConfigTest, ProcessServerDowngradeAttack) { | 129 TEST(QuicCryptoClientConfigTest, ProcessServerDowngradeAttack) { |
130 QuicVersionVector supported_versions = QuicSupportedVersions(); | 130 QuicVersionVector supported_versions = QuicSupportedVersions(); |
(...skipping 16 matching lines...) Expand all Loading... |
147 QuicCryptoClientConfig config; | 147 QuicCryptoClientConfig config; |
148 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, | 148 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, |
149 config.ProcessServerHello(msg, 0, supported_versions, | 149 config.ProcessServerHello(msg, 0, supported_versions, |
150 &cached, &out_params, &error)); | 150 &cached, &out_params, &error)); |
151 EXPECT_EQ("Downgrade attack detected", error); | 151 EXPECT_EQ("Downgrade attack detected", error); |
152 } | 152 } |
153 | 153 |
154 TEST(QuicCryptoClientConfigTest, InitializeFrom) { | 154 TEST(QuicCryptoClientConfigTest, InitializeFrom) { |
155 QuicCryptoClientConfig config; | 155 QuicCryptoClientConfig config; |
156 QuicSessionKey canonical_key1("www.google.com", 80, false, | 156 QuicSessionKey canonical_key1("www.google.com", 80, false, |
157 kPrivacyModeDisabled); | 157 PRIVACY_MODE_DISABLED); |
158 QuicCryptoClientConfig::CachedState* state = | 158 QuicCryptoClientConfig::CachedState* state = |
159 config.LookupOrCreate(canonical_key1); | 159 config.LookupOrCreate(canonical_key1); |
160 // TODO(rch): Populate other fields of |state|. | 160 // TODO(rch): Populate other fields of |state|. |
161 state->set_source_address_token("TOKEN"); | 161 state->set_source_address_token("TOKEN"); |
162 state->SetProofValid(); | 162 state->SetProofValid(); |
163 | 163 |
164 QuicSessionKey other_key("mail.google.com", 80, false, kPrivacyModeDisabled); | 164 QuicSessionKey other_key("mail.google.com", 80, false, PRIVACY_MODE_DISABLED); |
165 config.InitializeFrom(other_key, canonical_key1, &config); | 165 config.InitializeFrom(other_key, canonical_key1, &config); |
166 QuicCryptoClientConfig::CachedState* other = config.LookupOrCreate(other_key); | 166 QuicCryptoClientConfig::CachedState* other = config.LookupOrCreate(other_key); |
167 | 167 |
168 EXPECT_EQ(state->server_config(), other->server_config()); | 168 EXPECT_EQ(state->server_config(), other->server_config()); |
169 EXPECT_EQ(state->source_address_token(), other->source_address_token()); | 169 EXPECT_EQ(state->source_address_token(), other->source_address_token()); |
170 EXPECT_EQ(state->certs(), other->certs()); | 170 EXPECT_EQ(state->certs(), other->certs()); |
171 EXPECT_EQ(1u, other->generation_counter()); | 171 EXPECT_EQ(1u, other->generation_counter()); |
172 } | 172 } |
173 | 173 |
174 } // namespace test | 174 } // namespace test |
175 } // namespace net | 175 } // namespace net |
OLD | NEW |