Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Unified Diff: net/quic/test_tools/crypto_test_utils_test.cc

Issue 2181773002: Add a test helper method to construct a full CHLO. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@127821412
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/test_tools/crypto_test_utils_test.cc
diff --git a/net/quic/test_tools/crypto_test_utils_test.cc b/net/quic/test_tools/crypto_test_utils_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fe7aee5dff8cc29616a4868e74582129a7b7eb7e
--- /dev/null
+++ b/net/quic/test_tools/crypto_test_utils_test.cc
@@ -0,0 +1,122 @@
+#include "net/quic/test_tools/crypto_test_utils.h"
Zhongyi Shi 2016/07/25 22:33:48 Add the license header?
Ryan Hamilton 2016/07/25 23:06:45 Done in final.
+
+#include "net/quic/crypto/crypto_server_config_protobuf.h"
+#include "net/quic/quic_utils.h"
+#include "net/quic/test_tools/mock_clock.h"
+#include "net/test/gtest_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using std::string;
+
+namespace net {
+namespace test {
+
+class ShloVerifier : public ValidateClientHelloResultCallback {
+ public:
+ ShloVerifier(QuicCryptoServerConfig* crypto_config,
+ IPAddress server_ip,
+ IPEndPoint client_addr,
+ const QuicClock* clock,
+ QuicCryptoProof* proof,
+ QuicCompressedCertsCache* compressed_certs_cache)
+ : crypto_config_(crypto_config),
+ server_ip_(server_ip),
+ client_addr_(client_addr),
+ clock_(clock),
+ proof_(proof),
+ compressed_certs_cache_(compressed_certs_cache) {}
+
+ // Verify that the output message is a SHLO.
+ void RunImpl(
+ const CryptoHandshakeMessage& chlo,
+ const ValidateClientHelloResultCallback::Result& result) override {
+ QuicCryptoNegotiatedParameters params;
+ string error_details;
+ DiversificationNonce diversification_nonce;
+ CryptoHandshakeMessage out;
+ crypto_config_->ProcessClientHello(
+ result, /*reject_only=*/false, /*connection_id=*/1, server_ip_,
+ client_addr_, QuicSupportedVersions().front(), QuicSupportedVersions(),
+ /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0,
+ clock_, QuicRandom::GetInstance(), compressed_certs_cache_, &params,
+ proof_, &out, &diversification_nonce, &error_details);
+ // Verify output is a SHLO.
+ EXPECT_EQ(out.tag(), kSHLO) << "Fail to pass validation. Get "
+ << out.DebugString();
+ }
+
+ protected:
+ QuicCryptoServerConfig* crypto_config_;
+ IPAddress server_ip_;
+ IPEndPoint client_addr_;
+ const QuicClock* clock_;
+ QuicCryptoProof* proof_;
+ QuicCompressedCertsCache* compressed_certs_cache_;
+};
+
+TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) {
+ MockClock clock;
+ QuicCryptoServerConfig crypto_config(
+ QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(),
+ CryptoTestUtils::ProofSourceForTesting());
+ IPAddress server_ip;
+ IPEndPoint client_addr(IPAddress::IPv4Localhost(), 1);
+ QuicCryptoProof proof;
+ QuicCompressedCertsCache compressed_certs_cache(
+ QuicCompressedCertsCache::kQuicCompressedCertsCacheSize);
+ CryptoHandshakeMessage full_chlo;
+
+ QuicCryptoServerConfig::ConfigOptions old_config_options;
+ old_config_options.id = "old-config-id";
+ delete crypto_config.AddDefaultConfig(QuicRandom::GetInstance(),
+ &clock, old_config_options);
+ QuicCryptoServerConfig::ConfigOptions new_config_options;
+ std::unique_ptr<QuicServerConfigProtobuf> primary_config(
+ crypto_config.GenerateConfig(QuicRandom::GetInstance(), &clock,
+ new_config_options));
+ primary_config->set_primary_time(clock.WallNow().ToUNIXSeconds());
+ std::unique_ptr<CryptoHandshakeMessage> msg(
+ crypto_config.AddConfig(primary_config.get(), clock.WallNow()));
+ StringPiece orbit;
+ ASSERT_TRUE(msg->GetStringPiece(kORBT, &orbit));
+ string nonce;
+ CryptoUtils::GenerateNonce(
+ clock.WallNow(), QuicRandom::GetInstance(),
+ StringPiece(reinterpret_cast<const char*>(orbit.data()),
+ sizeof(orbit.size())),
+ &nonce);
+ string nonce_hex = "#" + QuicUtils::HexEncode(nonce);
+
+ char public_value[32];
+ memset(public_value, 42, sizeof(public_value));
+ string pub_hex =
+ "#" + QuicUtils::HexEncode(public_value, sizeof(public_value));
+
+ QuicVersion version(QuicSupportedVersions().front());
+ // clang-format off
+ CryptoHandshakeMessage inchoate_chlo = CryptoTestUtils::Message(
+ "CHLO",
+ "PDMD", "X509",
+ "AEAD", "AESG",
+ "KEXS", "C255",
+ "COPT", "SREJ",
+ "PUBS", pub_hex.c_str(),
+ "NONC", nonce_hex.c_str(),
+ "VER\0", QuicUtils::TagToString(QuicVersionToQuicTag(version)).c_str(),
+ "$padding", static_cast<int>(kClientHelloMinimumSize),
+ nullptr);
+ // clang-format on
+
+ CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_ip,
+ client_addr, version, &clock, &proof,
+ &compressed_certs_cache, &full_chlo);
+ // Verify that full_chlo can pass crypto_config's verification.
+ crypto_config.ValidateClientHello(
+ full_chlo, client_addr.address(), server_ip, version, &clock, &proof,
+ new ShloVerifier(&crypto_config, server_ip, client_addr, &clock, &proof,
+ &compressed_certs_cache));
+}
+
+} // namespace test
+} // namespace net
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698