1

I'm trying to send a request to a web api in Xamarin.Forms. The api requires a client certificate. I attempted to add the client certificate in the core project and in the native project as e.g. described here xamarin.android adding client certificate. However, I always get the response "400 No required SSL certificate was sent". If I send the request via e.g. Postman or openSSL, everything works fine. I've tested the request on Android and on iOS, but I always get the 400. Can anyone help?

Note: For Android, I am using the HttpClient implementation 'Android' and the TLS implementation 'Native TLS 1.2+'

The code I am using in the core project:

            var handler = new HttpClientHandler
            {
                ClientCertificateOptions = ClientCertificateOption.Manual,
                SslProtocols = System.Security.Authentication.SslProtocols.Tls12,
                ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true
            };

            //clientCertificateFileName is the location where the certificate is saved
            var clientCertificate = new X509Certificate2(clientCertificateFileName, "password");
            handler.ClientCertificates.Add(clientCertificate);

            client = new HttpClient(handler);

            var response = await client.GetAsync(targetUrl);
  • At first, the [offical document](https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/http-stack?tabs=windows) recommend the AndroidClientHandler to the developers. In addition, 400 always means the parameter format false and you can check it over. – Liyun Zhang - MSFT Jan 14 '22 at 09:33
  • 1
    To anyone having the same question: I was able to implement the sending of the client certificate natively in Android and iOS (for Android by using code similar to the one in the link I referenced), but in the end we used the great library ModernHttpClient-updated: https://github.com/alexrainman/ModernHttpClient as we also needed certificate pinning and found no easy way to implement this together with the sending of the client certificate. – Nicolas.Mueller Jun 10 '22 at 12:17

0 Answers0