Index: net/quic/crypto/crypto_server_test.cc |
diff --git a/net/quic/crypto/crypto_server_test.cc b/net/quic/crypto/crypto_server_test.cc |
index f3738ffea424df4d8e16624c0334409f9eda30e2..6844058dec4419b2a27bbee1a63f96c4f74c342c 100644 |
--- a/net/quic/crypto/crypto_server_test.cc |
+++ b/net/quic/crypto/crypto_server_test.cc |
@@ -50,8 +50,7 @@ class CryptoServerTest : public ::testing::Test { |
virtual void SetUp() { |
scoped_ptr<CryptoHandshakeMessage> msg( |
- config_.AddDefaultConfig(rand_, &clock_, |
- config_options_)); |
+ config_.AddDefaultConfig(rand_, &clock_, config_options_)); |
StringPiece orbit; |
CHECK(msg->GetStringPiece(kORBT, &orbit)); |
@@ -65,15 +64,21 @@ class CryptoServerTest : public ::testing::Test { |
nonce_hex_ = "#" + base::HexEncode(nonce_str.data(), nonce_str.size()); |
pub_hex_ = "#" + base::HexEncode(public_value, sizeof(public_value)); |
- CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( |
- "CHLO", |
- "AEAD", "AESG", |
- "KEXS", "C255", |
- "PUBS", pub_hex_.c_str(), |
- "NONC", nonce_hex_.c_str(), |
- "VER\0", client_version_.data(), |
- "$padding", static_cast<int>(kClientHelloMinimumSize), |
- NULL); |
+ CryptoHandshakeMessage client_hello = |
+ CryptoTestUtils::Message("CHLO", |
+ "AEAD", |
+ "AESG", |
+ "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); |
// The message should be rejected because the source-address token is |
// missing. |
@@ -154,9 +159,8 @@ class CryptoServerTest : public ::testing::Test { |
EXPECT_TRUE(called); |
} |
- void RunValidate( |
- const CryptoHandshakeMessage& message, |
- ValidateClientHelloResultCallback* cb) { |
+ void RunValidate(const CryptoHandshakeMessage& message, |
+ ValidateClientHelloResultCallback* cb) { |
config_.ValidateClientHello(message, client_address_, &clock_, cb); |
} |
@@ -171,7 +175,9 @@ class CryptoServerTest : public ::testing::Test { |
const CryptoHandshakeMessage& message, |
bool* called) { |
config_.ValidateClientHello( |
- message, client_address_, &clock_, |
+ message, |
+ client_address_, |
+ &clock_, |
new ValidateCallback(this, false, error_substr, called)); |
} |
@@ -180,16 +186,23 @@ class CryptoServerTest : public ::testing::Test { |
bool should_succeed, |
const char* error_substr) { |
string error_details; |
- QuicErrorCode error = config_.ProcessClientHello( |
- result, 1 /* ConnectionId */, client_address_, |
- supported_versions_.front(), supported_versions_, |
- kInitialFlowControlWindowForTest, &clock_, rand_, ¶ms_, &out_, |
- &error_details); |
+ QuicErrorCode error = |
+ config_.ProcessClientHello(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) |
- << "Message failed with error " << error_details << ": " |
- << message.DebugString(); |
+ ASSERT_EQ(error, QUIC_NO_ERROR) << "Message failed with error " |
+ << error_details << ": " |
+ << message.DebugString(); |
} else { |
ASSERT_NE(error, QUIC_NO_ERROR) |
<< "Message didn't fail: " << message.DebugString(); |
@@ -214,7 +227,8 @@ class CryptoServerTest : public ::testing::Test { |
string GenerateNonce() { |
string nonce; |
CryptoUtils::GenerateNonce( |
- clock_.WallNow(), rand_, |
+ clock_.WallNow(), |
+ rand_, |
StringPiece(reinterpret_cast<const char*>(orbit_), sizeof(orbit_)), |
&nonce); |
return nonce; |
@@ -240,23 +254,17 @@ class CryptoServerTest : public ::testing::Test { |
TEST_F(CryptoServerTest, BadSNI) { |
static const char* kBadSNIs[] = { |
- "", |
- "foo", |
- "#00", |
- "#ff00", |
- "127.0.0.1", |
- "ffee::1", |
+ "", "foo", "#00", "#ff00", "127.0.0.1", "ffee::1", |
}; |
- string client_version = QuicUtils::TagToString( |
- QuicVersionToQuicTag(supported_versions_.front())); |
+ 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)); |
+ ShouldFailMentioning( |
+ "SNI", |
+ InchoateClientHello( |
+ "CHLO", "SNI", kBadSNIs[i], "VER\0", client_version.data(), NULL)); |
} |
} |
@@ -264,18 +272,26 @@ TEST_F(CryptoServerTest, BadSNI) { |
TEST_F(CryptoServerTest, DISABLED_DefaultCert) { |
// Check that the server replies with a default certificate when no SNI is |
// specified. |
- ShouldSucceed(InchoateClientHello( |
- "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(), |
- "$padding", static_cast<int>(kClientHelloMinimumSize), |
- "PDMD", "X509", |
- "VER\0", client_version_.data(), |
- NULL)); |
+ ShouldSucceed(InchoateClientHello("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(), |
+ "$padding", |
+ static_cast<int>(kClientHelloMinimumSize), |
+ "PDMD", |
+ "X509", |
+ "VER\0", |
+ client_version_.data(), |
+ NULL)); |
StringPiece cert, proof; |
EXPECT_TRUE(out_.GetStringPiece(kCertificateTag, &cert)); |
@@ -285,44 +301,36 @@ TEST_F(CryptoServerTest, DISABLED_DefaultCert) { |
} |
TEST_F(CryptoServerTest, TooSmall) { |
- ShouldFailMentioning("too small", CryptoTestUtils::Message( |
- "CHLO", |
- "VER\0", client_version_.data(), |
- NULL)); |
+ ShouldFailMentioning( |
+ "too small", |
+ CryptoTestUtils::Message("CHLO", "VER\0", client_version_.data(), NULL)); |
} |
TEST_F(CryptoServerTest, BadSourceAddressToken) { |
// Invalid source-address tokens should be ignored. |
static const char* kBadSourceAddressTokens[] = { |
- "", |
- "foo", |
- "#0000", |
- "#0000000000000000000000000000000000000000", |
+ "", "foo", "#0000", "#0000000000000000000000000000000000000000", |
}; |
for (size_t i = 0; i < arraysize(kBadSourceAddressTokens); i++) { |
- ShouldSucceed(InchoateClientHello( |
- "CHLO", |
- "STK", kBadSourceAddressTokens[i], |
- "VER\0", client_version_.data(), |
- NULL)); |
+ ShouldSucceed(InchoateClientHello("CHLO", |
+ "STK", |
+ kBadSourceAddressTokens[i], |
+ "VER\0", |
+ client_version_.data(), |
+ NULL)); |
} |
} |
TEST_F(CryptoServerTest, BadClientNonce) { |
// Invalid nonces should be ignored. |
static const char* kBadNonces[] = { |
- "", |
- "#0000", |
- "#0000000000000000000000000000000000000000", |
+ "", "#0000", "#0000000000000000000000000000000000000000", |
}; |
for (size_t i = 0; i < arraysize(kBadNonces); i++) { |
ShouldSucceed(InchoateClientHello( |
- "CHLO", |
- "NONC", kBadNonces[i], |
- "VER\0", client_version_.data(), |
- NULL)); |
+ "CHLO", "NONC", kBadNonces[i], "VER\0", client_version_.data(), NULL)); |
} |
} |
@@ -333,28 +341,35 @@ TEST_F(CryptoServerTest, DowngradeAttack) { |
} |
// Set the client's preferred version to a supported version that |
// is not the "current" version (supported_versions_.front()). |
- string bad_version = QuicUtils::TagToString( |
- QuicVersionToQuicTag(supported_versions_.back())); |
+ string bad_version = |
+ QuicUtils::TagToString(QuicVersionToQuicTag(supported_versions_.back())); |
- ShouldFailMentioning("Downgrade", InchoateClientHello( |
- "CHLO", |
- "VER\0", bad_version.data(), |
- NULL)); |
+ ShouldFailMentioning( |
+ "Downgrade", |
+ InchoateClientHello("CHLO", "VER\0", bad_version.data(), NULL)); |
} |
TEST_F(CryptoServerTest, ReplayProtection) { |
// This tests that disabling replay protection works. |
- 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); |
+ 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. |
@@ -414,7 +429,6 @@ TEST(CryptoServerConfigGenerationTest, SCIDVaries) { |
EXPECT_NE(scid_a, scid_b); |
} |
- |
TEST(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { |
MockRandom rand_a; |
const QuicCryptoServerConfig::ConfigOptions options; |
@@ -451,16 +465,14 @@ class CryptoServerTestNoConfig : public CryptoServerTest { |
}; |
TEST_F(CryptoServerTestNoConfig, DontCrash) { |
- ShouldFailMentioning("No config", InchoateClientHello( |
- "CHLO", |
- "VER\0", client_version_.data(), |
- NULL)); |
+ ShouldFailMentioning( |
+ "No config", |
+ InchoateClientHello("CHLO", "VER\0", client_version_.data(), NULL)); |
} |
class AsyncStrikeServerVerificationTest : public CryptoServerTest { |
protected: |
- AsyncStrikeServerVerificationTest() { |
- } |
+ AsyncStrikeServerVerificationTest() {} |
virtual void SetUp() { |
const string kOrbit = "12345678"; |
@@ -469,7 +481,7 @@ class AsyncStrikeServerVerificationTest : public CryptoServerTest { |
10000, // strike_register_max_entries |
static_cast<uint32>(clock_.WallNow().ToUNIXSeconds()), |
60, // strike_register_window_secs |
- reinterpret_cast<const uint8 *>(kOrbit.data()), |
+ reinterpret_cast<const uint8*>(kOrbit.data()), |
StrikeRegister::NO_STARTUP_PERIOD_NEEDED); |
config_.SetStrikeRegisterClient(strike_register_client_); |
CryptoServerTest::SetUp(); |
@@ -481,17 +493,25 @@ class AsyncStrikeServerVerificationTest : public CryptoServerTest { |
TEST_F(AsyncStrikeServerVerificationTest, AsyncReplayProtection) { |
// This tests async validation with a strike register works. |
- 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); |
+ 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); |
// Clear the message tag. |
out_.set_tag(0); |
@@ -525,17 +545,25 @@ TEST_F(AsyncStrikeServerVerificationTest, AsyncReplayProtection) { |
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); |
+ 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. |