diff --git a/quic/api/test/IoBufQuicBatchTest.cpp b/quic/api/test/IoBufQuicBatchTest.cpp index dc810dc6b..66e041d56 100644 --- a/quic/api/test/IoBufQuicBatchTest.cpp +++ b/quic/api/test/IoBufQuicBatchTest.cpp @@ -56,7 +56,7 @@ void RunTest(int numBatch) { auto batchWriter = std::make_unique(numBatch); folly::SocketAddress peerAddress{"127.0.0.1", 1234}; QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); QuicConnectionStateBase::HappyEyeballsState happyEyeballsState; IOBufQuicBatch ioBufBatch( diff --git a/quic/api/test/QuicPacketSchedulerTest.cpp b/quic/api/test/QuicPacketSchedulerTest.cpp index 248834ed7..9c338af59 100644 --- a/quic/api/test/QuicPacketSchedulerTest.cpp +++ b/quic/api/test/QuicPacketSchedulerTest.cpp @@ -117,7 +117,7 @@ TEST_F(QuicPacketSchedulerTest, NoopScheduler) { TEST_F(QuicPacketSchedulerTest, CryptoPaddingInitialPacket) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); auto connId = getTestConnectionId(); LongHeader longHeader1( LongHeader::Types::Initial, @@ -177,7 +177,7 @@ TEST_F(QuicPacketSchedulerTest, CryptoServerInitialNotPadded) { TEST_F(QuicPacketSchedulerTest, CryptoPaddingRetransmissionClientInitial) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); auto connId = getTestConnectionId(); LongHeader longHeader( LongHeader::Types::Initial, @@ -225,7 +225,7 @@ TEST_F(QuicPacketSchedulerTest, CryptoSchedulerOnlySingleLossFits) { TEST_F(QuicPacketSchedulerTest, CryptoWritePartialLossBuffer) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); auto connId = getTestConnectionId(); LongHeader longHeader( LongHeader::Types::Initial, @@ -313,7 +313,7 @@ TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerStreamNotExists) { TEST_F(QuicPacketSchedulerTest, CloningSchedulerTest) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); FrameScheduler noopScheduler("frame"); ASSERT_FALSE(noopScheduler.hasData()); CloningScheduler cloningScheduler(noopScheduler, conn, "CopyCat", 0); @@ -341,7 +341,7 @@ TEST_F(QuicPacketSchedulerTest, CloningSchedulerTest) { TEST_F(QuicPacketSchedulerTest, WriteOnlyOutstandingPacketsTest) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); FrameScheduler noopScheduler("frame"); ASSERT_FALSE(noopScheduler.hasData()); CloningScheduler cloningScheduler(noopScheduler, conn, "CopyCat", 0); @@ -409,7 +409,7 @@ TEST_F(QuicPacketSchedulerTest, WriteOnlyOutstandingPacketsTest) { TEST_F(QuicPacketSchedulerTest, DoNotCloneProcessedClonedPacket) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); FrameScheduler noopScheduler("frame"); CloningScheduler cloningScheduler(noopScheduler, conn, "CopyCat", 0); // Add two outstanding packets, but then mark the second one processed by @@ -440,7 +440,7 @@ TEST_F(QuicPacketSchedulerTest, DoNotCloneProcessedClonedPacket) { TEST_F(QuicPacketSchedulerTest, DoNotClonePureAck) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); FrameScheduler noopScheduler("frame"); CloningScheduler cloningScheduler(noopScheduler, conn, "CopyCat", 0); // Add two outstanding packets, with second one being pureAck @@ -467,7 +467,7 @@ TEST_F(QuicPacketSchedulerTest, DoNotClonePureAck) { TEST_F(QuicPacketSchedulerTest, CloneSchedulerHasDataIgnoresNonAppData) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); FrameScheduler noopScheduler("frame"); CloningScheduler cloningScheduler(noopScheduler, conn, "CopyCat", 0); EXPECT_FALSE(cloningScheduler.hasData()); @@ -484,7 +484,7 @@ TEST_F(QuicPacketSchedulerTest, CloneSchedulerHasDataIgnoresNonAppData) { TEST_F(QuicPacketSchedulerTest, DoNotCloneHandshake) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); FrameScheduler noopScheduler("frame"); CloningScheduler cloningScheduler(noopScheduler, conn, "CopyCat", 0); // Add two outstanding packets, with second one being handshake @@ -512,7 +512,7 @@ TEST_F(QuicPacketSchedulerTest, DoNotCloneHandshake) { TEST_F(QuicPacketSchedulerTest, CloneSchedulerUseNormalSchedulerFirst) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); MockFrameScheduler mockScheduler; CloningScheduler cloningScheduler(mockScheduler, conn, "Mocker", 0); ShortHeader header( @@ -561,7 +561,7 @@ TEST_F(QuicPacketSchedulerTest, CloneSchedulerUseNormalSchedulerFirst) { TEST_F(QuicPacketSchedulerTest, CloneWillGenerateNewWindowUpdate) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); conn.streamManager->setMaxLocalBidirectionalStreams(10); auto stream = conn.streamManager->createNextBidirectionalStream().value(); FrameScheduler noopScheduler("frame"); @@ -643,7 +643,7 @@ class AckSchedulingTest : public TestWithParam {}; TEST_F(QuicPacketSchedulerTest, AckStateHasAcksToSchedule) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); EXPECT_FALSE(hasAcksToSchedule(conn.ackStates.initialAckState)); EXPECT_FALSE(hasAcksToSchedule(conn.ackStates.handshakeAckState)); EXPECT_FALSE(hasAcksToSchedule(conn.ackStates.appDataAckState)); @@ -661,7 +661,7 @@ TEST_F(QuicPacketSchedulerTest, AckStateHasAcksToSchedule) { TEST_F(QuicPacketSchedulerTest, AckSchedulerHasAcksToSchedule) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); AckScheduler initialAckScheduler( conn, getAckState(conn, PacketNumberSpace::Initial)); AckScheduler handshakeAckScheduler( @@ -685,7 +685,7 @@ TEST_F(QuicPacketSchedulerTest, AckSchedulerHasAcksToSchedule) { TEST_F(QuicPacketSchedulerTest, LargestAckToSend) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); EXPECT_EQ(folly::none, largestAckToSend(conn.ackStates.initialAckState)); EXPECT_EQ(folly::none, largestAckToSend(conn.ackStates.handshakeAckState)); EXPECT_EQ(folly::none, largestAckToSend(conn.ackStates.appDataAckState)); @@ -701,7 +701,7 @@ TEST_F(QuicPacketSchedulerTest, LargestAckToSend) { TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerAllFit) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); conn.streamManager->setMaxLocalBidirectionalStreams(10); conn.flowControlState.peerAdvertisedMaxOffset = 100000; conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiRemote = 100000; @@ -727,7 +727,7 @@ TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerAllFit) { TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerRoundRobin) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); conn.streamManager->setMaxLocalBidirectionalStreams(10); conn.flowControlState.peerAdvertisedMaxOffset = 100000; conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiRemote = 100000; @@ -781,7 +781,7 @@ TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerRoundRobin) { TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerRoundRobinControl) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); conn.streamManager->setMaxLocalBidirectionalStreams(10); conn.flowControlState.peerAdvertisedMaxOffset = 100000; conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiRemote = 100000; @@ -846,7 +846,7 @@ TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerRoundRobinControl) { TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerOneStream) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); conn.streamManager->setMaxLocalBidirectionalStreams(10); conn.flowControlState.peerAdvertisedMaxOffset = 100000; conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiRemote = 100000; @@ -868,7 +868,7 @@ TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerOneStream) { TEST_F(QuicPacketSchedulerTest, StreamFrameSchedulerRemoveOne) { QuicClientConnectionState conn( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); conn.streamManager->setMaxLocalBidirectionalStreams(10); conn.flowControlState.peerAdvertisedMaxOffset = 100000; conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiRemote = 100000; diff --git a/quic/client/QuicClientTransport.cpp b/quic/client/QuicClientTransport.cpp index f66681fa1..b34602192 100644 --- a/quic/client/QuicClientTransport.cpp +++ b/quic/client/QuicClientTransport.cpp @@ -11,8 +11,8 @@ #include #include +#include #include -#include #include #include #include @@ -30,9 +30,11 @@ namespace quic { QuicClientTransport::QuicClientTransport( folly::EventBase* evb, std::unique_ptr socket, + std::shared_ptr handshakeFactory, size_t connectionIdSize) : QuicTransportBase(evb, std::move(socket)), happyEyeballsConnAttemptDelayTimeout_(this) { + DCHECK(handshakeFactory); // TODO(T53612743) Only enforce that the initial destination connection id // is at least kMinInitialDestinationConnIdLength. // All subsequent connection ids should be in between @@ -41,8 +43,8 @@ QuicClientTransport::QuicClientTransport( connectionIdSize == 0 || (connectionIdSize >= kMinInitialDestinationConnIdLength && connectionIdSize <= kMaxConnectionIdSize)); - auto tempConn = std::make_unique( - std::make_shared()); + auto tempConn = + std::make_unique(std::move(handshakeFactory)); clientConn_ = tempConn.get(); conn_ = std::move(tempConn); std::vector connIdData( @@ -891,12 +893,7 @@ void QuicClientTransport::startCryptoHandshake() { conn_->transportParametersEncoded = true; auto handshakeLayer = clientConn_->clientHandshakeLayer; handshakeLayer->connect( - ctx_, - verifier_, - hostname_, - std::move(cachedPsk), - std::move(paramsExtension), - this); + hostname_, std::move(cachedPsk), std::move(paramsExtension), this); auto zeroRttWriteCipher = handshakeLayer->getZeroRttWriteCipher(); auto zeroRttWriteHeaderCipher = handshakeLayer->getZeroRttWriteHeaderCipher(); @@ -1093,14 +1090,6 @@ void QuicClientTransport::start(ConnectionCallback* cb) { CHECK(conn_->peerAddress.isInitialized()); - if (!ctx_) { - ctx_ = std::make_shared(); - } - if (!verifier_) { - verifier_ = std::make_shared( - fizz::VerificationContext::Client); - } - if (conn_->qLogger) { conn_->qLogger->addTransportStateUpdate(kStart); } @@ -1170,16 +1159,6 @@ void QuicClientTransport::setHostname(const std::string& hostname) { hostname_ = hostname; } -void QuicClientTransport::setFizzClientQuicHandshakeContext( - std::shared_ptr ctx) { - ctx_ = std::move(ctx); -} - -void QuicClientTransport::setCertificateVerifier( - std::shared_ptr verifier) { - verifier_ = std::move(verifier); -} - void QuicClientTransport::setPskCache(std::shared_ptr pskCache) { pskCache_ = std::move(pskCache); } diff --git a/quic/client/QuicClientTransport.h b/quic/client/QuicClientTransport.h index 51ba6b784..055ddd45f 100644 --- a/quic/client/QuicClientTransport.h +++ b/quic/client/QuicClientTransport.h @@ -18,6 +18,8 @@ namespace quic { +class ClientHandshakeFactory; + class QuicClientTransport : public QuicTransportBase, public folly::AsyncUDPSocket::ReadCallback, @@ -28,6 +30,7 @@ class QuicClientTransport QuicClientTransport( folly::EventBase* evb, std::unique_ptr socket, + std::shared_ptr handshakeFactory, size_t connectionIdSize = kDefaultConnectionIdSize); ~QuicClientTransport() override; @@ -46,9 +49,10 @@ class QuicClientTransport static std::shared_ptr newClient( folly::EventBase* evb, std::unique_ptr sock, + std::shared_ptr handshakeFactory, size_t connectionIdSize = kDefaultConnectionIdSize) { - auto client = - std::make_shared(evb, std::move(sock), connectionIdSize); + auto client = std::make_shared( + evb, std::move(sock), std::move(handshakeFactory), connectionIdSize); client->setSelfOwning(); return client; } @@ -59,18 +63,6 @@ class QuicClientTransport */ void setHostname(const std::string& hostname); - /** - * Set the client context for fizz. Must be set before start() - */ - void setFizzClientQuicHandshakeContext( - std::shared_ptr ctx); - - /** - * Set a custom certificate verifier. Must be set before start(). - */ - void setCertificateVerifier( - std::shared_ptr verifier); - /** * Supplies a new peer address to use for the connection. This must be called * at least once before start(). @@ -182,8 +174,6 @@ class QuicClientTransport Buf readBuffer_; folly::Optional hostname_; - std::shared_ptr ctx_; - std::shared_ptr verifier_; HappyEyeballsConnAttemptDelayTimeout happyEyeballsConnAttemptDelayTimeout_; bool serverInitialParamsSet_{false}; uint64_t peerAdvertisedInitialMaxData_{0}; diff --git a/quic/client/handshake/ClientHandshake.h b/quic/client/handshake/ClientHandshake.h index 50badee28..e3ad85dfb 100644 --- a/quic/client/handshake/ClientHandshake.h +++ b/quic/client/handshake/ClientHandshake.h @@ -10,9 +10,7 @@ #include #include -#include #include -#include #include #include @@ -45,8 +43,6 @@ class ClientHandshake : public Handshake { * Initiate the handshake with the supplied parameters. */ virtual void connect( - std::shared_ptr context, - std::shared_ptr verifier, folly::Optional hostname, folly::Optional cachedPsk, const std::shared_ptr& diff --git a/quic/client/handshake/FizzClientHandshake.cpp b/quic/client/handshake/FizzClientHandshake.cpp index 034e1ea0c..88f94c250 100644 --- a/quic/client/handshake/FizzClientHandshake.cpp +++ b/quic/client/handshake/FizzClientHandshake.cpp @@ -8,6 +8,7 @@ #include +#include #include namespace quic { @@ -18,26 +19,28 @@ FizzClientHandshake::FizzClientHandshake( : ClientHandshake(cryptoState), fizzContext_(std::move(fizzContext)) {} void FizzClientHandshake::connect( - std::shared_ptr context, - std::shared_ptr verifier, folly::Optional hostname, folly::Optional cachedPsk, const std::shared_ptr& transportParams, HandshakeCallback* callback) { transportParams_ = transportParams; callback_ = callback; - auto ctx = std::make_shared(*context); + auto cryptoFactory = std::make_shared(); - ctx->setFactory(cryptoFactory); + + // Setup context for this handshake. + auto context = std::make_shared( + *fizzContext_->getContext()); + context->setFactory(cryptoFactory); cryptoFactory_ = std::move(cryptoFactory); - ctx->setSupportedCiphers({fizz::CipherSuite::TLS_AES_128_GCM_SHA256}); - ctx->setCompatibilityMode(false); + context->setSupportedCiphers({fizz::CipherSuite::TLS_AES_128_GCM_SHA256}); + context->setCompatibilityMode(false); // Since Draft-17, EOED should not be sent - ctx->setOmitEarlyRecordLayer(true); + context->setOmitEarlyRecordLayer(true); processActions(machine_.processConnect( state_, - std::move(ctx), - std::move(verifier), + std::move(context), + fizzContext_->getCertificateVerifier(), std::move(hostname), std::move(cachedPsk), transportParams)); diff --git a/quic/client/handshake/FizzClientHandshake.h b/quic/client/handshake/FizzClientHandshake.h index 125cc32c9..0e4b3ffab 100644 --- a/quic/client/handshake/FizzClientHandshake.h +++ b/quic/client/handshake/FizzClientHandshake.h @@ -21,8 +21,6 @@ class FizzClientHandshake : public ClientHandshake { std::shared_ptr fizzContext); void connect( - std::shared_ptr context, - std::shared_ptr verifier, folly::Optional hostname, folly::Optional cachedPsk, const std::shared_ptr& diff --git a/quic/client/handshake/FizzClientQuicHandshakeContext.cpp b/quic/client/handshake/FizzClientQuicHandshakeContext.cpp index 8990262d7..bb3c101d9 100644 --- a/quic/client/handshake/FizzClientQuicHandshakeContext.cpp +++ b/quic/client/handshake/FizzClientQuicHandshakeContext.cpp @@ -12,10 +12,30 @@ namespace quic { +FizzClientQuicHandshakeContext::FizzClientQuicHandshakeContext( + std::shared_ptr context, + std::shared_ptr verifier) + : context_(std::move(context)), verifier_(std::move(verifier)) {} + std::unique_ptr FizzClientQuicHandshakeContext::makeClientHandshake( QuicCryptoState& cryptoState) { return std::make_unique(cryptoState, shared_from_this()); } +std::shared_ptr +FizzClientQuicHandshakeContext::Builder::build() { + if (!context_) { + context_ = std::make_shared(); + } + if (!verifier_) { + verifier_ = std::make_shared( + fizz::VerificationContext::Client); + } + + return std::shared_ptr( + new FizzClientQuicHandshakeContext( + std::move(context_), std::move(verifier_))); +} + } // namespace quic diff --git a/quic/client/handshake/FizzClientQuicHandshakeContext.h b/quic/client/handshake/FizzClientQuicHandshakeContext.h index 99d7ce2b0..715aabf32 100644 --- a/quic/client/handshake/FizzClientQuicHandshakeContext.h +++ b/quic/client/handshake/FizzClientQuicHandshakeContext.h @@ -10,6 +10,9 @@ #include +#include +#include + namespace quic { class FizzClientHandshake; @@ -20,6 +23,54 @@ class FizzClientQuicHandshakeContext public: std::unique_ptr makeClientHandshake( QuicCryptoState& cryptoState) override; + + const std::shared_ptr& getContext() + const { + return context_; + } + + const std::shared_ptr& + getCertificateVerifier() const { + return verifier_; + } + + private: + /** + * We make the constructor private so that users have to use the Builder + * facility. This ensures that + * - This will ALWAYS be managed by a shared_ptr, which the implementation + * expects. + * - We can enforce that the internal state of FizzClientContext is always + * sane. + */ + FizzClientQuicHandshakeContext( + std::shared_ptr context, + std::shared_ptr verifier); + + std::shared_ptr context_; + std::shared_ptr verifier_; + + public: + class Builder { + public: + Builder& setFizzClientContext( + std::shared_ptr context) { + context_ = std::move(context); + return *this; + } + + Builder& setCertificateVerifier( + std::shared_ptr verifier) { + verifier_ = std::move(verifier); + return *this; + } + + std::shared_ptr build(); + + private: + std::shared_ptr context_; + std::shared_ptr verifier_; + }; }; } // namespace quic diff --git a/quic/client/handshake/test/ClientHandshakeTest.cpp b/quic/client/handshake/test/ClientHandshakeTest.cpp index 4e1bd0ea6..425b0bd66 100644 --- a/quic/client/handshake/test/ClientHandshakeTest.cpp +++ b/quic/client/handshake/test/ClientHandshakeTest.cpp @@ -56,8 +56,6 @@ class ClientHandshakeTest : public Test, public boost::static_visitor<> { virtual void connect() { handshake->connect( - clientCtx, - verifier, hostname, folly::none, std::make_shared( @@ -81,10 +79,13 @@ class ClientHandshakeTest : public Test, public boost::static_visitor<> { // Fizz is the name of the identity for our server certificate. hostname = "Fizz"; setupClientAndServerContext(); + verifier = std::make_shared(); - handshake = - std::make_shared()->makeClientHandshake( - cryptoState); + handshake = FizzClientQuicHandshakeContext::Builder() + .setFizzClientContext(clientCtx) + .setCertificateVerifier(verifier) + .build() + ->makeClientHandshake(cryptoState); std::vector supportedVersions = {getVersion()}; auto serverTransportParameters = std::make_shared( @@ -348,8 +349,6 @@ class ClientHandshakeCallbackTest : public ClientHandshakeTest { void connect() override { handshake->connect( - clientCtx, - verifier, hostname, folly::none, std::make_shared( @@ -450,8 +449,6 @@ class ClientHandshakeZeroRttTest : public ClientHandshakeTest { void connect() override { handshake->connect( - clientCtx, - verifier, hostname, psk.cachedPsk, std::make_shared( diff --git a/quic/client/test/QuicClientTransportTest.cpp b/quic/client/test/QuicClientTransportTest.cpp index ec4ee2075..7fc012b87 100644 --- a/quic/client/test/QuicClientTransportTest.cpp +++ b/quic/client/test/QuicClientTransportTest.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -72,8 +73,13 @@ class TestingQuicClientTransport : public QuicClientTransport { TestingQuicClientTransport( folly::EventBase* evb, std::unique_ptr socket, + std::shared_ptr handshakeFactory, size_t connIdSize = kDefaultConnectionIdSize) - : QuicClientTransport(evb, std::move(socket), connIdSize) {} + : QuicClientTransport( + evb, + std::move(socket), + std::move(handshakeFactory), + connIdSize) {} ~TestingQuicClientTransport() override { if (destructionCallback_) { @@ -183,6 +189,8 @@ class QuicClientTransportIntegrationTest : public TestWithParam { connected_ = true; })); + clientCtx = createClientContext(); + verifier = createTestCertificateVerifier(); client = createClient(); } @@ -190,21 +198,30 @@ class QuicClientTransportIntegrationTest : public TestWithParam { return GetParam().version; } - std::shared_ptr createClient() { + std::shared_ptr createClientContext() { clientCtx = std::make_shared(); clientCtx->setSupportedAlpns({"h1q-fb"}); clientCtx->setClock(std::make_shared()); + return clientCtx; + } + + std::shared_ptr createClient() { pskCache_ = std::make_shared(); auto sock = std::make_unique(&eventbase_); + auto fizzClientContext = FizzClientQuicHandshakeContext::Builder() + .setFizzClientContext(clientCtx) + .setCertificateVerifier(verifier) + .build(); client = std::make_shared( - &eventbase_, std::move(sock), GetParam().dstConnIdSize); + &eventbase_, + std::move(sock), + std::move(fizzClientContext), + GetParam().dstConnIdSize); client->setSupportedVersions({getVersion()}); client->setCongestionControllerFactory( std::make_shared()); client->setHostname(hostname); - client->setFizzClientQuicHandshakeContext(clientCtx); - client->setCertificateVerifier(createTestCertificateVerifier()); client->addNewPeerAddress(serverAddr); client->setPskCache(pskCache_); return client; @@ -317,6 +334,7 @@ class QuicClientTransportIntegrationTest : public TestWithParam { std::shared_ptr client; std::shared_ptr serverCtx; std::shared_ptr clientCtx; + std::shared_ptr verifier; std::shared_ptr pskCache_; std::shared_ptr server_; bool connected_{false}; @@ -449,6 +467,9 @@ TEST_P(QuicClientTransportIntegrationTest, ALPNTest) { } TEST_P(QuicClientTransportIntegrationTest, TLSAlert) { + verifier = nullptr; + client = createClient(); + auto qLogger = std::make_shared(VantagePoint::CLIENT); client->getNonConstConn().qLogger = qLogger; EXPECT_CALL(clientConnCallback, onConnectionError(_)) @@ -465,7 +486,6 @@ TEST_P(QuicClientTransportIntegrationTest, TLSAlert) { ASSERT_EQ(client->getAppProtocol(), folly::none); - client->setCertificateVerifier(nullptr); client->start(&clientConnCallback); eventbase_.loopForever(); } @@ -1102,8 +1122,6 @@ class FakeOneRttHandshakeLayer : public ClientHandshake { : ClientHandshake(cryptoState) {} void connect( - std::shared_ptr, - std::shared_ptr, folly::Optional, folly::Optional, const std::shared_ptr&, @@ -1251,13 +1269,17 @@ class QuicClientTransportTest : public Test { auto socket = std::make_unique(eventbase_.get()); sock = socket.get(); + + auto fizzClientContext = + FizzClientQuicHandshakeContext::Builder() + .setCertificateVerifier(createTestCertificateVerifier()) + .build(); client = TestingQuicClientTransport::newClient( - eventbase_.get(), std::move(socket)); + eventbase_.get(), std::move(socket), std::move(fizzClientContext)); destructionCallback = std::make_shared(); client->setDestructionCallback(destructionCallback); client->setSupportedVersions( {QuicVersion::MVFST, MVFST1, QuicVersion::QUIC_DRAFT}); - client->setCertificateVerifier(createTestCertificateVerifier()); connIdAlgo_ = std::make_unique(); ON_CALL(*sock, resumeRead(_)) .WillByDefault(SaveArg<0>(&networkReadCallback)); diff --git a/quic/loss/test/QuicLossFunctionsTest.cpp b/quic/loss/test/QuicLossFunctionsTest.cpp index 593aa96d5..cda9284df 100644 --- a/quic/loss/test/QuicLossFunctionsTest.cpp +++ b/quic/loss/test/QuicLossFunctionsTest.cpp @@ -87,7 +87,7 @@ class QuicLossFunctionsTest : public TestWithParam { std::unique_ptr createClientConn() { auto conn = std::make_unique( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); conn->clientConnectionId = getTestConnectionId(); conn->version = QuicVersion::MVFST; conn->ackStates.initialAckState.nextPacketNum = 1; diff --git a/quic/samples/echo/EchoClient.h b/quic/samples/echo/EchoClient.h index 68ecd797b..d451f83da 100644 --- a/quic/samples/echo/EchoClient.h +++ b/quic/samples/echo/EchoClient.h @@ -18,6 +18,7 @@ #include #include +#include #include namespace quic { @@ -111,11 +112,13 @@ class EchoClient : public quic::QuicSocket::ConnectionCallback, evb->runInEventBaseThreadAndWait([&] { auto sock = std::make_unique(evb); - quicClient_ = - std::make_shared(evb, std::move(sock)); + auto fizzClientContext = + FizzClientQuicHandshakeContext::Builder() + .setCertificateVerifier(test::createTestCertificateVerifier()) + .build(); + quicClient_ = std::make_shared( + evb, std::move(sock), std::move(fizzClientContext)); quicClient_->setHostname("echo.com"); - quicClient_->setCertificateVerifier( - test::createTestCertificateVerifier()); quicClient_->addNewPeerAddress(addr); TransportSettings settings; diff --git a/quic/state/test/QuicStreamFunctionsTest.cpp b/quic/state/test/QuicStreamFunctionsTest.cpp index 59466d7eb..014509299 100644 --- a/quic/state/test/QuicStreamFunctionsTest.cpp +++ b/quic/state/test/QuicStreamFunctionsTest.cpp @@ -29,7 +29,7 @@ using PeekIterator = std::deque::const_iterator; class QuicStreamFunctionsTest : public Test { public: QuicStreamFunctionsTest() - : conn(std::make_shared()) {} + : conn(FizzClientQuicHandshakeContext::Builder().build()) {} void SetUp() override { conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiLocal = @@ -1088,7 +1088,7 @@ TEST_F(QuicStreamFunctionsTest, IsBidirectionalStream) { TEST_F(QuicStreamFunctionsTest, IsSendingStream) { QuicClientConnectionState clientState( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); QuicServerConnectionState serverState; QuicNodeType nodeType; StreamId id; @@ -1116,7 +1116,7 @@ TEST_F(QuicStreamFunctionsTest, IsSendingStream) { TEST_F(QuicStreamFunctionsTest, IsReceivingStream) { QuicClientConnectionState clientState( - std::make_shared()); + FizzClientQuicHandshakeContext::Builder().build()); QuicServerConnectionState serverState; QuicNodeType nodeType; StreamId id; diff --git a/quic/tools/tperf/tperf.cpp b/quic/tools/tperf/tperf.cpp index 53d22d1fe..b98eb2767 100644 --- a/quic/tools/tperf/tperf.cpp +++ b/quic/tools/tperf/tperf.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -431,10 +432,13 @@ class TPerfClient : public quic::QuicSocket::ConnectionCallback, folly::SocketAddress addr(host_.c_str(), port_); auto sock = std::make_unique(&eventBase_); + auto fizzClientContext = + FizzClientQuicHandshakeContext::Builder() + .setCertificateVerifier(test::createTestCertificateVerifier()) + .build(); quicClient_ = std::make_shared( - &eventBase_, std::move(sock)); + &eventBase_, std::move(sock), std::move(fizzClientContext)); quicClient_->setHostname("tperf"); - quicClient_->setCertificateVerifier(test::createTestCertificateVerifier()); quicClient_->addNewPeerAddress(addr); quicClient_->setCongestionControllerFactory( std::make_shared());