How to get a standard Windows dialog for accepting / rejecting a digital certificate in C #?

When writing a C / S application with C #, I check the certificate of the server I'm connecting to. So I get a callback where I can review the X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors to verify the certificate. I want the user to make a decision about this, so I thought about using the standard Windows certificate window, which looks like this:

Windows standard certificate decision dialog

How can I achieve this with data?

I found a partial answer for showing the certificate. So I can use this code:

 X509Certificate certificate = ... X509Certificate2 certenh = new X509Certificate2(certificate); X509Certificate2UI.DisplayCertificate(certenh); 

But another message is still missing. I could reproduce it, but not for every language, and I do not know where to find this symbol. As a condition for showing this message, I could use certenh.Verify(); .

For the background message icon, I can use urlmon.dll at indices 13, 14 and 15. There you will find icons such as:

Certificate informationCertificate questionCertificate warning

So, I can create a similar message, similar to what was in the background. The only problem that remains is that it would be better to use standard phrases to create a message. But I did not find a library containing language-specific strings.

At the moment, I am creating the message myself using the sslPolicyErrors value.

+4
source share

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


All Articles