Bug 1814798 - pt 2. Add a PHCManager component to control PHC r=glandium,emilio
[gecko.git] / netwerk / protocol / http / QuicSocketControl.cpp
blob183b9f5fd597c9b18b237149f4ed4f73e8672a27
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"
16 #include "sslt.h"
17 #include "ssl.h"
19 namespace mozilla {
20 namespace net {
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);
35 if (errorCode) {
36 mFailedVerification = true;
37 SetCanceled(errorCode);
40 CallAuthenticated();
43 NS_IMETHODIMP
44 QuicSocketControl::GetSSLVersionOffered(int16_t* aSSLVersionOffered) {
45 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
46 *aSSLVersionOffered = nsITLSSocketControl::TLS_VERSION_1_3;
47 return NS_OK;
50 void QuicSocketControl::CallAuthenticated() {
51 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
52 RefPtr<Http3Session> http3Session = do_QueryReferent(mHttp3Session);
53 if (http3Session) {
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
64 // error.
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;
78 mNPNCompleted = true;
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) ==
88 SECSuccess) {
89 mCipherSuite.emplace(aCipherSuite);
90 mProtocolVersion.emplace(aProtocolVersion & 0xFF);
91 mKeaGroupName.emplace(getKeaGroupName(aKeaGroupName));
92 mSignatureSchemeName.emplace(getSignatureName(aSignatureScheme));
93 mIsAcceptedEch.emplace(aEchAccepted);
97 NS_IMETHODIMP
98 QuicSocketControl::GetEchConfig(nsACString& aEchConfig) {
99 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
100 aEchConfig = mEchConfig;
101 return NS_OK;
104 NS_IMETHODIMP
105 QuicSocketControl::SetEchConfig(const nsACString& aEchConfig) {
106 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
107 mEchConfig = aEchConfig;
108 RefPtr<Http3Session> http3Session = do_QueryReferent(mHttp3Session);
109 if (http3Session) {
110 http3Session->DoSetEchConfig(mEchConfig);
112 return NS_OK;
115 NS_IMETHODIMP
116 QuicSocketControl::GetRetryEchConfig(nsACString& aEchConfig) {
117 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
118 aEchConfig = mRetryEchConfig;
119 return NS_OK;
122 void QuicSocketControl::SetRetryEchConfig(const nsACString& aEchConfig) {
123 COMMON_SOCKET_CONTROL_ASSERT_ON_OWNING_THREAD();
124 mRetryEchConfig = aEchConfig;
127 } // namespace net
128 } // namespace mozilla