View certificate information from a web browser

Does anyone know how to open an SSL-based Certificate Information screen using a WebBrowser ?

+4
source share
3 answers

This can be achieved using the X509Certificate2UI class.

To make this class available to you, you need to add a link to System.Security.dll

In the X509Certificate2UI class, you have a meyhod called DisplayCertificate() that takes an X509Certificate2 object as a parameter. When called, this method displays a dialog box that displays all the certificate information, including the chain, just like the dialog box you find in IE.

The webbrowser control can only return an X509Certificate , which can then be passed to the constructor of the X509Certificate2 class.

So, the code is as follows:

 //includes on top using System.Security; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; //Do webrequest to get info on secure site HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://securesite.com"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); //retrieve the ssl cert and assign it to an X509Certificate object X509Certificate cert = request.ServicePoint.Certificate; //convert the X509Certificate to an X509Certificate2 object by passing it into the constructor X509Certificate2 cert2 = new X509Certificate2(cert); //display the cert dialog box X509Certificate2UI.DisplayCertificate(cert2); 
+7
source

If I understand correctly, you should not look for this information in WebBrowser , but inside CryptoAPI. There are functions such as CryptUIDlgSelectCertificateFromStore , CryptUIDlgViewContext from Cryptui.dll . WINTRUST.DLL has several functions, such as WinVerifyTrustEx , which can also display some dialogs.

Could you describe how I can display the dialog, what do you want in Internet Explore? You are already working with the WebBrowser , then you can trace, for example, inside the BeforeNavigate2 Event, which is the URL that Internet Explorer has. With this URL, you can upload the SSL certificate to the display if in relation to CryptUIDlgViewContext . To download or obtain a certificate, you can use InternetQueryOption with INTERNET_OPTION_SERVER_CERT_CHAIN_CONTEXT or INTERNET_OPTION_CLIENT_CERT_CONTEXT. Perhaps you will have enough information from INTERNET_OPTION_SECURITY_CERTIFICATE, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT (see http://support.microsoft.com/kb/251347 ).

+1
source

As long as it doesn't use .NET WebBrowser, you can use this C # shell code for standard WebBrowser without significant impact on your project:

http://code.google.com/p/csexwb2/

Then you only need to say ShowCertificateDialog()

Cannot execute ExecWB or invoke this dialog otherwise.

+1
source

Source: https://habr.com/ru/post/1307657/


All Articles