I am trying to connect to a server through https and Android does not recognize the certificate as "trusted", so I get the following exception:
javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:
Trust anchor for certification path not found.
To solve this problem, I have Included the certificate in the app (assets folder) and use it to validate the server certificate.
I do it with a class called CustomSSLSocketFactory where it is read the certificate and make the validation process during the https connection without problem.
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setSSLSocketFactory(CustomSSLSocketFactory.getSSLSocketFactory(context));
Now I have to repeat this process but using exoplayer2 to play the hlsvideo, and after several days investigating I do not achieve it.
private MediaSource buildMediaSourceHlsMedia(Uri uri) throws MalformedURLException {
String UserAgent = Util.getUserAgent(getContext (), getResources().getString(R.string.app_name));
int minLoadableRetryCount;
DefaultHttpDataSourceFactory dataSourceFactory =new DefaultHttpDataSourceFactory( UserAgent,BANDWIDTH_METER,DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,true);
dataSourceConHeader(dataSourceFactory,uri.toString(),mParam4);
MediaSource ms= new HlsMediaSource.Factory(dataSourceFactory).setMinLoadableRetryCount(5).createMediaSource(uri);
return ms;
}
I suppose that it is necessary to code a custom datasource but after several days, I can not achieve it. I do not know how to do it.
I suppose that I have to include in the custom datasource , (with the rest of necessary code) :
conn.setSSLSocketFactory(CustomSSLSocketFactory.getSSLSocketFactory(context));
Can someone guide me?. Thanks