12 template <
typename SM>
15 std::shared_ptr<const FizzClientContext> fizzContext,
16 const std::shared_ptr<ClientExtensions>& extensions)
18 fizzContext_(
std::
move(fizzContext)),
19 extensions_(extensions),
21 fizzClient_(state_, transportReadBuf_, visitor_, this) {}
23 template <
typename SM>
26 std::shared_ptr<const FizzClientContext> fizzContext,
27 const std::shared_ptr<ClientExtensions>& extensions)
35 template <
typename SM>
39 std::chrono::milliseconds timeout) {
40 auto pskIdentity = hostname;
49 template <
typename SM>
52 std::shared_ptr<const CertificateVerifier> verifier,
55 std::chrono::milliseconds timeout) {
56 DelayedDestruction::DestructorGuard dg(
this);
65 "handshake connect called but socket isn't open");
73 if (timeout != std::chrono::milliseconds::zero()) {
91 template <
typename SM>
95 std::shared_ptr<const CertificateVerifier> verifier,
98 std::chrono::milliseconds totalTimeout,
99 std::chrono::milliseconds socketTimeout,
102 DelayedDestruction::DestructorGuard dg(
this);
112 if (totalTimeout != std::chrono::milliseconds::zero()) {
116 auto underlyingSocket =
118 if (underlyingSocket) {
120 underlyingSocket->connect(
123 static_cast<int>(socketTimeout.count()),
129 "could not find underlying socket");
134 template <
typename SM>
139 template <
typename SM>
144 template <
typename SM>
149 template <
typename SM>
154 template <
typename SM>
164 template <
typename SM>
168 return cert->getX509().get();
174 template <
typename SM>
180 template <
typename SM>
186 template <
typename SM>
191 template <
typename SM>
198 template <
typename SM>
215 template <
typename SM>
220 DelayedDestruction::DestructorGuard dg(
this);
228 template <
typename SM>
230 DelayedDestruction::DestructorGuard dg(
this);
240 template <
typename SM>
242 DelayedDestruction::DestructorGuard dg(
this);
252 template <
typename SM>
268 template <
typename SM>
274 template <
typename SM>
277 std::unique_ptr<folly::IOBuf>&& buf,
285 "fizz app write in error state"));
291 auto size = buf->computeChainDataLength();
314 auto writeCopy = w.
data->clone();
315 writeCopy->unshare();
331 template <
typename SM>
334 DelayedDestruction::DestructorGuard dg(
this);
338 template <
typename SM>
343 template <
typename SM>
346 bool closeTransport) {
347 DelayedDestruction::DestructorGuard dg(
this);
358 w.callback->writeErr(0, ex);
365 template <
typename SM>
379 callback->connectErr(ase);
381 [callback](
const std::exception& stdEx) {
384 callback->connectErr(ase);
389 callback->connectErr(ase);
395 template <
typename SM>
400 template <
typename SM>
404 for (
size_t i = 1;
i < data.
contents.size(); ++
i) {
410 template <
typename SM>
414 client_.earlyDataState_->remainingEarlyData = earlySuccess.
maxEarlyDataSize;
415 if (client_.callback_) {
416 auto cb = *client_.callback_;
424 callback->connectSuccess();
429 template <
typename SM>
436 "fizz early data rejected");
448 "fizz early data rejected, could not be resent");
456 template <
typename SM>
459 client_.cancelHandshakeTimeout();
460 if (client_.earlyDataState_) {
462 auto ex = client_.handleEarlyReject();
464 if (client_.pskIdentity_) {
465 client_.fizzContext_->removePsk(*client_.pskIdentity_);
467 client_.deliverAllErrors(*ex,
false);
468 client_.transport_->closeNow();
473 while (!client_.earlyDataState_->pendingAppWrites.empty()) {
474 auto w =
std::move(client_.earlyDataState_->pendingAppWrites.front());
475 client_.earlyDataState_->pendingAppWrites.pop_front();
476 client_.fizzClient_.appWrite(
std::move(w));
478 client_.earlyDataState_.clear();
480 if (client_.callback_) {
481 auto cb = *client_.callback_;
489 callback->connectSuccess();
492 if (client_.replaySafetyCallback_) {
493 auto callback = client_.replaySafetyCallback_;
494 client_.replaySafetyCallback_ =
nullptr;
495 callback->onReplaySafe();
499 template <
typename SM>
515 template <
typename SM>
520 client_.deliverAllErrors(ase);
523 template <
typename SM>
525 client_.fizzClient_.waitForData();
527 if (client_.callback_) {
529 client_.startTransportReads();
533 template <
typename SM>
535 mutator(client_.state_);
538 template <
typename SM>
541 if (client_.pskIdentity_) {
542 client_.fizzContext_->putPsk(
547 template <
typename SM>
552 template <
typename SM>
558 template <
typename SM>
566 template <
typename SM>
571 return fizzClient_.getEarlyEkm(label, context, length);
574 template <
typename SM>
void closeWithReset() override
folly::fbstring what() const
std::unique_ptr< folly::IOBuf > data
std::shared_ptr< const FizzClientContext > fizzContext_
virtual void deliverError(const folly::AsyncSocketException &ex, bool closeTransport=true)
folly::IOBufQueue transportReadBuf_
Buf getEarlyEkm(folly::StringPiece label, const Buf &context, uint16_t length) const
EarlyDataRejectionPolicy earlyDataRejectionPolicy_
void handle(CatchFns...fns)
folly::Optional< CipherSuite > getCipher() const override
std::unique_ptr< X509, X509Deleter > X509UniquePtr
void transportDataAvailable() override
void connectSuccess() noexceptoverride
void connectErr(const folly::AsyncSocketException &ex) noexceptoverride
constexpr detail::Map< Move > move
folly::small_vector< TLSContent, 4 > contents
virtual void fizzHandshakeError(AsyncFizzClientT *transport, folly::exception_wrapper ex) noexcept=0
bool isReplaySafe() const override
FOLLY_CPP14_CONSTEXPR bool has_value() const noexcept
void transportError(const folly::AsyncSocketException &ex) override
virtual void startHandshakeTimeout(std::chrono::milliseconds)
folly::Optional< PskKeyExchangeMode > pskMode() const
folly::AsyncTransport::ReplaySafetyCallback * replaySafetyCallback_
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
std::unique_ptr< AsyncFizzClientT, folly::DelayedDestruction::Destructor > UniquePtr
bool good() const override
folly::Optional< CipherSuite > cipher() const
const folly::Optional< std::string > & alpn() const
virtual void cancelHandshakeTimeout()
std::shared_ptr< const Cert > clientCert() const
constexpr auto size(C const &c) -> decltype(c.size())
folly::Optional< folly::AsyncSocketException > handleEarlyReject()
std::map< OptionKey, int > OptionMap
folly::AsyncTransportWrapper::UniquePtr transport_
void operator()(DeliverAppData &)
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
void writeAppData(folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE) override
void setReplaySafetyCallback(folly::AsyncTransport::ReplaySafetyCallback *callback) override
FizzClient< ActionMoveVisitor, SM > fizzClient_
void write(folly::AsyncTransportWrapper::WriteCallback *callback, const void *buf, size_t bytes, folly::WriteFlags flags=folly::WriteFlags::NONE) override
folly::Optional< boost::variant< HandshakeCallback *, folly::AsyncSocket::ConnectCallback * > > callback_
const folly::Optional< EarlyDataParams > & earlyDataParams() const
std::shared_ptr< ClientExtensions > extensions_
const Cert * getSelfCertificate() const override
std::basic_string< E, T, A > toStdString() const
void deliverAllErrors(const folly::AsyncSocketException &ex, bool closeTransport=true)
folly::exception_wrapper error
bool earlyParametersMatch(const State &state)
void disableTransparentTls()
virtual void fizzHandshakeSuccess(AsyncFizzClientT *transport) noexcept=0
NetworkSocket socket(int af, int type, int protocol)
std::shared_ptr< const Cert > serverCert
bool readable() const override
virtual void startTransportReads()
folly::AsyncTransportWrapper::WriteCallback * callback
folly::Optional< EarlyDataState > earlyDataState_
std::shared_ptr< const CertificateVerifier > verifier_
void deliverHandshakeError(folly::exception_wrapper ex)
const auto & getSupportedSigSchemes() const
std::vector< SignatureScheme > getSupportedSigSchemes() const override
ActionMoveVisitor visitor_
bool error() const override
Buf getEkm(folly::StringPiece label, const Buf &context, uint16_t length) const override
std::unique_ptr< folly::IOBuf > Buf
const X509 * getSelfCert() const override
std::shared_ptr< const Cert > serverCert() const
folly::ssl::X509UniquePtr getPeerCert() const override
const FizzClientContext * context() const
virtual void writeSuccess() noexcept=0
decltype(auto) variant_match(Variant &&variant, Cases &&...cases)
const Cert * getPeerCertificate() const override
folly::Optional< std::string > pskIdentity_
virtual void writeErr(size_t bytesWritten, const AsyncSocketException &ex) noexcept=0
bool connecting() const override
folly::Optional< std::string > sni_
virtual void connect(HandshakeCallback *callback, std::shared_ptr< const CertificateVerifier > verifier, folly::Optional< std::string > sni, folly::Optional< std::string > pskIdentity, std::chrono::milliseconds=std::chrono::milliseconds(0))
uint32_t maxEarlyDataSize
static constexpr uint64_t data[1]
const State & getState() const
std::unique_ptr< folly::IOBuf > data
folly::AsyncTransportWrapper::WriteCallback * callback
std::string getApplicationProtocol() const noexceptoverride
AsyncFizzClientT(folly::AsyncTransportWrapper::UniquePtr socket, std::shared_ptr< const FizzClientContext > fizzContext, const std::shared_ptr< ClientExtensions > &extensions=nullptr)
std::unique_ptr< folly::IOBuf > data
folly::AsyncTransportWrapper::WriteCallback * callback