Skip to content

Commit ef66c81

Browse files
jbeshayfacebook-github-bot
authored andcommitted
Add verify_server_cert flag to hq CLI for server certificate verification
Summary: This change adds a new command line flag `--verify_server_cert` to the hq CLI tool for MVFST that allows enabling server certificate verification. The flag defaults to `false` to maintain backward compatibility. ## Changes Made: 1. Added `DEFINE_bool(verify_server_cert, false, ...)` flag to HQCommandLine.cpp 2. Added `bool verifyServerCert` field to HQToolClientParams struct in HQCommandLine.h 3. Modified HQClient::initializeQuicClient() to conditionally bypass InsecureVerifier when the flag is set to true 4. Updated command line processing to propagate the flag value through HQParams ## Behavior: - When `--verify_server_cert=false` (default): Uses InsecureVerifier, bypassing certificate validation (existing behavior) - When `--verify_server_cert=true`: Omits InsecureVerifier, enabling proper certificate validation The implementation maintains backward compatibility by defaulting to false, preserving the existing insecure behavior unless explicitly enabled. Reviewed By: lnicco Differential Revision: D78852031 fbshipit-source-id: 3178acfd2a15ec0007a1e61d6f5d3363d55c31d1
1 parent 287360f commit ef66c81

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

proxygen/httpserver/samples/hq/HQClient.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,22 @@ void HQClient::connectError(const quic::QuicError& error) {
276276

277277
void HQClient::initializeQuicClient() {
278278
auto sock = std::make_unique<FollyQuicAsyncUDPSocket>(qEvb_);
279-
auto client = std::make_shared<quic::QuicClientTransport>(
280-
qEvb_,
281-
std::move(sock),
279+
auto handshakeContextBuilder =
282280
quic::FizzClientQuicHandshakeContext::Builder()
283281
.setFizzClientContext(
284282
createFizzClientContext(params_, params_.earlyData))
285-
.setCertificateVerifier(
286-
std::make_unique<
287-
proxygen::InsecureVerifierDangerousDoNotUseInProduction>())
288-
.setPskCache(params_.pskCache)
289-
.build());
283+
.setPskCache(params_.pskCache);
284+
285+
if (!params_.verifyServerCert) {
286+
handshakeContextBuilder =
287+
std::move(handshakeContextBuilder)
288+
.setCertificateVerifier(
289+
std::make_unique<
290+
proxygen::InsecureVerifierDangerousDoNotUseInProduction>());
291+
}
292+
293+
auto client = std::make_shared<quic::QuicClientTransport>(
294+
qEvb_, std::move(sock), std::move(handshakeContextBuilder).build());
290295
client->setPacingTimer(pacingTimer_);
291296
client->setHostname(params_.host);
292297
client->addNewPeerAddress(params_.remoteAddress.value());

proxygen/httpserver/samples/hq/HQCommandLine.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ DEFINE_bool(pacing, false, "Whether to enable pacing on HQServer");
7878
DEFINE_int32(pacing_timer_tick_interval_us, 200, "Pacing timer resolution");
7979
DEFINE_string(psk_file, "", "Cache file to use for QUIC psks");
8080
DEFINE_bool(early_data, false, "Whether to use 0-rtt");
81+
DEFINE_bool(verify_server_cert,
82+
false,
83+
"Whether HQClient should verify server certificates");
8184
DEFINE_uint32(quic_batching_mode,
8285
static_cast<uint32_t>(quic::QuicBatchingMode::BATCHING_MODE_NONE),
8386
"QUIC batching mode");
@@ -377,6 +380,7 @@ void initializeHttpClientSettings(HQToolClientParams& hqParams) {
377380
folly::split(',', FLAGS_gap_ms, hqParams.requestGaps);
378381

379382
hqParams.earlyData = FLAGS_early_data;
383+
hqParams.verifyServerCert = FLAGS_verify_server_cert;
380384
hqParams.migrateClient = FLAGS_migrate_client;
381385
hqParams.txnTimeout = std::chrono::milliseconds(FLAGS_txn_timeout);
382386
hqParams.httpVersion.parse(FLAGS_httpversion);

proxygen/httpserver/samples/hq/HQCommandLine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct HQToolClientParams : public HQBaseParams {
2525

2626
folly::Optional<folly::SocketAddress> remoteAddress;
2727
bool earlyData;
28+
bool verifyServerCert;
2829
std::chrono::milliseconds connectTimeout;
2930
proxygen::HTTPHeaders httpHeaders;
3031
std::string httpBody;

0 commit comments

Comments
 (0)