[FIX] Оптимизация certificatePinning

This commit is contained in:
Gravita 2021-02-08 14:42:07 +07:00
parent bca195ca96
commit 3ccb0c5c8a

View file

@ -21,6 +21,7 @@ public final class CertificatePinningTrustManager {
@LauncherInject("launchercore.certificates") @LauncherInject("launchercore.certificates")
private static List<byte[]> secureConfigCertificates; private static List<byte[]> secureConfigCertificates;
private static X509Certificate[] certs = null; private static X509Certificate[] certs = null;
private volatile static TrustManagerFactory INSTANCE;
private static X509Certificate[] getInternalCertificates() { private static X509Certificate[] getInternalCertificates() {
CertificateFactory certFactory = null; CertificateFactory certFactory = null;
try { try {
@ -45,6 +46,7 @@ public static X509Certificate[] getCertificates() {
} }
public static TrustManagerFactory getTrustManager() throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException { public static TrustManagerFactory getTrustManager() throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException {
if(INSTANCE != null) return INSTANCE;
if(certs == null) certs = getInternalCertificates(); if(certs == null) certs = getInternalCertificates();
TrustManagerFactory factory = TrustManagerFactory.getInstance("X.509"); TrustManagerFactory factory = TrustManagerFactory.getInstance("X.509");
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
@ -57,6 +59,7 @@ public static TrustManagerFactory getTrustManager() throws KeyStoreException, No
i++; i++;
} }
factory.init(keystore); factory.init(keystore);
INSTANCE = factory;
return factory; return factory;
} }
} }