我需要在5.0版本之前的设备上启用TLS 1.2。 我实现了TLSSocketFactory:
public class TLSSocketFactory : SSLSocketFactory
{
......
}
TlSSocketFactory implementation
我实现了AndroidCustomClientHandler
我对服务器的请求是:
_client.SendAsync(aRequest, cancellationToken.Token);
aRequest是HttpRequestMessage的类型。
我收到一个例外:
Javax.Net.Ssl.SSLHandshakeException:
java.security.cert.CertPathValidatorException: Trust anchor for ` .
certification path not found. --->`
Java.Security.Cert.CertificateException:
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. ---> Java.Security.Cert.CertPathValidatorException: Trust anchor for certification path not found.
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <7802aa64ad574c33adca332a3fa9706a>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00014] in <7802aa64ad574c33adca332a3fa9706a>:0
at Javax.Net.Ssl.HttpsURLConnectionInvoker.Connect () [0x00000] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/obj/Release/android-26/mcw/Javax.Net.Ssl.HttpsURLConnection.cs:417
at Xamarin.Android.Net.AndroidClientHandler+<>c__DisplayClass42_0.<ConnectAsync>b__0 () [0x0005a] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs:308
at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Threading.Tasks.Task.Execute () [0x00010] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at Xamarin.Android.Net.AndroidClientHandler+<DoProcessRequest>d__44.MoveNext () [0x000e4] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs:357
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0
at Xamarin.Android.Net.AndroidClientHandler+<SendAsync>d__39.MoveNext () [0x001e2] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs:275
我该如何解决这个问题? 非常感谢。