android: TrustFailure exception with inner exception: Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED on android and xamarin-forms on android
Steps to Reproduce
(See attached project)
- Click floating action button
- App will attempt to enroll on our servers 10 times
- App reports number of failures, and posts the exception to logcat
Expected Behavior
App successfully enrolls 10 times in a row, and reports no errors, every time.
Actual Behavior
App will somewhat consistently fail to enroll at first, but eventually succeed. The first attempt will almost always fail with a TrustFailure exception, but after a few tries will succeed.
The error started occurring this week out of nowhere. It’s been happening to apps in development, but also published apps that haven’t been updated since March. Additionally, the error is only happening on Android, not on xamarin.iOS apps. We’re seeing the issue on multiple versions of Android (confirmed on 4.4, 7.1, 8.1, and 9.0), and in apps made in xamarin.android and xamarin.forms.
The certificates for the server look fine at a glance, but I have attached the certs as they appear in logcat in case they’re the problem. The certificates are the same, no matter if it succeeds or fails.
Version Information
Microsoft Visual Studio Community 2019 Version 16.5.4 VisualStudio.16.Release/16.5.4+30011.22 Microsoft .NET Framework Version 4.8.03752
Installed Version: Community
Visual C++ 2019 00435-60000-00000-AA425 Microsoft Visual C++ 2019
ASP.NET and Web Tools 2019 16.5.236.49856 ASP.NET and Web Tools 2019
ASP.NET Web Frameworks and Tools 2019 16.5.236.49856 For additional information, visit https://www.asp.net/
Azure App Service Tools v3.0.0 16.5.236.49856 Azure App Service Tools v3.0.0
Azure Functions and Web Jobs Tools 16.5.236.49856 Azure Functions and Web Jobs Tools
C# Tools 3.5.0-beta4-20153-05+20b9af913f1b8ce0a62f72bea9e75e4aa3cf6b0e C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Extensibility Message Bus 1.2.0 (d16-2@8b56e20) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info
Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30207.1
Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.
Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft Library Manager 2.1.25+gdacdb9b7a1 Install client-side libraries easily to any web project
Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers
Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards
Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.
Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package
Mono Debugging for Visual Studio 16.5.514 (c4f36a9) Support for debugging Mono processes with Visual Studio.
NuGet Package Manager 5.5.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info
SQL Server Data Tools 16.0.62003.05170 Microsoft SQL Server Data Tools
TypeScript Tools 16.0.20225.2001 TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 3.5.0-beta4-20153-05+20b9af913f1b8ce0a62f72bea9e75e4aa3cf6b0e Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 10.8.0.0 for F# 4.7 16.5.0-beta.20181.6+85af456066acd4e76d2bc7821b44a325e46f2fca Microsoft Visual F# Tools 10.8.0.0 for F# 4.7
Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
Visual Studio Container Tools Extensions (Preview) 1.0 View, manage, and diagnose containers within Visual Studio.
Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers
VisualStudio.DeviceLog 1.0 Information about my package
VisualStudio.Foo 1.0 Information about my package
VisualStudio.Mac 1.0 Mac Extension for Visual Studio
Xamarin 16.5.000.533 (d16-5@9152e1b) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 16.5.0.470 (remotes/origin/d16-5@681de3fd6) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates 16.5.49 (0904f41) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
Xamarin.Android SDK 10.2.0.100 (d16-5/988c811) Xamarin.Android Reference Assemblies and MSBuild support. Mono: c0c5c78 Java.Interop: xamarin/java.interop/d16-5@fc18c54 ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.28.0@46204c4 Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-5@9f4ed4b
Xamarin.iOS and Xamarin.Mac SDK 13.16.0.13 (b75deaf) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Log File
Lastly, I apologize for not adding a label, I couldn’t find a way to do so for some reason.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 49 (7 by maintainers)
Hello everybody. I came across this problem today when the DST Root CA X3 expired earlier this day. Our Xamarin App on Android stopped working with the exact inner exception mentioned above. This CA was longtime used with let’s encrypt certificates which we are using for our service.
Chrome and other browsers on Android had no problem in opening websites from on of our servers but the Xamarin app has. I renewed our current certificate and switched to the ISRG Root X2 chain which is not terminating in a DST Root but this had no impact.
I switched from the managed HTTPClient to the Android option but this has not changed the behavior either.
Our current workaround is to not use LE for our certificates, but I’m not absolutely happy with that. So can somebody explain, why this is a problem? Am I doing something wrong? I guess that there must be others using Let’s Encrypt with their Xamarin Apps and I guess they are in kind of trouble too? Or is it just us…?
I encountered a similar problem with Sectigo CA root expiration. As @visuall say, i changed the implementation of HTTP handler from managed to Android. This perfectly solved the problem for me
Implementation before Fail to validate certificate chain with expired Sectigo cert.
Implementation after (Forms side) Successfully validates the flawed certificate chain
Implementation after (Android side) Don’t forget to add dependency
System.Net.Httpfrom NuGetI’m not sure this is actually a duplicate of those issues. They seem to be about custom validation handlers not working. The problem is, we don’t have any custom validation handlers for SSL certificates, the built-in one worked fine up until the start of this week. Additionally, the version that worked in 9.0 but not in 10.0 still works just fine for us. On top of that, it started happening in apps that haven’t been updated since March, but we didn’t see any issues before Monday of this week.
If we add the following code, the issue stops happening:
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicy) => { return true; };This is obviously bad practice as it completely bypasses any validation of the SSL certificate, opening us up to man-in-the-middle attacks. We could write our own code here, but it would likely not be as secure as something coming from Microsoft.Looks like duplicate of https://github.com/xamarin/xamarin-android/issues/3682#issuecomment-535834783 and https://github.com/xamarin/xamarin-android/issues/3705
Please try to use the
HttpClientHandler.ServerCertificateCustomValidationCallbackI can confirm this issue with the expiration of the DST Root CA X3, which is still used for cross-signing ISRG Root X1.
An immediate fix on the server side is to force the ISRG Root X1.
e.g. with Certbot
certbot renew --force-renewal --preferred-chain "ISRG Root X1"[Update]
Don’t forget to reload the web servers to apply the new certificate @daltonks was a bit faster 😉
This is the last thing I will post about it here or anywhere, because this is still derailing this issue. As already mentioned: if you have something to see do it on an appropriate channel like a discussion. I am also kind of disappointed that I spend a lot of time talking to you about this @juwens and you still choose this approach.
I’m sorry you understood it this way, but that is not what I said nor meant.
As already pointed out, there is a bug for this on the Mono repo, so if anything this should’ve been probably closed. But as I am not on this team, do not have any insights on how they work nor do I have even any rights to do anything on this repo, that is up to them.
Aggression is never the answer. If you are frustrated with something and you think Xamarin is no longer the right option for you, that is of course not what we want. But being bitter on the internet is never a good look on anyone.
@jfversluis as a dev on the team, i think it’s a bad idea to write 18! months after the bug was created, and several people posting here too, that nothing can be done, because you work on MAUI and “it’s not a XF bug”, and the author should create an issue for the mono runtime.
1. you cannot ignore bugs of a production release, with the argument that you are working on the next version 2. if it’s a problem of the mono runtime, it should have been redirected by an MS employee, when you triaged it back in may 2020
These things is what makes people more and more aggressive in there communication.
Complaining about severe nuisances (without any insight of the XF team) is the last resort devs have, before giving up and turning away from XF and moving to a competitor like Flutter.
//cc @maddymontaquila
I’m was also having the same issue but after some research trials and errors I found out the solution well it’s more like a workaround. The root certificate of Let’s encrypt is expired so just remove it from the
yourcert-chain.prem.-----BEGIN CERTIFICATE-----at the end of the file-----BEGIN CERTIFICATE-----to-----END CERTIFICATE-----The same issue with new lets encrypt root cert !
I have been able to go around this by using the native Android http handler - AndroidClientHandler. It is properly validating the certificate in such case.
Sorry @naman20sharma. We never got any support on fixing this bug. We ended up giving instructions to the android users to delete the expired root cert (see my other earlier posts) so that the cert chain ended up finding the valid root cert. A terrible solution. This bug caused the app to be broken for hundreds of our government app users.
How is it possible that a call from flutter works and xamarin doesn’t? this makes me rethink many things …
This does not work for me and I use refit
While they certainly share a good amount of code, two of the biggest changes between Xamarin.Android and .NET for Android are:
These two changes should eliminate a large class of bugs that occurred on Xamarin.Android.
Probably because Xamarin doesn’t have any update in last 6 months they are focusing on Maui