其他分享
首页 > 其他分享> > android – Universal-Image-Loader | SSLHandshakeException:握手失败

android – Universal-Image-Loader | SSLHandshakeException:握手失败

作者:互联网

我有一个ListView与项目中的一些内容(TextViews,ImageView …).我正在使用Nostra的UIL加载项目中的图像,但其中一些无法加载.当我调用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)

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

这是一个示例图像,无法加载:

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

(我可以附加一个包含整个错误的日志 – UIL自动将其放入Log的错误)

解决方法:

如果我是对的,你必须创建一个证书,签名并将其包含在你的应用程序中.或者更改服务器配置(further information here).

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

在项目中包含此类

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) {
    }
}

}

扩展您的应用程序,并在您的onCreate中调用’nuke’功能

public class YOURApplication extends Application {

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

    //...

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

我发现这个代码在SO中,但目前找不到链接….

标签:android,imageview,image-loading,sslhandshakeexception,universal-image-loader
来源: https://codeday.me/bug/20190714/1459312.html