I'm trying to access a website from an Android application with WebView library, so I have:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.setWebViewClient(
new SSLTolerentWebViewClient()
);
myWebView.loadUrl("https://www.mywebsite.ro");
}
}
class SSLTolerentWebViewClient extends WebViewClient {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
if (error.toString() == "piglet")
handler.cancel();
else
handler.proceed(); // Ignore SSL certificate errors
}
}
In debug I have:
D/OpenSSLLib: OpensslErr:Module:20(119:258); file:external/openssl/ssl/s23_clnt.c ;Line:714;Function:ssl23_get_server_hello
W/chromium: external/chromium/net/socket/ssl_client_socket_openssl.cc:171 [0209/105028:WARNING:ssl_client_socket_openssl.cc(171)] Unmapped error reason: 258
E/chromium: external/chromium/net/socket/ssl_client_socket_openssl.cc:792 [0209/105028:ERROR:ssl_client_socket_openssl.cc(792)] handshake failed; returned -1, SSL error code 1, net_error -2
D/chromium/tcp: LogConnectCompletion with error:-2
D/WebRequest: request error: -2
D/chromium: Unknown chromium error: -2
V/webview: setCertificate=null
V/webcore: setupViewport mRestoredScale=0.0 mViewScale=2.0 mTextWrapScale=2.0 data.mScale= 2.0
V/webcore: viewSizeChanged w=360; h=559; textwrapWidth=360; scale=2.0
D/skia: Flag is not 10