Skip to content

Commit

Permalink
proxy cache support ssl error
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Mar 23, 2020
1 parent 2c82da1 commit 171254f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gsyVideoPlayer-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ dependencies {
api viewDependencies.ijkplayer_java
api viewDependencies.ijkplayer_exo
api viewDependencies.transitionseverywhere
//api project(':gsyVideoPlayer-proxy_cache')
api project(':gsyVideoPlayer-proxy_cache')
//api project(':gsyVideoPlayer-base')
api "com.shuyu:gsyVideoPlayer-base:$gsyVideoVersion"
api "com.shuyu:gsyvideoplayer-androidvideocache:$gsyVideoVersion"
//api "com.shuyu:gsyvideoplayer-androidvideocache:$gsyVideoVersion"

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@
import java.io.InterruptedIOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Map;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import static com.danikula.videocache.Preconditions.checkNotNull;
import static com.danikula.videocache.ProxyCacheUtils.DEFAULT_BUFFER_SIZE;
import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
Expand Down Expand Up @@ -152,7 +163,55 @@ private HttpURLConnection openConnection(long offset, int timeout) throws IOExce
int redirectCount = 0;
String url = this.sourceInfo.url;
do {
connection = (HttpURLConnection) new URL(url).openConnection();
if (url.startsWith("https")) {
/**去除证书限制**/
connection = (HttpURLConnection) new URL(url).openConnection();
((HttpsURLConnection) connection).setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}

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

@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
((HttpsURLConnection) connection).setSSLSocketFactory(sslSocketFactory);
((HttpsURLConnection) connection).setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
/**去除证书限制**/
} else {
connection = (HttpURLConnection) new URL(url).openConnection();
}
injectCustomHeaders(connection, url);
if (offset > 0) {
connection.setRequestProperty("Range", "bytes=" + offset + "-");
Expand Down
4 changes: 2 additions & 2 deletions gsyVideoPlayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

//api project(':gsyVideoPlayer-java')
api project(':gsyVideoPlayer-java')
//api project(':gsyVideoPlayer-exo_player2')
//api project(':gsyVideoPlayer-armv5')
//api project(':gsyVideoPlayer-armv7a')
Expand All @@ -48,7 +48,7 @@ dependencies {

//api "com.shuyu:GSYVideoPlayer:$gsyVideoVersion"

api "com.shuyu:gsyVideoPlayer-java:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-java:$gsyVideoVersion"
api "com.shuyu:GSYVideoPlayer-exo2:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-armv7a:$gsyVideoVersion"
Expand Down

0 comments on commit 171254f

Please sign in to comment.