1 /* -*- Mode: C++; tab-width: 2; 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/. */
6 #include "SocketProcessBackgroundParent.h"
7 #include "SocketProcessLogging.h"
9 #include "mozilla/ipc/Endpoint.h"
10 #include "mozilla/net/HttpConnectionMgrParent.h"
11 #include "mozilla/net/WebSocketConnectionParent.h"
12 #include "mozilla/psm/IPCClientCertsParent.h"
13 #include "mozilla/psm/VerifySSLServerCertParent.h"
14 #include "mozilla/psm/SelectTLSClientAuthCertParent.h"
15 #include "nsIHttpChannelInternal.h"
17 namespace mozilla::net
{
19 SocketProcessBackgroundParent::SocketProcessBackgroundParent() {
20 LOG(("SocketProcessBackgroundParent ctor"));
23 SocketProcessBackgroundParent::~SocketProcessBackgroundParent() {
24 LOG(("SocketProcessBackgroundParent dtor"));
27 mozilla::ipc::IPCResult
28 SocketProcessBackgroundParent::RecvInitVerifySSLServerCert(
29 Endpoint
<PVerifySSLServerCertParent
>&& aEndpoint
,
30 nsTArray
<ByteArray
>&& aPeerCertChain
, const nsACString
& aHostName
,
31 const int32_t& aPort
, const OriginAttributes
& aOriginAttributes
,
32 const Maybe
<ByteArray
>& aStapledOCSPResponse
,
33 const Maybe
<ByteArray
>& aSctsFromTLSExtension
,
34 const Maybe
<DelegatedCredentialInfoArg
>& aDcInfo
,
35 const uint32_t& aProviderFlags
, const uint32_t& aCertVerifierFlags
) {
36 LOG(("SocketProcessBackgroundParent::RecvInitVerifySSLServerCert\n"));
37 if (!aEndpoint
.IsValid()) {
38 return IPC_FAIL(this, "Invalid endpoint");
41 nsCOMPtr
<nsISerialEventTarget
> transportQueue
;
42 if (NS_FAILED(NS_CreateBackgroundTaskQueue("VerifySSLServerCert",
43 getter_AddRefs(transportQueue
)))) {
44 return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
47 transportQueue
->Dispatch(NS_NewRunnableFunction(
48 "InitVerifySSLServerCert",
49 [endpoint
= std::move(aEndpoint
),
50 peerCertChain
= std::move(aPeerCertChain
),
51 hostName
= nsCString(aHostName
), port(aPort
),
52 originAttributes(aOriginAttributes
),
53 stapledOCSPResponse
= std::move(aStapledOCSPResponse
),
54 sctsFromTLSExtension
= std::move(aSctsFromTLSExtension
),
55 dcInfo
= std::move(aDcInfo
), providerFlags(aProviderFlags
),
56 certVerifierFlags(aCertVerifierFlags
)]() mutable {
57 RefPtr
<psm::VerifySSLServerCertParent
> parent
=
58 new psm::VerifySSLServerCertParent();
59 if (!endpoint
.Bind(parent
)) {
63 parent
->Dispatch(std::move(peerCertChain
), hostName
, port
,
64 originAttributes
, stapledOCSPResponse
,
65 sctsFromTLSExtension
, dcInfo
, providerFlags
,
72 mozilla::ipc::IPCResult
73 SocketProcessBackgroundParent::RecvInitSelectTLSClientAuthCert(
74 Endpoint
<PSelectTLSClientAuthCertParent
>&& aEndpoint
,
75 const nsACString
& aHostName
, const OriginAttributes
& aOriginAttributes
,
76 const int32_t& aPort
, const uint32_t& aProviderFlags
,
77 const uint32_t& aProviderTlsFlags
, const ByteArray
& aServerCertBytes
,
78 nsTArray
<ByteArray
>&& aCANames
, const uint64_t& aBrowserId
) {
79 LOG(("SocketProcessBackgroundParent::RecvInitSelectTLSClientAuthCert\n"));
80 if (!aEndpoint
.IsValid()) {
81 return IPC_FAIL(this, "Invalid endpoint");
84 nsCOMPtr
<nsISerialEventTarget
> transportQueue
;
85 if (NS_FAILED(NS_CreateBackgroundTaskQueue("SelectTLSClientAuthCert",
86 getter_AddRefs(transportQueue
)))) {
87 return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
90 transportQueue
->Dispatch(NS_NewRunnableFunction(
91 "InitSelectTLSClientAuthCert",
92 [endpoint
= std::move(aEndpoint
), hostName
= nsCString(aHostName
),
93 originAttributes(aOriginAttributes
), port(aPort
),
94 providerFlags(aProviderFlags
), providerTlsFlags(aProviderTlsFlags
),
95 serverCertBytes(aServerCertBytes
), CANAMEs(std::move(aCANames
)),
96 browserId(aBrowserId
)]() mutable {
97 RefPtr
<psm::SelectTLSClientAuthCertParent
> parent
=
98 new psm::SelectTLSClientAuthCertParent();
99 if (!endpoint
.Bind(parent
)) {
103 parent
->Dispatch(hostName
, originAttributes
, port
, providerFlags
,
104 providerTlsFlags
, serverCertBytes
, std::move(CANAMEs
),
111 mozilla::ipc::IPCResult
SocketProcessBackgroundParent::RecvInitIPCClientCerts(
112 Endpoint
<PIPCClientCertsParent
>&& aEndpoint
) {
113 LOG(("SocketProcessBackgroundParent::RecvInitIPCClientCerts\n"));
114 if (!aEndpoint
.IsValid()) {
115 return IPC_FAIL(this, "Invalid endpoint");
118 nsCOMPtr
<nsISerialEventTarget
> transportQueue
;
119 if (NS_FAILED(NS_CreateBackgroundTaskQueue("IPCClientCerts",
120 getter_AddRefs(transportQueue
)))) {
121 return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
124 transportQueue
->Dispatch(NS_NewRunnableFunction(
125 "InitIPCClientCerts", [endpoint
= std::move(aEndpoint
)]() mutable {
126 RefPtr
<psm::IPCClientCertsParent
> parent
=
127 new psm::IPCClientCertsParent();
128 endpoint
.Bind(parent
);
133 mozilla::ipc::IPCResult
134 SocketProcessBackgroundParent::RecvInitWebSocketConnection(
135 Endpoint
<PWebSocketConnectionParent
>&& aEndpoint
,
136 const uint32_t& aListenerId
) {
137 LOG(("SocketProcessBackgroundParent::RecvInitWebSocketConnection\n"));
138 if (!aEndpoint
.IsValid()) {
139 return IPC_FAIL(this, "Invalid endpoint");
142 nsCOMPtr
<nsISerialEventTarget
> transportQueue
;
143 if (NS_FAILED(NS_CreateBackgroundTaskQueue("WebSocketConnection",
144 getter_AddRefs(transportQueue
)))) {
145 return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
148 transportQueue
->Dispatch(NS_NewRunnableFunction(
149 "InitWebSocketConnection",
150 [endpoint
= std::move(aEndpoint
), aListenerId
]() mutable {
151 Maybe
<nsCOMPtr
<nsIHttpUpgradeListener
>> listener
=
152 net::HttpConnectionMgrParent::GetAndRemoveHttpUpgradeListener(
158 RefPtr
<WebSocketConnectionParent
> actor
=
159 new WebSocketConnectionParent(*listener
);
160 endpoint
.Bind(actor
);
165 void SocketProcessBackgroundParent::ActorDestroy(ActorDestroyReason aReason
) {
166 LOG(("SocketProcessBackgroundParent::ActorDestroy"));
169 } // namespace mozilla::net