OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/tools/quic/stateless_rejector.h" | 5 #include "net/tools/quic/stateless_rejector.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "net/quic/crypto/crypto_handshake_message.h" | 10 #include "net/quic/crypto/crypto_handshake_message.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 }; | 128 }; |
129 | 129 |
130 INSTANTIATE_TEST_CASE_P(Flags, | 130 INSTANTIATE_TEST_CASE_P(Flags, |
131 StatelessRejectorTest, | 131 StatelessRejectorTest, |
132 ::testing::ValuesIn(GetTestParams())); | 132 ::testing::ValuesIn(GetTestParams())); |
133 | 133 |
134 TEST_P(StatelessRejectorTest, InvalidChlo) { | 134 TEST_P(StatelessRejectorTest, InvalidChlo) { |
135 // clang-format off | 135 // clang-format off |
136 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( | 136 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( |
137 "CHLO", | 137 "CHLO", |
| 138 "PDMD", "X509", |
138 "COPT", "SREJ", | 139 "COPT", "SREJ", |
139 nullptr); | 140 nullptr); |
140 // clang-format on | 141 // clang-format on |
141 rejector_.OnChlo(GetParam().version, kConnectionId, | 142 rejector_.OnChlo(GetParam().version, kConnectionId, |
142 kServerDesignateConnectionId, client_hello); | 143 kServerDesignateConnectionId, client_hello); |
143 | 144 |
144 if (GetParam().flags != ENABLED || GetParam().version <= QUIC_VERSION_32) { | 145 if (GetParam().flags != ENABLED || GetParam().version <= QUIC_VERSION_32) { |
145 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_.state()); | 146 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_.state()); |
146 return; | 147 return; |
147 } | 148 } |
148 | 149 |
149 EXPECT_EQ(StatelessRejector::FAILED, rejector_.state()); | 150 EXPECT_EQ(StatelessRejector::FAILED, rejector_.state()); |
150 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, rejector_.error()); | 151 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, rejector_.error()); |
151 } | 152 } |
152 | 153 |
153 TEST_P(StatelessRejectorTest, ValidChloWithoutSrejSupport) { | 154 TEST_P(StatelessRejectorTest, ValidChloWithoutSrejSupport) { |
154 // clang-format off | 155 // clang-format off |
155 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( | 156 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( |
156 "CHLO", | 157 "CHLO", |
| 158 "PDMD", "X509", |
157 "AEAD", "AESG", | 159 "AEAD", "AESG", |
158 "KEXS", "C255", | 160 "KEXS", "C255", |
159 "PUBS", pubs_hex_.c_str(), | 161 "PUBS", pubs_hex_.c_str(), |
160 "NONC", nonc_hex_.c_str(), | 162 "NONC", nonc_hex_.c_str(), |
161 "VER\0", ver_hex_.c_str(), | 163 "VER\0", ver_hex_.c_str(), |
162 "$padding", static_cast<int>(kClientHelloMinimumSize), | 164 "$padding", static_cast<int>(kClientHelloMinimumSize), |
163 nullptr); | 165 nullptr); |
164 // clang-format on | 166 // clang-format on |
165 | 167 |
166 rejector_.OnChlo(GetParam().version, kConnectionId, | 168 rejector_.OnChlo(GetParam().version, kConnectionId, |
167 kServerDesignateConnectionId, client_hello); | 169 kServerDesignateConnectionId, client_hello); |
168 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_.state()); | 170 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_.state()); |
169 } | 171 } |
170 | 172 |
171 TEST_P(StatelessRejectorTest, RejectChlo) { | 173 TEST_P(StatelessRejectorTest, RejectChlo) { |
172 // clang-format off | 174 // clang-format off |
173 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( | 175 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( |
174 "CHLO", | 176 "CHLO", |
| 177 "PDMD", "X509", |
175 "AEAD", "AESG", | 178 "AEAD", "AESG", |
176 "KEXS", "C255", | 179 "KEXS", "C255", |
177 "COPT", "SREJ", | 180 "COPT", "SREJ", |
178 "SCID", scid_hex_.c_str(), | 181 "SCID", scid_hex_.c_str(), |
179 "PUBS", pubs_hex_.c_str(), | 182 "PUBS", pubs_hex_.c_str(), |
180 "NONC", nonc_hex_.c_str(), | 183 "NONC", nonc_hex_.c_str(), |
181 "#004b5453", stk_hex_.c_str(), | 184 "#004b5453", stk_hex_.c_str(), |
182 "VER\0", ver_hex_.c_str(), | 185 "VER\0", ver_hex_.c_str(), |
183 "$padding", static_cast<int>(kClientHelloMinimumSize), | 186 "$padding", static_cast<int>(kClientHelloMinimumSize), |
184 nullptr); | 187 nullptr); |
(...skipping 18 matching lines...) Expand all Loading... |
203 } | 206 } |
204 | 207 |
205 TEST_P(StatelessRejectorTest, AcceptChlo) { | 208 TEST_P(StatelessRejectorTest, AcceptChlo) { |
206 const uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); | 209 const uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); |
207 const string xlct_hex = | 210 const string xlct_hex = |
208 "#" + | 211 "#" + |
209 QuicUtils::HexEncode(reinterpret_cast<const char*>(&xlct), sizeof(xlct)); | 212 QuicUtils::HexEncode(reinterpret_cast<const char*>(&xlct), sizeof(xlct)); |
210 // clang-format off | 213 // clang-format off |
211 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( | 214 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( |
212 "CHLO", | 215 "CHLO", |
| 216 "PDMD", "X509", |
213 "AEAD", "AESG", | 217 "AEAD", "AESG", |
214 "KEXS", "C255", | 218 "KEXS", "C255", |
215 "COPT", "SREJ", | 219 "COPT", "SREJ", |
216 "SCID", scid_hex_.c_str(), | 220 "SCID", scid_hex_.c_str(), |
217 "PUBS", pubs_hex_.c_str(), | 221 "PUBS", pubs_hex_.c_str(), |
218 "NONC", nonc_hex_.c_str(), | 222 "NONC", nonc_hex_.c_str(), |
219 "#004b5453", stk_hex_.c_str(), | 223 "#004b5453", stk_hex_.c_str(), |
220 "VER\0", ver_hex_.c_str(), | 224 "VER\0", ver_hex_.c_str(), |
221 "XLCT", xlct_hex.c_str(), | 225 "XLCT", xlct_hex.c_str(), |
222 "$padding", static_cast<int>(kClientHelloMinimumSize), | 226 "$padding", static_cast<int>(kClientHelloMinimumSize), |
223 nullptr); | 227 nullptr); |
224 // clang-format on | 228 // clang-format on |
225 | 229 |
226 rejector_.OnChlo(GetParam().version, kConnectionId, | 230 rejector_.OnChlo(GetParam().version, kConnectionId, |
227 kServerDesignateConnectionId, client_hello); | 231 kServerDesignateConnectionId, client_hello); |
228 if (GetParam().flags != ENABLED || GetParam().version <= QUIC_VERSION_32) { | 232 if (GetParam().flags != ENABLED || GetParam().version <= QUIC_VERSION_32) { |
229 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_.state()); | 233 EXPECT_EQ(StatelessRejector::UNSUPPORTED, rejector_.state()); |
230 return; | 234 return; |
231 } | 235 } |
232 EXPECT_EQ(StatelessRejector::ACCEPTED, rejector_.state()); | 236 EXPECT_EQ(StatelessRejector::ACCEPTED, rejector_.state()); |
233 } | 237 } |
234 | 238 |
235 } // namespace | 239 } // namespace |
236 } // namespace test | 240 } // namespace test |
237 } // namespace net | 241 } // namespace net |
OLD | NEW |