通用图像加载器 |SSLHandshakeException:握手失败

Universal-Image-Loader | SSLHandshakeException: Handshake failed(通用图像加载器 |SSLHandshakeException:握手失败)

本文介绍了通用图像加载器 |SSLHandshakeException:握手失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView,其中包含一些内容(TextViews、ImageView...).我正在使用 Nostra 的 UIL 来加载项目中的图像,但其中一些他们无法加载.当我调用 Log.v(String.valueOf(failReason.getCause()); 时,这就是我得到的:

I have a ListView with some content (TextViews, ImageView...) in the items. I'm using UIL by Nostra to load the images in the items but some of them fail to load. This is what do I get, when i call Log.v(String.valueOf(failReason.getCause()); :

11-16 23:52:20.447: V/javax.net.ssl.SSLHandshakeException: Handshake failed(17467): failz
11-16 23:52:20.657: V/NativeCrypto(17467): SSL handshake aborted: ssl=0x15fd758: Failure in SSL library, usually a protocol error
11-16 23:52:20.657: V/NativeCrypto(17467): error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:762 0x4c2ed485:0x00000000)
11-16 23:52:21.207: V/NativeCrypto(17467): SSL handshake aborted: ssl=0x1562468: Failure in SSL library, usually a protocol error
11-16 23:52:21.207: V/NativeCrypto(17467): error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:762 0x4c2ed485:0x00000000)

你不知道,为什么会出现这个问题或者我该如何解决?

Don't you know, why is there this problem or how can I solve it?

这是一张示例图片,未加载:

This is one example image, which doesn't get loaded:

http://bigparty.cz/photos/headlinefoto/13.jpg

(我可以附加一个带有整个错误的日志 - UIL 自动放入日志的错误)

(I can attach a Log with the whole error - error which UIL automatically puts to Log)

推荐答案

如果我是对的,您必须创建一个证书,对其进行签名并将其包含在您的应用程序中.或更改服务器配置(此处了解更多信息).

If I'm right you have to create a certificate, sign it and include it in your app. Or change the server configuration (further information here).

否则,您可以信任应用中的每次握手.这不是最好的方法,但在实施过程中非常有用.

Otherwise you can trust every handshake within your app. This is not the best approach, but really useful during implementation.

在你的项目中包含这个类

Include this class in your project

public class SSLCertificateHandler {

protected static final String TAG = "NukeSSLCerts";

/**
 * Enables https connections
 */
public static void nuke() {
    try {
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                X509Certificate[] myTrustedAnchors = new X509Certificate[0];
                return myTrustedAnchors;
            }

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };

        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String arg0, SSLSession arg1) {
                return true;
            }
        });
    } catch (Exception e) {
    }
}

}

扩展你的Application,并在你的onCreate中调用'nuke'函数

Extend your Application, and call the 'nuke' function in your onCreate

public class YOURApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();

    //...

    // trust all SSL -> HTTPS connection
    SSLCertificateHandler.nuke();
}

我在 SO 中找到了这段代码,但目前找不到链接....

I found this code in SO, but can't find the link at the moment....

这篇关于通用图像加载器 |SSLHandshakeException:握手失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:通用图像加载器 |SSLHandshakeException:握手失败

基础教程推荐