2017-03-07 84 views
2

我做了一个应用程序,它使用WebView和YouTube iframe观看YouTube视频。我使用WebViewClient来存储所有网址,我想强制使用我生成的私钥,这样我就可以解密Wireshark流量(我使用Android命令行和tcpdump命令在应用中捕获流量)。onReceivedClientCertRequest不叫

WebViewClient类是这样的:

private class MyWebviewClient extends WebViewClient { 

    @Override 
    public void onReceivedError(WebView view, int errorCode, 
           String description, String failingUrl) { 
     // TODO Auto-generated method stub 
     super.onReceivedError(view, errorCode, description, failingUrl); 
     Log.d(TAG, "onReceivedError : description = " + description); 

    } 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     // TODO Auto-generated method stub 
     System.out.println("********************************************"); 
     Log.d(TAG, "shouldOverrideUrlLoading : url = " + url); 
     return true; 
    } 

    @Override 
    public void onLoadResource(WebView view, String url) { 
     webAppInterface.logResourceURL(url); 
     System.out.println("************************************ " + url + " ************************************"); 
    } 

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

    //forcing my private key 
    @Override 
    public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { 
     System.out.println("test test test"); 

     X509Certificate cert = CertificateKey.getCertificate(); 
     X509Certificate[] mCertificates = new X509Certificate[1]; 
     mCertificates[0] = (X509Certificate)cert; 

     request.proceed(CertificateKey.getKey(), mCertificates); 
    } 
} 

的问题是方法onReceivedClientCertRequest不会被调用!我甚至没有打印。

  • 其他所有方法工作打算(即onLoadResource作品)
  • 我使用SSL/HTTPS如可以在Wireshark的捕获的流量 wireshark traffic
  • 我使用的方法onReceivedSslError(view, handler, error)在错误
  • 我的情况可以看出我使用自己生成的证书(这是不是由CA签署,至少我认为)
  • 证书和私钥都保存在手机上

问题是Android版本(目前为5.​​1)吗?

回答

0

将每次调用onReceivedClientCertRequest方法,服务器端,需要客户端认证。这不是一个Web服务器的常用服务(当然,Youtube根本不需要客户端身份验证),并且由于这个原因,你不能强制任何东西。此外,onReceivedClientCertRequest方法是一个侦听器,因此默认情况下它取决于要触发的外部输入,因为Web服务器从不向您的浏览器代理(例如您的WebView)请求客户端证书,您的代码将永远不会执行。

如需进一步了解详情,请参阅Android guide to Client Certificatehow SSL works in 2-way handshake