Filedownloader: 大神 为什么这个下载地址不能正常下载的

Created on 28 Dec 2016  ·  9Comments  ·  Source: lingochamp/FileDownloader

https://f.qr2c.cn/data/uploads/paper/2016/12/27/5861c2082ac92.zip

FileDownloader.FileDownloadMgr: can't continue 1159061853 file not suit, exists[FALSE], directory[FALSE]

FileDownloader.FileDownloadRunnable: On error 1159061853 javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

question

All 9 comments

这是https,默认是不支持的,不过你可以自己加入。可以这样处理:
FileDownloader.init(appContext,
new FileDownloadHelper.OkHttpClientCustomMaker() { // is not has to provide.
@Override
public OkHttpClient customMake() {
// just for OkHttpClient customize.
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
// you can set the connection timeout.
builder.connectTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
builder.readTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
builder.writeTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
// you can set the HTTP proxy.
builder.proxy(Proxy.NO_PROXY);

                    //创建TrustManager
                    X509TrustManager xtm = new X509TrustManager() {
                        @Override
                        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                        }

                        @Override
                        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                        }

                        @Override
                        public X509Certificate[] getAcceptedIssuers() {
                            return new X509Certificate[]{};
                        }
                    };
                    //这个好像是HOST验证
                    X509HostnameVerifier hostnameVerifier = new X509HostnameVerifier() {
                        public boolean verify(String arg0, SSLSession arg1) {
                            return true;
                        }

                        public void verify(String arg0, SSLSocket arg1) throws IOException {
                        }

                        public void verify(String arg0, String[] arg1, String[] arg2) throws SSLException {
                        }

                        public void verify(String arg0, X509Certificate arg1) throws SSLException {
                        }
                    };
                    try {
                        // Install the all-trusting trust manager
                        final SSLContext sslContext = SSLContext.getInstance("TLS");
                        sslContext.init(null, new TrustManager[]{xtm}, new java.security.SecureRandom());
                        // Create an ssl socket factory with our all-trusting manager
                        final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                        builder.sslSocketFactory(sslSocketFactory, xtm);
                        builder.hostnameVerifier(hostnameVerifier);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    // etc.
                    return builder.build();
                }
            });

这个就是接受所有的证书,就能过正常下载https的文件链接

  • 1.3.9之前的版本使用OkHttp是默认支持的。如果1.3.9之后的版本要使用okhttp,可以引入这个组件
  • 1.3.9 版本以后,默认的FileDownloadUrlConnection只是一个Demo的作用,默认是使用了URL#openConnection 去建立一个连接,默认情况下如果是Https的链接,是会实例化一个HttpsURLConnection的,而这个connection是有处理Https协议的请求的,你也可以通过HttpsURLConnection#getServerCertificates获取到当前的证书信息。

原因

我看你的错误信息应该是该域名的根证书不被信任。如果你的证书的根证书是不被信任的证书,你要绕过,完全可以自己实现FileDownloadConnection进行绕过。关于证书校验可以到这里

解决方案

你可以定制自己的FileDownloadUrlConnection来绕过证书校验,可以通过FileDownloader.setupOnApplicationOnCreate(this).connectionCreator(...).commit()来传入你的FileDownloadUrlConnection

FileDownloadUrlConnection 怎么设置 FileDownloadHelper.ConnectionCreator怎么传

@byc4426
image

您好, 带有忽略SSL验证的FileDownloadUrlConnection 传入到filedownload中, 没有生效, 是我写的不对吗

Can you please suggest what i need to change here to ignore self signed certificate ?

FileDownloadLog.NEED_LOG=true; FileDownloader.setupOnApplicationOnCreate(this) .connectionCreator(new FileDownloadUrlConnection .Creator(new FileDownloadUrlConnection.Configuration () )) .commit();

Can you please suggest what i need to change here to ignore self signed certificate ?

FileDownloadLog.NEED_LOG=true; FileDownloader.setupOnApplicationOnCreate(this) .connectionCreator(new FileDownloadUrlConnection .Creator(new FileDownloadUrlConnection.Configuration () )) .commit();

+1

@byc4426
image

一直在说自己定制,却从来不说怎么定制,我就是想知道怎么定制

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itsmallsun picture itsmallsun  ·  4Comments

mzpbvsig picture mzpbvsig  ·  6Comments

Jeffin21 picture Jeffin21  ·  4Comments

logan62334 picture logan62334  ·  3Comments

techGay picture techGay  ·  3Comments