-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# Android SSL Crash using System.Net.Http.HttpClient #84559
Comments
Of course as soon as I post this, I find dotnet/runtime#94230 which may or may not be related given that Android should be using dotnet7 |
@jpetersen23 I don't think it's the same issue, I'm able to reproduce it on Android API 29 emulator. Unfortunately, there isn't much information in the logs so it's hard to pinpoint where the bug originates. |
I'm having the same issue while trying to use Grpc.Net.Client to connect to a TLS backed Grpc server. The game crashes on a physical Android device with Android v11 (API level 30). I have a .Net MAUI application which uses the same library and works fine on Android devices. I have below trace log while debugging with Android Studio:
So the warning here: could give a hint for the reason of the crash. What do you think this could be related to? |
Same issue but coming from the C# PlayFabSDK. I can't seem to get any debug info or call stack. I used debug lines to find that the failure occurred at the PostAsync() call. While groping in the dark I tried this suggestion: https://stackoverflow.com/questions/48475378/httpclient-not-working-on-android But still no dice. |
Any type of SSL stream made by .Net fails actually. I tried using raw sockets with SSLStream and the app crashed again. |
This looks like you're missing OpenSSL (libssl.so) which the libSystem.Security.Cryptography.Native.OpenSsl.so library depends on. |
Well actually when I unzip the APK, I see that libSystem.Security.Cryptography.Native.OpenSsl.so is actually packaged under assets/.godot/mono/publish/arm64. I've attached the directory listing. But like you said, I don't see libssl.so here. So if it is depending on it, that makes perfect sense that the app crashes. |
I just checked the APK of my MAUI project which uses Grpc and couldn't locate libssl.so there as well. |
@ozanyasindogan that's expected, MAUI doesn't use the The doc you linked talks about not referencing the libssl which ships as part of Android, but you're fine to bring your own (with all the caveats that entails). |
@ozanyasindogan Please have patience. Android support for C# in 4.2 is experimental, and some issues like this are expected and will be fixed in due time, once contributors have time to debug the issue and provide a fix. |
Thank you very much Rémi @akien-mga for given attention, I really appreciate all the work done by Godot team to create such a great product. Also thank you very much Alexander @akoeplinger for your valuable comments. It really encourages me as a .Net developer that MS staff is supporting the use of .Net in various platforms. |
One thing you can try is downloading and extracting https://dl.google.com/android/maven2/com/android/ndk/thirdparty/openssl/1.1.1p-beta-1/openssl-1.1.1p-beta-1.aar and packaging libssl.so and libcrypto.so into the app and see if that helps. |
Can confirm that it helps to fix the problem. |
@akoeplinger @spirifoxy how do I go about packaging that with the android build? Do I package it as an Android plugin? https://docs.godotengine.org/en/stable/tutorials/platform/android/android_plugin.html Or do I somehow configure .net to use that .so? |
I found something interesting I'll try tomorrow: dotnet/maui#6174 (comment) |
For some reason My csproj currently looks like:
Settings UseNativeHttpHandler doesn't seem to make a difference true or false. It did work for this person here: dotnet/maui#6174 (comment) |
Manually packaging as suggested is making progress. Now I get:"The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot" But the good news is its no longer crashing. Now to figure out how to properly include a certificate chain that makes it happy. This is an area I'm not familiar with. And for anyone wondering how to manually include those libraries: Download and extract the openssl lib from here: https://dl.google.com/android/maven2/com/android/ndk/thirdparty/openssl/1.1.1p-beta-1/openssl-1.1.1p-beta-1.aar Then once you extract it, you should have a folder structure similar to: Then drag those into your AndroidManifest directory: Then when you export, they should be included in the apk. Now to figure out the cert issues! :) |
Made a new finding which I think is good news. The certificate error originates on the .NET side. Was able to confirm by setting .NET to accept all certs: HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =>
{
// Implement your custom certificate validation logic here
return true; // Return true to accept the certificate
};
this._client = new HttpClient(handler); Specifically, I tested it with PlayFab as @sanform pointed out like this: public class MyPlayFabPollyHttp : PlayFabPollyHttp
{
public MyPlayFabPollyHttp() : base()
{
HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =>
{
// Implement your custom certificate validation logic here
return true; // Return true to accept the certificate
};
this._client = new HttpClient(handler);
}
} And then created an instance of the playfabClient like so: PluginManager.SetPlugin(new MyPlayFabPollyHttp(), PluginContract.PlayFab_Transport);
playFabClient = new PlayFabClientInstanceAPI(new PlayFabApiSettings
{
TitleId = PlayFabUtils.TITLE_ID,
}); Then my mqtt client crashed with cert errors (probably for the same reason). So gonna go see if simply accepting all certs gets me to the next step there as well. THIS IS NOT A SOLUTION This opens the application up to man in the middle attacks. Don't use this as the final solution. I'm merely pointing out that the next issue appears to be on the .NET side. Probably as simple as reading in and making use of the certs godot has in the repo. |
How did you determine this was what was causing the crash? The application gets farther now but then crashes. Would like to determine what is causing the current crash :) |
I've determined that the mqtt client seems to be working properly when accepting all certs. It may be something else causing my game to crash on Android at this point. I'll post more updates here if they are related and if not, I'll open a new issue. Assuming there is an issue on the Godot end of course. I'll also post an update with how I officially handle the certs when I get around to it if there isn't an official solution on here by then. |
I hope this issue will be fixed by this: #88803 |
Perfect! I'll merge that into my fork tomorrow and see how it goes. Thanks @ozanyasindogan! :) It's a perfect birthday present! 😊 |
Happy birthday :) |
FWIW |
Gotcha. That makes sense. Thank you for that info! :) |
Godot version
4.2-beta4
System information
Godot v4.2.beta4.mono - macOS 13.6.0 - Vulkan (Mobile) - integrated Apple M2 Max - Apple M2 Max (12 Threads)
Issue description
Making a network request using System.Net.Http.HttpClient to "https://www.example.com" cause a crash, calling "http://www.example.com" does not crash. If I use Godot's node HttpRequest it does not crash.
The logcat output for the crash looks like:
11-06 17:44:57.813 3989 4048 I godot : Pressed button SystemSsl
11-06 17:44:57.856 3989 4048 I godot : send request to https://www.example.com
11-06 17:44:57.902 4405 4405 I SKBD : and isTosAccept false
11-06 17:44:58.071 1061 1209 D DnsProxyListener: DNSDBG::dns addrinfo af 0
11-06 17:44:58.103 4405 4405 I SKBD : and isTosAccept false
11-06 17:44:58.282 3989 4201 E godot : USER ERROR: BUG: Unreferenced static string to 0: Physics2DConstraintSolveIslands
11-06 17:44:58.282 3989 4201 E godot : at: unref (core/string/string_name.cpp:127)
11-06 17:44:58.282 3989 4201 E godot : USER ERROR: BUG: Unreferenced static string to 0: Physics2DConstraintSetup
11-06 17:44:58.282 3989 4201 E godot : at: unref (core/string/string_name.cpp:127)
--------- beginning of crash
11-06 17:44:58.284 3989 4201 F libc : FORTIFY: pthread_mutex_lock called on a destroyed mutex (0x6f51b6400c)
Steps to reproduce
This is the code that crashes in its simplest form:
Minimal reproduction project
The sample project has 4 buttons, each doing a different network call to example.com:
SystemSSL
SystemNonSSL
GodotSSL
GodotNonSSL
The system ones use System.Net.Http.HttpClient, the Godot ones use a HttpRequest node.
SSLCrashExample_Buttons_For_Zipping.zip
The text was updated successfully, but these errors were encountered: