97 lines
3.9 KiB
Java
97 lines
3.9 KiB
Java
|
package com.discord.utilities.ssl;
|
||
|
|
||
|
import android.content.res.AssetManager;
|
||
|
import d0.y.b;
|
||
|
import d0.z.d.m;
|
||
|
import java.io.InputStream;
|
||
|
import java.security.KeyManagementException;
|
||
|
import java.security.KeyStore;
|
||
|
import java.security.NoSuchAlgorithmException;
|
||
|
import java.security.cert.Certificate;
|
||
|
import java.security.cert.CertificateFactory;
|
||
|
import java.security.cert.X509Certificate;
|
||
|
import javax.net.ssl.SSLContext;
|
||
|
import javax.net.ssl.SSLSocketFactory;
|
||
|
import javax.net.ssl.TrustManager;
|
||
|
import javax.net.ssl.TrustManagerFactory;
|
||
|
/* compiled from: SecureSocketsLayerUtils.kt */
|
||
|
public final class SecureSocketsLayerUtils {
|
||
|
public static final SecureSocketsLayerUtils INSTANCE = new SecureSocketsLayerUtils();
|
||
|
|
||
|
private SecureSocketsLayerUtils() {
|
||
|
}
|
||
|
|
||
|
public static final SSLSocketFactory createSocketFactory() {
|
||
|
return createSocketFactory$default(null, 1, null);
|
||
|
}
|
||
|
|
||
|
public static final SSLSocketFactory createSocketFactory(TrustManagerFactory trustManagerFactory) {
|
||
|
TrustManager[] trustManagerArr;
|
||
|
SSLContext context$default = getContext$default(INSTANCE, null, 1, null);
|
||
|
if (trustManagerFactory != null) {
|
||
|
try {
|
||
|
trustManagerArr = trustManagerFactory.getTrustManagers();
|
||
|
} catch (KeyManagementException e) {
|
||
|
throw e;
|
||
|
}
|
||
|
} else {
|
||
|
trustManagerArr = null;
|
||
|
}
|
||
|
context$default.init(null, trustManagerArr, null);
|
||
|
SSLSocketFactory socketFactory = context$default.getSocketFactory();
|
||
|
m.checkNotNullExpressionValue(socketFactory, "sslContext.socketFactory");
|
||
|
return socketFactory;
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ SSLSocketFactory createSocketFactory$default(TrustManagerFactory trustManagerFactory, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
trustManagerFactory = null;
|
||
|
}
|
||
|
return createSocketFactory(trustManagerFactory);
|
||
|
}
|
||
|
|
||
|
private final SSLContext getContext(String str) {
|
||
|
try {
|
||
|
SSLContext instance = SSLContext.getInstance(str);
|
||
|
m.checkNotNullExpressionValue(instance, "SSLContext.getInstance(protocol)");
|
||
|
return instance;
|
||
|
} catch (NoSuchAlgorithmException e) {
|
||
|
throw e;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ SSLContext getContext$default(SecureSocketsLayerUtils secureSocketsLayerUtils, String str, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
str = "TLS";
|
||
|
}
|
||
|
return secureSocketsLayerUtils.getContext(str);
|
||
|
}
|
||
|
|
||
|
/* JADX WARNING: Code restructure failed: missing block: B:12:0x004d, code lost:
|
||
|
r0 = move-exception;
|
||
|
*/
|
||
|
/* JADX WARNING: Code restructure failed: missing block: B:13:0x004e, code lost:
|
||
|
d0.y.b.closeFinally(r4, r5);
|
||
|
*/
|
||
|
/* JADX WARNING: Code restructure failed: missing block: B:14:0x0051, code lost:
|
||
|
throw r0;
|
||
|
*/
|
||
|
public static final TrustManagerFactory getTrustManagerFactory(AssetManager assetManager, String str) {
|
||
|
m.checkNotNullParameter(assetManager, "assetManager");
|
||
|
m.checkNotNullParameter(str, "certificatePath");
|
||
|
TrustManagerFactory instance = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||
|
InputStream open = assetManager.open(str);
|
||
|
Certificate generateCertificate = CertificateFactory.getInstance("X.509").generateCertificate(open);
|
||
|
if (generateCertificate != null) {
|
||
|
KeyStore instance2 = KeyStore.getInstance(KeyStore.getDefaultType());
|
||
|
instance2.load(null);
|
||
|
instance2.setCertificateEntry("caCert", (X509Certificate) generateCertificate);
|
||
|
instance.init(instance2);
|
||
|
m.checkNotNullExpressionValue(instance, "tmf");
|
||
|
b.closeFinally(open, null);
|
||
|
return instance;
|
||
|
}
|
||
|
throw new NullPointerException("null cannot be cast to non-null type java.security.cert.X509Certificate");
|
||
|
}
|
||
|
}
|