Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LOWANGA opened this issue Dec 28, 2016 · 9 comments
Closed

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

LOWANGA opened this issue Dec 28, 2016 · 9 comments
Labels

Comments

@LOWANGA
Copy link

LOWANGA commented Dec 28, 2016

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.

@10045125
Copy link

10045125 commented Jan 6, 2017

这是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();
                }
            });

@10045125
Copy link

10045125 commented Jan 6, 2017

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

@Jacksgong
Copy link
Collaborator

Jacksgong commented Jan 6, 2017

  • 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

@byc4426
Copy link

byc4426 commented Apr 20, 2018

FileDownloadUrlConnection 怎么设置 FileDownloadHelper.ConnectionCreator怎么传

@Jacksgong
Copy link
Collaborator

@byc4426
image

@zuohp
Copy link

zuohp commented Jul 2, 2018

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

@aldocano
Copy link

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();

@793383996
Copy link

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

@flyzend
Copy link

flyzend commented Aug 20, 2019

@byc4426
image

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants