1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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__
|