C
C#2y ago
Iceman228

TcpClient connection

using TcpClient tcpClient = new(domain, port);
using TcpClient tcpClient = new(domain, port);
When I let this run on my local machine, it works fine. But on our server, I get System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (10060). But only for some websites. I am using Port 443. Goal is to read the certificate with SslStream afterwards. When I tested it on the system of a colleague, he first had to run the program with Visual Studio, otherwise the exe produced the same errors for some websites as on the server. I have no idea what the issue could be.
1 Reply
Iceman228
Iceman228OP2y ago
var certificate = await SSL.GetCertificateAsync(url);



private static readonly RemoteCertificateValidationCallback _certificateValidationCallback = (_, _, _, _) => true;

public static async Task<X509Certificate2?> GetCertificateAsync(string domain, int port = 443)
{
using TcpClient tcpClient = new(domain, port);
using SslStream sslStream = new(tcpClient.GetStream(), leaveInnerStreamOpen: true, _certificateValidationCallback);

await sslStream.AuthenticateAsClientAsync(domain).ConfigureAwait(false);

var serverCertificate = sslStream.RemoteCertificate;
if (serverCertificate != null)
return new X509Certificate2(serverCertificate);

return null;
}
}
var certificate = await SSL.GetCertificateAsync(url);



private static readonly RemoteCertificateValidationCallback _certificateValidationCallback = (_, _, _, _) => true;

public static async Task<X509Certificate2?> GetCertificateAsync(string domain, int port = 443)
{
using TcpClient tcpClient = new(domain, port);
using SslStream sslStream = new(tcpClient.GetStream(), leaveInnerStreamOpen: true, _certificateValidationCallback);

await sslStream.AuthenticateAsClientAsync(domain).ConfigureAwait(false);

var serverCertificate = sslStream.RemoteCertificate;
if (serverCertificate != null)
return new X509Certificate2(serverCertificate);

return null;
}
}
Want results from more Discord servers?
Add your server