I have SSL error untrusted on my Xamarin application on adroid app (iOS works good). I need to use Webview.
I follow this instructions for httpclient : https://thomasbandt.com/certificate-and-public-key-pinning-with-xamarin . I need to set TrustManagerFactory, KeyManagerFactory and KeyStore, but in WebViewRenderer and WebViewClient I can not find option to add my certificates as trusted. I dont want to compare certificates in OnReceivedSslError override method, because certificate that come in this method is the final certificate (that will expire up to one year). I want to add my root and intermediate certificates to list of trusted certificates before checking certificate method in webview will be called.
ExportRenderer:
public class CustomWebView : WebViewRenderer
{
private TrustManagerFactory _trustManagerFactory;
private KeyManagerFactory _keyManagerFactory;
private KeyStore _keyStore;
public CustomWebView(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var customWebViewClient = new CustomWebViewClient();
_trustManagerFactory = CertificateHelper.TrustManagerFactory;
_keyManagerFactory = CertificateHelper.KeyManagerFactory;
_keyStore = CertificateHelper.KeyStore;
Control.SetWebViewClient(customWebViewClient);
}
}
}
How to set TrustManagerFactory, KeyManagerFactory and KeyStore here?
question from:https://stackoverflow.com/questions/65905802/xamarin-webview-android-ssl-error-untrusted-how-to-add-trusted-certificate