Check self-signed certificate (SSL, C#)

2019-04-03 04:11发布

In my desktop application i use HTTPS connection. Certificate is SELF-signed. How I can check self-signed certificate in c# programatically?

i make i a callback "ValidateRemoteCertificate":

 ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate)

By default, my "ValidateRemoteCertificate" method always return TRUE. But I think i need to check valid or invalid this certificate. How to check it? What i must to check in "ValidateRemoteCertificate"?

标签: c# ssl https
1条回答
三岁会撩人
2楼-- · 2019-04-03 05:03

Since you already have implemented the callback you know the signature of the callback delegate

public delegate bool RemoteCertificateValidationCallback(
    Object sender,
    X509Certificate certificate,
    X509Chain chain,
    SslPolicyErrors sslPolicyErrors)

If I understand you correctly, the client does not have the certificate installed in his store, correct? Although I´d recommend getting your infrastructure in order and deploy a valid certificate, what you could do in your case, is to compare the hash/fingerprint for the certificate to values stored in your application to verify the validty of the certificate.

查看更多
登录 后发表回答