Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TorTcpConnectionFactory: Add missing cancellation token #8911

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions WalletWasabi/Tor/Socks5/TorTcpConnectionFactory.cs
Expand Up @@ -3,6 +3,7 @@
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Extensions;
Expand Down Expand Up @@ -100,7 +101,7 @@ public async Task<TorTcpConnection> ConnectAsync(string host, int port, bool use

if (useSsl)
{
transportStream = await UpgradeToSslAsync(tcpClient, host).ConfigureAwait(false);
transportStream = await UpgradeToSslAsync(tcpClient, host, cancellationToken).ConfigureAwait(false);
}

bool allowRecycling = !useSsl && (circuit is DefaultCircuit or PersonCircuit);
Expand Down Expand Up @@ -200,10 +201,18 @@ private async Task HandshakeAsync(TcpClient tcpClient, ICircuit circuit, Cancell
}
}

private static async Task<SslStream> UpgradeToSslAsync(TcpClient tcpClient, string host)
private static async Task<SslStream> UpgradeToSslAsync(TcpClient tcpClient, string host, CancellationToken cancellationToken)
{
SslStream sslStream = new(tcpClient.GetStream(), leaveInnerStreamOpen: true);
await sslStream.AuthenticateAsClientAsync(host, clientCertificates: new(), checkCertificateRevocation: true).ConfigureAwait(false);

SslClientAuthenticationOptions options = new()
{
TargetHost = host,
ClientCertificates = new(),
CertificateRevocationCheckMode = X509RevocationMode.Online,
};

await sslStream.AuthenticateAsClientAsync(options, cancellationToken).ConfigureAwait(false);
return sslStream;
}

Expand Down