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

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

Issue 2397513002: Conversion of a QUIC method to an async signature and resulting fallout. No functional change inten… (Closed)
Patch Set: Add NET_EXPORT_PRIVATE Created 4 years, 2 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/core/quic_crypto_server_stream_test.cc ('k') | net/quic/test_tools/crypto_test_utils_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/test_tools/crypto_test_utils.cc
diff --git a/net/quic/test_tools/crypto_test_utils.cc b/net/quic/test_tools/crypto_test_utils.cc
index 1e1bda42c5edf571eaf0eb4461bd1053425b02d4..ab907cdbbc1b4efc35551b538032e35dc02ea485 100644
--- a/net/quic/test_tools/crypto_test_utils.cc
+++ b/net/quic/test_tools/crypto_test_utils.cc
@@ -275,7 +275,7 @@ namespace {
// This class is used by GenerateFullCHLO() to extract SCID and STK from
// REJ/SREJ and to construct a full CHLO with these fields and given inchoate
// CHLO.
-class FullChloGenerator : public ValidateClientHelloResultCallback {
+class FullChloGenerator {
public:
FullChloGenerator(QuicCryptoServerConfig* crypto_config,
IPAddress server_ip,
@@ -292,36 +292,77 @@ class FullChloGenerator : public ValidateClientHelloResultCallback {
compressed_certs_cache_(compressed_certs_cache),
out_(out) {}
- void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result,
- std::unique_ptr<ProofSource::Details> /* details */) override {
- QuicCryptoNegotiatedParameters params;
- string error_details;
- DiversificationNonce diversification_nonce;
- CryptoHandshakeMessage rej;
+ class ValidateClientHelloCallback : public ValidateClientHelloResultCallback {
+ public:
+ explicit ValidateClientHelloCallback(FullChloGenerator* generator)
+ : generator_(generator) {}
+ void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result,
+ std::unique_ptr<ProofSource::Details> /* details */) override {
+ generator_->ValidateClientHelloDone(std::move(result));
+ }
+
+ private:
+ FullChloGenerator* generator_;
+ };
+
+ std::unique_ptr<ValidateClientHelloCallback>
+ GetValidateClientHelloCallback() {
+ return std::unique_ptr<ValidateClientHelloCallback>(
+ new ValidateClientHelloCallback(this));
+ }
+
+ private:
+ void ValidateClientHelloDone(
+ scoped_refptr<ValidateClientHelloResultCallback::Result> result) {
+ result_ = result;
crypto_config_->ProcessClientHello(
- result, /*reject_only=*/false, /*connection_id=*/1, server_ip_,
+ result_, /*reject_only=*/false, /*connection_id=*/1, server_ip_,
client_addr_, AllSupportedVersions().front(), AllSupportedVersions(),
/*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0,
- clock_, QuicRandom::GetInstance(), compressed_certs_cache_, &params,
- proof_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, &rej,
- &diversification_nonce, &error_details);
+ clock_, QuicRandom::GetInstance(), compressed_certs_cache_, &params_,
+ proof_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize,
+ GetProcessClientHelloCallback());
+ }
+
+ class ProcessClientHelloCallback : public ProcessClientHelloResultCallback {
+ public:
+ explicit ProcessClientHelloCallback(FullChloGenerator* generator)
+ : generator_(generator) {}
+ void Run(
+ QuicErrorCode error,
+ const string& error_details,
+ std::unique_ptr<CryptoHandshakeMessage> message,
+ std::unique_ptr<DiversificationNonce> diversification_nonce) override {
+ generator_->ProcessClientHelloDone(std::move(message));
+ }
+
+ private:
+ FullChloGenerator* generator_;
+ };
+
+ std::unique_ptr<ProcessClientHelloCallback> GetProcessClientHelloCallback() {
+ return std::unique_ptr<ProcessClientHelloCallback>(
+ new ProcessClientHelloCallback(this));
+ }
+
+ void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> rej) {
// Verify output is a REJ or SREJ.
- EXPECT_THAT(rej.tag(),
+ EXPECT_THAT(rej->tag(),
testing::AnyOf(testing::Eq(kSREJ), testing::Eq(kREJ)));
- VLOG(1) << "Extract valid STK and SCID from\n" << rej.DebugString();
+ VLOG(1) << "Extract valid STK and SCID from\n" << rej->DebugString();
StringPiece srct;
- ASSERT_TRUE(rej.GetStringPiece(kSourceAddressTokenTag, &srct));
+ ASSERT_TRUE(rej->GetStringPiece(kSourceAddressTokenTag, &srct));
StringPiece scfg;
- ASSERT_TRUE(rej.GetStringPiece(kSCFG, &scfg));
+ ASSERT_TRUE(rej->GetStringPiece(kSCFG, &scfg));
std::unique_ptr<CryptoHandshakeMessage> server_config(
CryptoFramer::ParseMessage(scfg));
StringPiece scid;
ASSERT_TRUE(server_config->GetStringPiece(kSCID, &scid));
- *out_ = result->client_hello;
+ *out_ = result_->client_hello;
out_->SetStringPiece(kSCID, scid);
out_->SetStringPiece(kSourceAddressTokenTag, srct);
uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting();
@@ -336,7 +377,11 @@ class FullChloGenerator : public ValidateClientHelloResultCallback {
QuicCryptoProof* proof_;
QuicCompressedCertsCache* compressed_certs_cache_;
CryptoHandshakeMessage* out_;
+
+ QuicCryptoNegotiatedParameters params_;
+ scoped_refptr<ValidateClientHelloResultCallback::Result> result_;
};
+
} // namespace
// static
@@ -412,18 +457,21 @@ int CryptoTestUtils::HandshakeWithFakeClient(
client_conn, client_session.GetCryptoStream(), server_conn, server,
async_channel_id_source);
- CompareClientAndServerKeys(client_session.GetCryptoStream(), server);
-
- if (options.channel_id_enabled) {
- std::unique_ptr<ChannelIDKey> channel_id_key;
- QuicAsyncStatus status = crypto_config.channel_id_source()->GetChannelIDKey(
- server_id.host(), &channel_id_key, nullptr);
- EXPECT_EQ(QUIC_SUCCESS, status);
- EXPECT_EQ(channel_id_key->SerializeKey(),
- server->crypto_negotiated_params().channel_id);
- EXPECT_EQ(
- options.channel_id_source_async,
- client_session.GetCryptoStream()->WasChannelIDSourceCallbackRun());
+ if (server->handshake_confirmed() && server->encryption_established()) {
+ CompareClientAndServerKeys(client_session.GetCryptoStream(), server);
+
+ if (options.channel_id_enabled) {
+ std::unique_ptr<ChannelIDKey> channel_id_key;
+ QuicAsyncStatus status =
+ crypto_config.channel_id_source()->GetChannelIDKey(
+ server_id.host(), &channel_id_key, nullptr);
+ EXPECT_EQ(QUIC_SUCCESS, status);
+ EXPECT_EQ(channel_id_key->SerializeKey(),
+ server->crypto_negotiated_params().channel_id);
+ EXPECT_EQ(
+ options.channel_id_source_async,
+ client_session.GetCryptoStream()->WasChannelIDSourceCallbackRun());
+ }
}
return client_session.GetCryptoStream()->num_sent_client_hellos();
@@ -964,11 +1012,11 @@ void CryptoTestUtils::GenerateFullCHLO(
QuicCompressedCertsCache* compressed_certs_cache,
CryptoHandshakeMessage* out) {
// Pass a inchoate CHLO.
+ FullChloGenerator generator(crypto_config, server_ip, client_addr, clock,
+ proof, compressed_certs_cache, out);
crypto_config->ValidateClientHello(
inchoate_chlo, client_addr.address(), server_ip, version, clock, proof,
- std::unique_ptr<FullChloGenerator>(
- new FullChloGenerator(crypto_config, server_ip, client_addr, clock,
- proof, compressed_certs_cache, out)));
+ generator.GetValidateClientHelloCallback());
}
} // namespace test
« no previous file with comments | « net/quic/core/quic_crypto_server_stream_test.cc ('k') | net/quic/test_tools/crypto_test_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698