My C # .NET SSL connection works when I import a certificate manually in IE (Tools / Internet Options / Content / Certificates), but how can I download the certificate by code? Here is my code:
TcpClient client = new TcpClient(ConfigManager.SSLSwitchIP, Convert.ToInt32(ConfigManager.SSLSwitchPort)); SslStream sslStream = new SslStream( client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null ); sslStream.AuthenticateAsClient("Test");
The above code works fine if I import the certificate file manually into Internet Explorer. But if I remove my certificate from IE and use the following code instead, I get an authentication exception:
sslStream.AuthenticateAsClient("Test", GetX509CertificateCollection(), SslProtocols.Default, false);
and here is the GetX509CertificateCollection method:
public static X509CertificateCollection GetX509CertificateCollection() { X509Certificate2 certificate1 = new X509Certificate2("c:\\ssl.txt"); X509CertificateCollection collection1 = new X509CertificateCollection(); collection1.Add(certificate1); return collection1; }
What to do to dynamically upload my certificate?
losingsleeep
source share