#include "net/quic/crypto/crypto_utils.h"
#include "net/quic/crypto/quic_crypto_server_config.h"
#include "net/quic/crypto/quic_random.h"
+#include "net/quic/quic_socket_address_coder.h"
#include "net/quic/quic_utils.h"
#include "net/quic/test_tools/crypto_test_utils.h"
#include "net/quic/test_tools/delayed_verify_strike_register_client.h"
config_(QuicCryptoServerConfig::TESTING, rand_) {
config_.SetProofSource(CryptoTestUtils::ProofSourceForTesting());
supported_versions_ = QuicSupportedVersions();
+ client_version_ = QuicUtils::TagToString(
+ QuicVersionToQuicTag(supported_versions_.front()));
}
virtual void SetUp() {
"KEXS", "C255",
"PUBS", pub_hex_.c_str(),
"NONC", nonce_hex_.c_str(),
+ "VER\0", client_version_.data(),
"$padding", static_cast<int>(kClientHelloMinimumSize),
NULL);
ShouldSucceed(client_hello);
bool* called_;
};
+ void CheckServerHello(const CryptoHandshakeMessage& server_hello) {
+ const QuicTag* versions;
+ size_t num_versions;
+ server_hello.GetTaglist(kVER, &versions, &num_versions);
+ ASSERT_EQ(QuicSupportedVersions().size(), num_versions);
+ for (size_t i = 0; i < num_versions; ++i) {
+ EXPECT_EQ(QuicVersionToQuicTag(QuicSupportedVersions()[i]), versions[i]);
+ }
+
+ StringPiece address;
+ ASSERT_TRUE(server_hello.GetStringPiece(kCADR, &address));
+ QuicSocketAddressCoder decoder;
+ ASSERT_TRUE(decoder.Decode(address.data(), address.size()));
+ EXPECT_EQ(client_address_.address(), decoder.ip());
+ EXPECT_EQ(client_address_.port(), decoder.port());
+ }
+
void ShouldSucceed(const CryptoHandshakeMessage& message) {
bool called = false;
RunValidate(message, new ValidateCallback(this, true, "", &called));
const char* error_substr) {
string error_details;
QuicErrorCode error = config_.ProcessClientHello(
- result, 1 /* GUID */, client_address_,
- supported_versions_.front(), supported_versions_, &clock_, rand_,
- ¶ms_, &out_, &error_details);
+ result, 1 /* ConnectionId */, client_address_,
+ supported_versions_.front(), supported_versions_,
+ kInitialFlowControlWindowForTest, &clock_, rand_, ¶ms_, &out_,
+ &error_details);
if (should_succeed) {
ASSERT_EQ(error, QUIC_NO_ERROR)
MockClock clock_;
const IPEndPoint client_address_;
QuicVersionVector supported_versions_;
+ string client_version_;
QuicCryptoServerConfig config_;
QuicCryptoServerConfig::ConfigOptions config_options_;
QuicCryptoNegotiatedParameters params_;
"ffee::1",
};
+ string client_version = QuicUtils::TagToString(
+ QuicVersionToQuicTag(supported_versions_.front()));
+
for (size_t i = 0; i < arraysize(kBadSNIs); i++) {
ShouldFailMentioning("SNI", InchoateClientHello(
"CHLO",
"SNI", kBadSNIs[i],
+ "VER\0", client_version.data(),
NULL));
}
}
"NONC", nonce_hex_.c_str(),
"$padding", static_cast<int>(kClientHelloMinimumSize),
"PDMD", "X509",
+ "VER\0", client_version_.data(),
NULL));
StringPiece cert, proof;
TEST_F(CryptoServerTest, TooSmall) {
ShouldFailMentioning("too small", CryptoTestUtils::Message(
"CHLO",
+ "VER\0", client_version_.data(),
NULL));
}
ShouldSucceed(InchoateClientHello(
"CHLO",
"STK", kBadSourceAddressTokens[i],
+ "VER\0", client_version_.data(),
NULL));
}
}
ShouldSucceed(InchoateClientHello(
"CHLO",
"NONC", kBadNonces[i],
+ "VER\0", client_version_.data(),
NULL));
}
}
}
// Set the client's preferred version to a supported version that
// is not the "current" version (supported_versions_.front()).
- string client_version = QuicUtils::TagToString(
+ string bad_version = QuicUtils::TagToString(
QuicVersionToQuicTag(supported_versions_.back()));
ShouldFailMentioning("Downgrade", InchoateClientHello(
"CHLO",
- "VER\0", client_version.data(),
+ "VER\0", bad_version.data(),
NULL));
}
"#004b5453", srct_hex_.c_str(),
"PUBS", pub_hex_.c_str(),
"NONC", nonce_hex_.c_str(),
+ "VER\0", client_version_.data(),
"$padding", static_cast<int>(kClientHelloMinimumSize),
NULL);
ShouldSucceed(msg);
ShouldSucceed(msg);
// The message should be accepted now.
ASSERT_EQ(kSHLO, out_.tag());
+ CheckServerHello(out_);
ShouldSucceed(msg);
// The message should accepted twice when replay protection is off.
ASSERT_EQ(kSHLO, out_.tag());
- const QuicTag* versions;
- size_t num_versions;
- out_.GetTaglist(kVER, &versions, &num_versions);
- ASSERT_EQ(QuicSupportedVersions().size(), num_versions);
- for (size_t i = 0; i < num_versions; ++i) {
- EXPECT_EQ(QuicVersionToQuicTag(QuicSupportedVersions()[i]), versions[i]);
- }
+ CheckServerHello(out_);
}
TEST(CryptoServerConfigGenerationTest, Determinism) {
TEST_F(CryptoServerTestNoConfig, DontCrash) {
ShouldFailMentioning("No config", InchoateClientHello(
"CHLO",
+ "VER\0", client_version_.data(),
NULL));
}
"#004b5453", srct_hex_.c_str(),
"PUBS", pub_hex_.c_str(),
"NONC", nonce_hex_.c_str(),
+ "VER\0", client_version_.data(),
"$padding", static_cast<int>(kClientHelloMinimumSize),
NULL);
EXPECT_EQ(kREJ, out_.tag());
}
+TEST_F(CryptoServerTest, InitialFlowControlWindow) {
+ // Test that the SHLO contains a value for initial flow control window.
+ CryptoHandshakeMessage msg = CryptoTestUtils::Message(
+ "CHLO",
+ "AEAD", "AESG",
+ "KEXS", "C255",
+ "SCID", scid_hex_.c_str(),
+ "#004b5453", srct_hex_.c_str(),
+ "PUBS", pub_hex_.c_str(),
+ "NONC", nonce_hex_.c_str(),
+ "VER\0", client_version_.data(),
+ "$padding", static_cast<int>(kClientHelloMinimumSize),
+ NULL);
+ ShouldSucceed(msg);
+ // The message should be rejected because the strike-register is still
+ // quiescent.
+ ASSERT_EQ(kREJ, out_.tag());
+ config_.set_replay_protection(false);
+
+ // The message should be accepted now.
+ ShouldSucceed(msg);
+ ASSERT_EQ(kSHLO, out_.tag());
+ CheckServerHello(out_);
+
+ // Ensure that the kIFCW tag is populated correctly.
+ QuicTag ifcw;
+ EXPECT_EQ(QUIC_NO_ERROR, out_.GetUint32(kIFCW, &ifcw));
+ EXPECT_EQ(kInitialFlowControlWindowForTest, ifcw);
+}
+
} // namespace test
} // namespace net