diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /netwerk/protocol/http/TlsHandshaker.h | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | netwerk/protocol/http/TlsHandshaker.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/netwerk/protocol/http/TlsHandshaker.h b/netwerk/protocol/http/TlsHandshaker.h new file mode 100644 index 0000000000..fc01b07518 --- /dev/null +++ b/netwerk/protocol/http/TlsHandshaker.h @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef TlsHandshaker_h__ +#define TlsHandshaker_h__ + +#include "nsITlsHandshakeListener.h" + +class nsISocketTransport; +class nsITLSSocketControl; + +namespace mozilla::net { + +class nsHttpConnection; +class nsHttpConnectionInfo; + +class TlsHandshaker : public nsITlsHandshakeCallbackListener { + public: + NS_DECL_THREADSAFE_ISUPPORTS + NS_DECL_NSITLSHANDSHAKECALLBACKLISTENER + + TlsHandshaker(nsHttpConnectionInfo* aInfo, nsHttpConnection* aOwner); + + void SetupSSL(bool aInSpdyTunnel, bool aForcePlainText); + [[nodiscard]] nsresult InitSSLParams(bool connectingToProxy, + bool ProxyStartSSL); + [[nodiscard]] nsresult SetupNPNList(nsITLSSocketControl* ssl, uint32_t caps, + bool connectingToProxy); + // Makes certain the SSL handshake is complete and NPN negotiation + // has had a chance to happen + [[nodiscard]] bool EnsureNPNComplete(); + void FinishNPNSetup(bool handshakeSucceeded, bool hasSecurityInfo); + bool EarlyDataAvailable() const { + return mEarlyDataState == EarlyData::USED || + mEarlyDataState == EarlyData::CANNOT_BE_USED; + } + bool EarlyDataWasAvailable() const { + return mEarlyDataState != EarlyData::NOT_AVAILABLE && + mEarlyDataState != EarlyData::DONE_NOT_AVAILABLE; + } + bool EarlyDataUsed() const { return mEarlyDataState == EarlyData::USED; } + bool EarlyDataCanNotBeUsed() const { + return mEarlyDataState == EarlyData::CANNOT_BE_USED; + } + void EarlyDataDone(); + void EarlyDataTelemetry(int16_t tlsVersion, bool earlyDataAccepted, + int64_t aContentBytesWritten0RTT); + + bool NPNComplete() const { return mNPNComplete; } + bool SetupSSLCalled() const { return mSetupSSLCalled; } + bool TlsHandshakeComplitionPending() const { + return mTlsHandshakeComplitionPending; + } + const nsCString& EarlyNegotiatedALPN() const { return mEarlyNegotiatedALPN; } + void SetNPNComplete() { mNPNComplete = true; } + void NotifyClose() { + mTlsHandshakeComplitionPending = false; + mOwner = nullptr; + } + + private: + virtual ~TlsHandshaker(); + + void Check0RttEnabled(nsITLSSocketControl* ssl); + + // SPDY related + bool mSetupSSLCalled{false}; + bool mNPNComplete{false}; + + bool mTlsHandshakeComplitionPending{false}; + // Helper variable for 0RTT handshake; + // Possible 0RTT has been checked. + bool m0RTTChecked{false}; + // 0RTT data state. + enum EarlyData { + NOT_AVAILABLE, + USED, + CANNOT_BE_USED, + DONE_NOT_AVAILABLE, + DONE_USED, + DONE_CANNOT_BE_USED, + }; + EarlyData mEarlyDataState{EarlyData::NOT_AVAILABLE}; + nsCString mEarlyNegotiatedALPN; + RefPtr<nsHttpConnectionInfo> mConnInfo; + // nsHttpConnection and TlsHandshaker create a reference cycle. To break this + // cycle, NotifyClose() needs to be called in nsHttpConnection::Close(). + RefPtr<nsHttpConnection> mOwner; +}; + +} // namespace mozilla::net + +#endif // TlsHandshaker_h__ |