Phonegap/Cordova whitelisted cross domain SSL request not working after exporting APK

后端 未结 2 843
情深已故
情深已故 2020-12-16 06:07

I have created a phonegap app which needs to communicate with a self signed SSL service.

I whitelisted my url in res/xml/cordova.xml like so:

2条回答
  •  [愿得一人]
    2020-12-16 06:24

    I did the following to get around the restriction (currently using Cordova 1.7.0). This is definitely inherently insecure:

    public class MyWebViewClient extends CordovaWebViewClient {
    
        public MyWebViewClient(DroidGap ctx) {
            super(ctx);
        }
    
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            // testing against getPrimaryError() or hasErrors() will fail on Honeycomb or older.
            // You might check for something different, such as specific info in the certificate,
            //if (error.getPrimaryError() == SslError.SSL_IDMISMATCH) {
                handler.proceed();
            //} else {
            //    super.onReceivedSslError(view, handler, error);
            //}
        }
    }
    

    and then in the main activity:

    @Override
    public void init() {
        super.init();
    
        //pass in our webviewclient to override SSL error
        this.setWebViewClient(this.appView, new MyWebViewClient(this));
    }
    

提交回复
热议问题