/// <summary> /// Sets up the socket factory and the hostname verifier for the next time a /// client is requested. /// </summary> private static void Setup(SSLSocketFactory factory, IHostnameVerifier verifier) { // create our custom socket factory to handle TLS v1.2 on older devices // although we can actually use it on any Android version as it is just // a proxy class that makes sure all supported protocols are enabled //if (Android.OS.Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) //{ socketFactory = new CompleteSSLSocketFactory(factory); //} //else //{ // socketFactory = factory; //} // set the hostname verifer hostnameVerifier = verifier; }
/// <summary> /// Creates, configures and processes an asynchronous request to the indicated resource. /// </summary> /// <returns>Task in which the request is executed</returns> /// <param name="request">Request provided by <see cref="System.Net.Http.HttpClient"/></param> /// <param name="cancellationToken">Cancellation token.</param> protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { AssertSelf(); if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!request.RequestUri.IsAbsoluteUri) { throw new ArgumentException("Must represent an absolute URI", "request"); } var redirectState = new RequestRedirectionState { NewUrl = request.RequestUri, RedirectCounter = 0, Method = request.Method }; while (true) { URL java_url = new URL(EncodeUrl(redirectState.NewUrl)); URLConnection java_connection; if (UseProxy) { java_connection = java_url.OpenConnection(); } else { java_connection = java_url.OpenConnection(Java.Net.Proxy.NoProxy); } var httpsConnection = java_connection as HttpsURLConnection; if (httpsConnection != null) { IHostnameVerifier hnv = GetSSLHostnameVerifier(httpsConnection); if (hnv != null) { httpsConnection.HostnameVerifier = hnv; } } if (ConnectTimeout != TimeSpan.Zero) { java_connection.ConnectTimeout = checked ((int)ConnectTimeout.TotalMilliseconds); } if (ReadTimeout != TimeSpan.Zero) { java_connection.ReadTimeout = checked ((int)ReadTimeout.TotalMilliseconds); } HttpURLConnection httpConnection = await SetupRequestInternal(request, java_connection).ConfigureAwait(continueOnCapturedContext: false);; HttpResponseMessage response = await ProcessRequest(request, java_url, httpConnection, cancellationToken, redirectState).ConfigureAwait(continueOnCapturedContext: false);; if (response != null) { return(response); } if (redirectState.NewUrl == null) { throw new InvalidOperationException("Request redirected but no new URI specified"); } request.Method = redirectState.Method; } }
public CatsAndroidClientHandler( Func <string, IList <DotNetX509Certificate>, CtVerificationResult, bool> _verifyResultFunc) { _hostnameVerifier = new CatsHostnameVerifier(_verifyResultFunc); }
public CatsAndroidClientHandler(IHostnameVerifier hostnameVerifier) { _hostnameVerifier = hostnameVerifier; }
public CatsAndroidClientHandler() { _hostnameVerifier = new CatsHostnameVerifier(); }