C# and dotnet 4.7.1 not adding custom certificate for TLS 1.2 calls

前端 未结 3 849
野性不改
野性不改 2021-01-07 19:09

I have the following C# code, constructing an https call with a custom certificate. When using Tls 1.1, the call works fine. When using Tls 1.2 the call breaks. I using curl

3条回答
  •  感动是毒
    2021-01-07 19:50

    I believe this code is masking some type of certificate error by always blindly returning true:

    handler.ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true;
    

    I recommend you have a function to truly analyze the results of arg4. That is your SSL policy errors. Log them and you will get your answer. In my example, I write to the console, but you can write to the trace, or a file. You'll get a number which will be associated a value for the SslPolicyErrors enumeration. Based on the results you might need to check your arg3, which is your chain.

    ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => {
    
    SslPolicyErrors errs = sslPolicyErrors;
    Console.WriteLine("Policy Errors " + sslPolicyErrors.ToString());           
    return true;};
    

提交回复
热议问题