From f88c6122735c685565fbbf355058a3abddf5d0c9 Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Wed, 28 Aug 2024 22:34:04 +0200 Subject: [PATCH] Pass SocksClientStream to SslStream constructor for ManagedProxySocket This doesn't seem to work as expected yet. --- .../Ssl/SslService/SslManagedSocketConnection.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs index 8cc761baf..d9d06fe96 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs @@ -1,6 +1,7 @@ using Ryujinx.HLE.HOS.Services.Sockets.Bsd; using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl; using Ryujinx.HLE.HOS.Services.Ssl.Types; +using RyuSocks; using System; using System.IO; using System.Net; @@ -111,12 +112,25 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService { return hostName; } + // Thrown by ManagedProxySocket when accessing RemoteEndPoint before connecting to a remote. + catch (NullReferenceException) + { + return hostName; + } } public ResultCode Handshake(string hostName) { StartSslOperation(); - _stream = new SslStream(new NetworkStream(((ManagedSocket)Socket).Socket, false), false, null, null); + + Stream socketStream = Socket switch + { + ManagedSocket managedSocket => new NetworkStream(managedSocket.Socket, false), + ManagedProxySocket proxySocket => new SocksClientStream(proxySocket.ProxyClient, false), + _ => throw new NotSupportedException($"{typeof(Socket)} is not supported.") + }; + + _stream = new SslStream(socketStream, false, null, null); hostName = RetrieveHostName(hostName); _stream.AuthenticateAsClient(hostName, null, TranslateSslVersion(_sslVersion), false); EndSslOperation();