How to use certificate callback in SslStream.AuthenticateAsClient method?

前端 未结 3 1710
孤独总比滥情好
孤独总比滥情好 2021-01-14 18:47

My C#.NET SSL connect works when I import the certificate manually in IE (Tools/Internet Options/Content/Certificates), but how can I load the certificate by code? Here is m

3条回答
  •  旧时难觅i
    2021-01-14 18:55

    A quick Google pointed me to a piece of text from the Microsoft SslStream class.

    The authentication is handled by the Security Support Provider (SSPI) channel provider. The client is given an opportunity to control validation of the server's certificate by specifying a RemoteCertificateValidationCallback delegate when creating an SslStream. The server can also control validation by supplying a RemoteCertificateValidationCallback delegate. The method referenced by the delegate includes the remote party's certificate and any errors SSPI encountered while validating the certificate. Note that if the server specifies a delegate, the delegate's method is invoked regardless of whether the server requested client authentication. If the server did not request client authentication, the server's delegate method receives a null certificate and an empty array of certificate errors.

    So simply implement the delegate and do the verification yourself.

提交回复
热议问题