[FIX] OutOfMemory при скачивании с certificatePinning

This commit is contained in:
Gravita 2021-02-08 17:58:24 +07:00
parent 3ccb0c5c8a
commit 7154989827

View file

@ -31,6 +31,7 @@ public class AsyncDownloader {
public final Callback callback; public final Callback callback;
@LauncherInject("launcher.certificatePinning") @LauncherInject("launcher.certificatePinning")
private static boolean isCertificatePinning; private static boolean isCertificatePinning;
private static volatile SSLSocketFactory sslSocketFactory;
public AsyncDownloader(Callback callback) { public AsyncDownloader(Callback callback) {
this.callback = callback; this.callback = callback;
@ -71,9 +72,11 @@ public void downloadFile(URL url, Path target) throws IOException {
} }
public SSLSocketFactory makeSSLSocketFactory() throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, KeyManagementException { public SSLSocketFactory makeSSLSocketFactory() throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, KeyManagementException {
if(sslSocketFactory != null) return sslSocketFactory;
SSLContext sslContext = SSLContext.getInstance("TLS"); SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, CertificatePinningTrustManager.getTrustManager().getTrustManagers(), new SecureRandom()); sslContext.init(null, CertificatePinningTrustManager.getTrustManager().getTrustManagers(), new SecureRandom());
return sslContext.getSocketFactory(); sslSocketFactory = sslContext.getSocketFactory();
return sslSocketFactory;
} }
public void downloadListInOneThread(List<SizedFile> files, String baseURL, Path targetDir) throws URISyntaxException, IOException { public void downloadListInOneThread(List<SizedFile> files, String baseURL, Path targetDir) throws URISyntaxException, IOException {