Verify Client SSL Certificate

While working on the winform application and connecting to the socket, I can create an SSLStream and authenticate. using the following code

// Authenticate ourself as a client. this.sslStream.AuthenticateAsClient(SSL_TARGET_HOST); 

Now someday, an application will throw an AuthenticationException if a certificate is not installed on the client computer.

I wonder if there is a way to verify that a particular certificate is installed on the client computer before calling to connect?

+4
source share
1 answer

You can use the X509Store class to determine which certificates are installed in a particular certificate store. There are various ways to search for certificates (for example, subject name, issuer name, serial number, etc.).

For example, to open the current user store and search for a certificate by topic name:

 X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); try { store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); X509Certificate2Collection foundCerts = store.Certificates.Find(X509FindType.FindBySubjectName, "MY CERTIFICATE SUJECT NAME", true); if (foundCerts.Count == 0) { // Cert not found } else { X509Certificate2 cert = foundCerts[0]; // Get first matching certificate } } finally { store.Close(); } 
+3
source

All Articles