我使用 aHttpClient與我的服務器進行通信,如下所示:
private static readonly HttpClientHandler Handler = new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
AllowAutoRedirect = true,
};
private static readonly HttpClient Client = new HttpClient(Handler, false);
問題是我System.AggregateException在 Android 上遇到了例外。例外詳細資訊可以在下面的螢屏截圖中看到:

應用程式在 iOS 上運行得非常好。
服務器正在使用Let's Encrypt證書,問題僅在一周前更新證書后才浮出水面。
我已經檢查了有關證書有效性的任何內容(到期、DNS 名稱等),一切似乎都沒有問題。
uj5u.com熱心網友回復:
這是Xamarin.Android 中的一個長期存在的問題
紅色鏈是過去發生的事情:IdenTrust DST Root CA X3 是一個舊的根證書,幾乎在任何地方都受到信任,包括在 2.3.6 以后的 Android 設備上。這就是 LetsEncrypt 過去使用的作為他們的根,這意味著每個人都信任他們。然而,這個 IdenTrust DST Root CA X3 最近過期了,這意味著一堆設備不會信任任何由它簽名的東西。LetsEncrypt 需要移動到他們自己的根證書。
藍鏈是理想的新鏈——ISRG Root X1 是 LetsEncrypt 自己的根證書,它包含在 Android 7.1.1 中。Android 設備 >= 7.1.1 將信任已由此 ISRG Root X1 簽名的證書。
但是,問題是舊的 7.1.1 之前的 Android 設備不知道 ISRG Root X1,并且不信任它。
LetsEncrypt 使用的解決方法是舊的 Android 設備不檢查根證書是否已過期。因此,它們默認提供一個鏈,其中包括 LetsEncrypt 的根 ISRG Root X1 證書(最新設備信任該證書),但還包括來自現已過期的 IdenTrust DST Root CA X3 的簽名。這意味著舊的 Android 設備信任該鏈(因為它們信任 IdenTrust DST Root CA X3,并且不檢查它是否已過期),而較新的設備也信任該鏈(因為它們能夠解決這個問題,即使鏈的根已經過期,他們仍然相信中間的 ISRG 根 X1 證書本身就是一個有效的根,因此信任它)。
這是綠色路徑,LetsEncrypt 當前默認服務的路徑。
However, the BoringSSL library used by xamarin-android isn't Android's SSL library. It 1) Doesn't trust the IdenTrust DST Root CA X3 because it's expired, and 2) Isn't smart enough to figure out that it does trust the ISRG Root X1 which is also in the chain. So if you serve the green chain in the image above, it doesn't trust it. Gack.
The options therefore are:
- Don't use BoringSSL and do use Android's SSL library. This means that xamarin-android behaves the same as other Android apps, and trusts the expired root. This is done by using
AndroidClientHandleras described previously. This should fix Android >= 2.3.6. - 請使用 BoringSSL,但從 Android 的信任存盤中洗掉過期的 IdenTrust DST Root CA X3(設定中的“Digital Signature Trust Co. - DST Root CA X3”)。這會誘使 BoringSSL 在它信任的 ISRG Root X1(在 Android 7.1.1 上)停止其鏈。但是,這僅適用于信任 ISRG Root X1(7.1.1 )的 Android 設備。
- 請使用 BoringSSL,并更改您的服務器以使用
--preferred-chain "ISRG Root X1". 這意味著 BoringSSL 完全忽略 IdenTrust DST Root CA X3,并根植于 ISRG Root X1。這再次僅適用于信任 ISRG Root X1(即 7.1.1 )的 Android 設備。 - 執行與 3 相同的操作,但通過手動編輯 fullchain.pem。
- 使用另一個 CA,例如 ZeroSSL,它使用受信任回 Android 2.2 的根,并且不會在 2038 年到期。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/391093.html
標籤:C# 安卓 沙马林 xamarin.forms 让加密
