diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/protocol/http/TlsHandshaker.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/protocol/http/TlsHandshaker.h')
-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__ |