| 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_server_id.h" | 8 #include "net/quic/quic_server_id.h" |
| 9 #include "net/quic/test_tools/crypto_test_utils.h" | 9 #include "net/quic/test_tools/crypto_test_utils.h" |
| 10 #include "net/quic/test_tools/mock_random.h" | 10 #include "net/quic/test_tools/mock_random.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST(QuicCryptoClientConfigTest, InchoateChlo) { | 153 TEST(QuicCryptoClientConfigTest, InchoateChlo) { |
| 154 QuicCryptoClientConfig::CachedState state; | 154 QuicCryptoClientConfig::CachedState state; |
| 155 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 155 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 156 QuicCryptoNegotiatedParameters params; | 156 QuicCryptoNegotiatedParameters params; |
| 157 CryptoHandshakeMessage msg; | 157 CryptoHandshakeMessage msg; |
| 158 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); | 158 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); |
| 159 MockRandom rand; | 159 MockRandom rand; |
| 160 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, | 160 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, |
| 161 ¶ms, &msg); | 161 /* demand_x509_proof= */ true, ¶ms, &msg); |
| 162 | 162 |
| 163 QuicTag cver; | 163 QuicTag cver; |
| 164 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); | 164 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); |
| 165 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); | 165 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); |
| 166 StringPiece proof_nonce; | 166 StringPiece proof_nonce; |
| 167 EXPECT_TRUE(msg.GetStringPiece(kNONP, &proof_nonce)); | 167 EXPECT_TRUE(msg.GetStringPiece(kNONP, &proof_nonce)); |
| 168 EXPECT_EQ(string(32, 'r'), proof_nonce); | 168 EXPECT_EQ(string(32, 'r'), proof_nonce); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST(QuicCryptoClientConfigTest, PreferAesGcm) { | 171 TEST(QuicCryptoClientConfigTest, PreferAesGcm) { |
| 172 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 172 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 173 if (config.aead.size() > 1) | 173 if (config.aead.size() > 1) |
| 174 EXPECT_NE(kAESG, config.aead[0]); | 174 EXPECT_NE(kAESG, config.aead[0]); |
| 175 config.PreferAesGcm(); | 175 config.PreferAesGcm(); |
| 176 EXPECT_EQ(kAESG, config.aead[0]); | 176 EXPECT_EQ(kAESG, config.aead[0]); |
| 177 } | 177 } |
| 178 | 178 |
| 179 TEST(QuicCryptoClientConfigTest, InchoateChloSecure) { | 179 TEST(QuicCryptoClientConfigTest, InchoateChloSecure) { |
| 180 QuicCryptoClientConfig::CachedState state; | 180 QuicCryptoClientConfig::CachedState state; |
| 181 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 181 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 182 QuicCryptoNegotiatedParameters params; | 182 QuicCryptoNegotiatedParameters params; |
| 183 CryptoHandshakeMessage msg; | 183 CryptoHandshakeMessage msg; |
| 184 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); | 184 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); |
| 185 MockRandom rand; | 185 MockRandom rand; |
| 186 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, | 186 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, |
| 187 ¶ms, &msg); | 187 /* demand_x509_proof= */ true, ¶ms, &msg); |
| 188 | 188 |
| 189 QuicTag pdmd; | 189 QuicTag pdmd; |
| 190 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); | 190 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); |
| 191 EXPECT_EQ(kX509, pdmd); | 191 EXPECT_EQ(kX509, pdmd); |
| 192 StringPiece scid; | 192 StringPiece scid; |
| 193 EXPECT_FALSE(msg.GetStringPiece(kSCID, &scid)); | 193 EXPECT_FALSE(msg.GetStringPiece(kSCID, &scid)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST(QuicCryptoClientConfigTest, InchoateChloSecureWithSCID) { | 196 TEST(QuicCryptoClientConfigTest, InchoateChloSecureWithSCID) { |
| 197 QuicCryptoClientConfig::CachedState state; | 197 QuicCryptoClientConfig::CachedState state; |
| 198 CryptoHandshakeMessage scfg; | 198 CryptoHandshakeMessage scfg; |
| 199 scfg.set_tag(kSCFG); | 199 scfg.set_tag(kSCFG); |
| 200 uint64_t future = 1; | 200 uint64_t future = 1; |
| 201 scfg.SetValue(kEXPY, future); | 201 scfg.SetValue(kEXPY, future); |
| 202 scfg.SetStringPiece(kSCID, "12345678"); | 202 scfg.SetStringPiece(kSCID, "12345678"); |
| 203 string details; | 203 string details; |
| 204 state.SetServerConfig(scfg.GetSerialized().AsStringPiece(), | 204 state.SetServerConfig(scfg.GetSerialized().AsStringPiece(), |
| 205 QuicWallTime::FromUNIXSeconds(0), &details); | 205 QuicWallTime::FromUNIXSeconds(0), &details); |
| 206 | 206 |
| 207 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 207 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 208 QuicCryptoNegotiatedParameters params; | 208 QuicCryptoNegotiatedParameters params; |
| 209 CryptoHandshakeMessage msg; | 209 CryptoHandshakeMessage msg; |
| 210 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); | 210 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); |
| 211 MockRandom rand; | 211 MockRandom rand; |
| 212 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, | 212 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, |
| 213 ¶ms, &msg); | 213 /* demand_x509_proof= */ true, ¶ms, &msg); |
| 214 | 214 |
| 215 StringPiece scid; | 215 StringPiece scid; |
| 216 EXPECT_TRUE(msg.GetStringPiece(kSCID, &scid)); | 216 EXPECT_TRUE(msg.GetStringPiece(kSCID, &scid)); |
| 217 EXPECT_EQ("12345678", scid); | 217 EXPECT_EQ("12345678", scid); |
| 218 } | 218 } |
| 219 | 219 |
| 220 TEST(QuicCryptoClientConfigTest, InchoateChloSecureNoEcdsa) { | 220 TEST(QuicCryptoClientConfigTest, InchoateChloSecureNoEcdsa) { |
| 221 QuicCryptoClientConfig::CachedState state; | 221 QuicCryptoClientConfig::CachedState state; |
| 222 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 222 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 223 config.DisableEcdsa(); | 223 config.DisableEcdsa(); |
| 224 QuicCryptoNegotiatedParameters params; | 224 QuicCryptoNegotiatedParameters params; |
| 225 CryptoHandshakeMessage msg; | 225 CryptoHandshakeMessage msg; |
| 226 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); | 226 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); |
| 227 MockRandom rand; | 227 MockRandom rand; |
| 228 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, | 228 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, |
| 229 ¶ms, &msg); | 229 /* demand_x509_proof= */ true, ¶ms, &msg); |
| 230 | 230 |
| 231 QuicTag pdmd; | 231 QuicTag pdmd; |
| 232 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); | 232 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); |
| 233 EXPECT_EQ(kX59R, pdmd); | 233 EXPECT_EQ(kX59R, pdmd); |
| 234 } | 234 } |
| 235 | 235 |
| 236 TEST(QuicCryptoClientConfigTest, FillClientHello) { | 236 TEST(QuicCryptoClientConfigTest, FillClientHello) { |
| 237 QuicCryptoClientConfig::CachedState state; | 237 QuicCryptoClientConfig::CachedState state; |
| 238 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 238 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 239 QuicCryptoNegotiatedParameters params; | 239 QuicCryptoNegotiatedParameters params; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 QuicCryptoNegotiatedParameters out_params; | 474 QuicCryptoNegotiatedParameters out_params; |
| 475 string error_details; | 475 string error_details; |
| 476 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, | 476 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, |
| 477 config.ProcessServerHello(msg, 0, version, supported_versions, | 477 config.ProcessServerHello(msg, 0, version, supported_versions, |
| 478 &cached, &out_params, &error_details)); | 478 &cached, &out_params, &error_details)); |
| 479 EXPECT_EQ("server hello missing server nonce", error_details); | 479 EXPECT_EQ("server hello missing server nonce", error_details); |
| 480 } | 480 } |
| 481 | 481 |
| 482 } // namespace test | 482 } // namespace test |
| 483 } // namespace net | 483 } // namespace net |
| OLD | NEW |