TlsHandshaker.h (3305B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef TlsHandshaker_h__ 7 #define TlsHandshaker_h__ 8 9 #include "nsITlsHandshakeListener.h" 10 11 class nsISocketTransport; 12 class nsITLSSocketControl; 13 14 namespace mozilla::net { 15 16 class nsHttpConnection; 17 class nsHttpConnectionInfo; 18 19 class TlsHandshaker : public nsITlsHandshakeCallbackListener { 20 public: 21 NS_DECL_THREADSAFE_ISUPPORTS 22 NS_DECL_NSITLSHANDSHAKECALLBACKLISTENER 23 24 TlsHandshaker(nsHttpConnectionInfo* aInfo, nsHttpConnection* aOwner); 25 26 void SetupSSL(bool aInSpdyTunnel, bool aForcePlainText); 27 [[nodiscard]] nsresult InitSSLParams(bool connectingToProxy, 28 bool ProxyStartSSL); 29 [[nodiscard]] nsresult SetupNPNList(nsITLSSocketControl* ssl, uint32_t caps, 30 bool connectingToProxy); 31 // Makes certain the SSL handshake is complete and NPN negotiation 32 // has had a chance to happen 33 [[nodiscard]] bool EnsureNPNComplete(); 34 void FinishNPNSetup(bool handshakeSucceeded, bool hasSecurityInfo); 35 bool EarlyDataAvailable() const { 36 return mEarlyDataState == EarlyData::USED || 37 mEarlyDataState == EarlyData::CANNOT_BE_USED; 38 } 39 bool EarlyDataWasAvailable() const { 40 return mEarlyDataState != EarlyData::NOT_AVAILABLE && 41 mEarlyDataState != EarlyData::DONE_NOT_AVAILABLE; 42 } 43 bool EarlyDataUsed() const { return mEarlyDataState == EarlyData::USED; } 44 bool EarlyDataCanNotBeUsed() const { 45 return mEarlyDataState == EarlyData::CANNOT_BE_USED; 46 } 47 void EarlyDataDone(); 48 49 #ifndef ANDROID 50 void EarlyDataTelemetry(int16_t tlsVersion, bool earlyDataAccepted, 51 int64_t aContentBytesWritten0RTT); 52 #endif 53 54 bool NPNComplete() const { return mNPNComplete; } 55 bool SetupSSLCalled() const { return mSetupSSLCalled; } 56 bool TlsHandshakeComplitionPending() const { 57 return mTlsHandshakeComplitionPending; 58 } 59 const nsCString& EarlyNegotiatedALPN() const { return mEarlyNegotiatedALPN; } 60 void SetNPNComplete() { mNPNComplete = true; } 61 void NotifyClose() { 62 mTlsHandshakeComplitionPending = false; 63 mOwner = nullptr; 64 } 65 66 private: 67 virtual ~TlsHandshaker(); 68 69 void Check0RttEnabled(nsITLSSocketControl* ssl); 70 void ReportSecureConnectionStart(); 71 72 // SPDY related 73 bool mSetupSSLCalled{false}; 74 bool mNPNComplete{false}; 75 76 bool mSecureConnectionStartReported{false}; 77 bool mTlsHandshakeComplitionPending{false}; 78 // Helper variable for 0RTT handshake; 79 // Possible 0RTT has been checked. 80 bool m0RTTChecked{false}; 81 // 0RTT data state. 82 enum EarlyData { 83 NOT_AVAILABLE, 84 USED, 85 CANNOT_BE_USED, 86 DONE_NOT_AVAILABLE, 87 DONE_USED, 88 DONE_CANNOT_BE_USED, 89 }; 90 EarlyData mEarlyDataState{EarlyData::NOT_AVAILABLE}; 91 nsCString mEarlyNegotiatedALPN; 92 RefPtr<nsHttpConnectionInfo> mConnInfo; 93 // nsHttpConnection and TlsHandshaker create a reference cycle. To break this 94 // cycle, NotifyClose() needs to be called in nsHttpConnection::Close(). 95 RefPtr<nsHttpConnection> mOwner; 96 }; 97 98 } // namespace mozilla::net 99 100 #endif // TlsHandshaker_h__