1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "QuicSocketControl.h"
9 #include "Http3Session.h"
10 #include "SharedCertVerifier.h"
11 #include "nsISocketProvider.h"
12 #include "nsIWebProgressListener.h"
13 #include "nsNSSComponent.h"
14 #include "nsSocketTransportService2.h"
15 #include "nsThreadUtils.h"
22 QuicSocketControl::QuicSocketControl(const nsCString
& aHostName
, int32_t aPort
,
23 uint32_t aProviderFlags
,
24 Http3Session
* aHttp3Session
)
25 : CommonSocketControl(aHostName
, aPort
, aProviderFlags
) {
26 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
27 mHttp3Session
= do_GetWeakReference(
28 static_cast<nsISupportsWeakReference
*>(aHttp3Session
));
31 void QuicSocketControl::SetCertVerificationResult(PRErrorCode errorCode
) {
32 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
33 SetUsedPrivateDNS(GetProviderFlags() & nsISocketProvider::USED_PRIVATE_DNS
);
36 mFailedVerification
= true;
37 SetCanceled(errorCode
);
44 QuicSocketControl::GetSSLVersionOffered(int16_t* aSSLVersionOffered
) {
45 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
46 *aSSLVersionOffered
= nsITLSSocketControl::TLS_VERSION_1_3
;
50 void QuicSocketControl::CallAuthenticated() {
51 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
52 RefPtr
<Http3Session
> http3Session
= do_QueryReferent(mHttp3Session
);
54 http3Session
->Authenticated(GetErrorCode());
58 void QuicSocketControl::HandshakeCompleted() {
59 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
60 uint32_t state
= nsIWebProgressListener::STATE_IS_SECURE
;
62 // If we're here, the TLS handshake has succeeded. If the overridable error
63 // category is nonzero, the user has added an override for a certificate
65 if (mOverridableErrorCategory
.isSome() &&
66 *mOverridableErrorCategory
!=
67 nsITransportSecurityInfo::OverridableErrorCategory::ERROR_UNSET
) {
68 state
|= nsIWebProgressListener::STATE_CERT_USER_OVERRIDDEN
;
71 SetSecurityState(state
);
72 mHandshakeCompleted
= true;
75 void QuicSocketControl::SetNegotiatedNPN(const nsACString
& aValue
) {
76 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
77 mNegotiatedNPN
= aValue
;
81 void QuicSocketControl::SetInfo(uint16_t aCipherSuite
,
82 uint16_t aProtocolVersion
,
83 uint16_t aKeaGroupName
,
84 uint16_t aSignatureScheme
, bool aEchAccepted
) {
85 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
86 SSLCipherSuiteInfo cipherInfo
;
87 if (SSL_GetCipherSuiteInfo(aCipherSuite
, &cipherInfo
, sizeof cipherInfo
) ==
89 mCipherSuite
.emplace(aCipherSuite
);
90 mProtocolVersion
.emplace(aProtocolVersion
& 0xFF);
91 mKeaGroupName
.emplace(getKeaGroupName(aKeaGroupName
));
92 mSignatureSchemeName
.emplace(getSignatureName(aSignatureScheme
));
93 mIsAcceptedEch
.emplace(aEchAccepted
);
98 QuicSocketControl::GetEchConfig(nsACString
& aEchConfig
) {
99 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
100 aEchConfig
= mEchConfig
;
105 QuicSocketControl::SetEchConfig(const nsACString
& aEchConfig
) {
106 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
107 mEchConfig
= aEchConfig
;
108 RefPtr
<Http3Session
> http3Session
= do_QueryReferent(mHttp3Session
);
110 http3Session
->DoSetEchConfig(mEchConfig
);
116 QuicSocketControl::GetRetryEchConfig(nsACString
& aEchConfig
) {
117 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
118 aEchConfig
= mRetryEchConfig
;
122 void QuicSocketControl::SetRetryEchConfig(const nsACString
& aEchConfig
) {
123 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
124 mRetryEchConfig
= aEchConfig
;
128 } // namespace mozilla