0

I have a cordova application that is using an invalid SSL certificate.

In 3.3.6 I could override the SSL certificate by extending the org.apache.cordova.CordovaWebViewClient and overriding the method public void onReceivedSslError, i.e.

import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaWebViewClient;
import org.apache.cordova.CordovaInterface;

import android.net.http.SslError;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;

public class MyWebViewClient extends CordovaWebViewClient {

    public MyWebViewClient(CordovaInterface cordova, CordovaWebView view) {
        super(cordova, view);
    }

    @Override
    public void onReceivedSslError
    (WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed();
    }

}

And then from the starting Java file I could use

MyWebViewClient myWebViewClient = new MyWebViewClient(this, this.appView);
this.appView.setWebViewClient(myWebViewClient);

After upgrading to 5.2.2 I can't use something like that as the WebView has been changed to Crosswalk. What I have tried based on the guidelines of Ignoring invalid SSL certificates on Cordova for Android and iOS, is to change the code above as following:

import org.apache.cordova.CordovaWebView;
import org.apache.cordova.engine.SystemWebViewClient;
import org.apache.cordova.engine.SystemWebViewEngine;
import org.apache.cordova.CordovaInterface;

import android.content.Intent;
import android.net.Uri;
import android.net.http.SslError;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;

public class myWebViewClient extends SystemWebViewClient {

    public myWebViewClient(SystemWebViewEngine systemWebViewEngine) {

        super(systemWebViewEngine);
    }
    @Override
    public void onReceivedSslError
    (WebView view, SslErrorHandler handler, SslError error) {


            handler.proceed();
        }

    }

And in the code calling:

CordovaActivity ca = (CordovaActivity) this.cordovaInterface.getActivity();
SystemWebView view = (SystemWebView) appView.getView();
myWebViewClient cWebClient = new myWebViewClient((SystemWebViewEngine) appView.getEngine());
appView.clearCache();
view.setWebViewClient(cWebClient);

However I receive the following exception

Unknown error during webview in activity
java.lang.ClassCastException: org.crosswalk.engine.XWalkCordovaView cannot be cast to org.apache.cordova.engine.SystemWebView
    at myProject.InitApp.onCreate(initApp.java:182)
    at android.app.Activity.performCreate(Activity.java:6289)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
    at android.app.ActivityThread.access$900(ActivityThread.java:177)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5951)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

Any help on that? It seems as if the Crosswalk doesn't allow such overriding. Is there any way to override it?

6
  • I'm following your instructions in the linked article . Im overriding onReceiveSSLErrors() on SystemWebViewClient.java. You cannot cast XWalkCordovaView (extends from xwalkView its core project) to SystemWebViewClient (extends webviewclient its android class). I think you should follow the instructions, and override the method onREceiveSSLErros() not extend class SystemWebViewClient Sep 12, 2016 at 10:46
  • Yes...I'm checking the code as well. It's an interface and as a consequence it cannot be cast. However I've tried to change the code and when I debug it from Android Studio it doesn't seem to do anything. I'm not so sure if it's compiled or Android Studio takes something else... Sep 12, 2016 at 12:47
  • I'm working on it too. Im found a clue about that, I'm trying to override XwalkCordovaResourceClient.java with the same logic. But it is true that it seems that not compile those classes. If I can fix it I will comment on here Sep 12, 2016 at 13:04
  • If you have this problem working with inapp browser , I suggest try iframe inside cordova html page . It ignores the SSL error . Sep 12, 2016 at 14:08
  • My problem was the server certificate it`s not considered trusted by Android system. The code its fine. Sep 13, 2016 at 8:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.