导航菜单

页面标题

页面副标题

Clash Legends v0.0.1 - JuspayTrustManager.java 源代码

正在查看: Clash Legends v0.0.1 应用的 JuspayTrustManager.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package in.juspay.godel.util;

import android.content.Context;
import android.net.http.SslCertificate;
import android.webkit.WebView;
import com.payu.custombrowser.util.b;
import in.juspay.godel.analytics.GodelTracker;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.KeyStore;
import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import naming.InvalidNameException;
import naming.ldap.LdapName;
import naming.ldap.Rdn;
import org.apache.http.conn.util.InetAddressUtils;

public class JuspayTrustManager {
    private TrustManagerFactory a = null;

    public void a(WebView webView) {
        try {
            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            this.a = trustManagerFactory;
            trustManagerFactory.init((KeyStore) null);
        } catch (Exception e) {
            JuspayLogger.b("JuspayTrustManager", "error while initializing trustmanager", e);
        }
    }

    private List<TrustManager> a() {
        ArrayList arrayList = new ArrayList(this.a.getTrustManagers().length);
        Collections.addAll(arrayList, this.a.getTrustManagers());
        return arrayList;
    }

    private String[] a(Context context, String str) {
        try {
            return context.getAssets().list(str);
        } catch (IOException e) {
            JuspayLogger.b("JuspayTrustManager", "caught while trying to open assets for trustmanager", e);
            return new String[0];
        }
    }

    private java.security.cert.X509Certificate[] b(android.webkit.WebView r17) {
        throw new UnsupportedOperationException("Method not decompiled: in.juspay.godel.util.JuspayTrustManager.b(android.webkit.WebView):java.security.cert.X509Certificate[]");
    }

    private X509Certificate a(TrustManager[] trustManagerArr, X509Certificate x509Certificate) {
        X509Certificate a;
        for (TrustManager trustManager : trustManagerArr) {
            if ((trustManager instanceof X509TrustManager) && (a = a(((X509TrustManager) trustManager).getAcceptedIssuers(), x509Certificate)) != null) {
                return a;
            }
        }
        return null;
    }

    private X509Certificate a(X509Certificate[] x509CertificateArr, X509Certificate x509Certificate) {
        if (x509CertificateArr != null && x509CertificateArr.length > 0) {
            for (X509Certificate x509Certificate2 : x509CertificateArr) {
                try {
                    x509Certificate.verify(x509Certificate2.getPublicKey());
                    return x509Certificate2;
                } catch (Exception e) {
                    JuspayLogger.b("JuspayTrustManager", "" + e.getLocalizedMessage());
                }
            }
        }
        JuspayLogger.b("JuspayTrustManager", "Nothing Found for " + x509Certificate.getSubjectDN());
        return null;
    }

    public boolean a(WebView webView, SslCertificate sslCertificate, String str) {
        X509Certificate a;
        boolean z = false;
        try {
            Field declaredField = sslCertificate.getClass().getDeclaredField("mX509Certificate");
            declaredField.setAccessible(true);
            X509Certificate x509Certificate = (X509Certificate) declaredField.get(sslCertificate);
            X509Certificate[] b = b(webView);
            ArrayList arrayList = new ArrayList();
            try {
                x509Certificate.checkValidity();
                try {
                    a(str, x509Certificate);
                    arrayList.add(x509Certificate);
                    do {
                        a = a(b, (X509Certificate) arrayList.get(arrayList.size() - 1));
                        if (a != null && !b(a)) {
                            arrayList.add(a);
                        }
                        if (a == null) {
                            break;
                        }
                    } while (!b(a));
                    X509Certificate a2 = a(this.a.getTrustManagers(), (X509Certificate) arrayList.get(arrayList.size() - 1));
                    if (a2 != null) {
                        arrayList.add(a2);
                    }
                    Iterator<TrustManager> it = a().iterator();
                    boolean z2 = false;
                    while (true) {
                        if (!it.hasNext()) {
                            z = z2;
                            break;
                        }
                        TrustManager next = it.next();
                        if (next instanceof X509TrustManager) {
                            try {
                                ((X509TrustManager) next).checkServerTrusted((X509Certificate[]) arrayList.toArray(new X509Certificate[arrayList.size()]), "generic");
                                try {
                                    JuspayLogger.b("JuspayTrustManager", "found a match here!");
                                    z = true;
                                    break;
                                } catch (Exception e) {
                                    z2 = true;
                                    JuspayLogger.b("JuspayTrustManager", ((X509Certificate) arrayList.get(0)).getSubjectDN() + " is not verified yet.");
                                }
                            } catch (Exception e2) {
                            }
                        }
                    }
                } catch (Exception e3) {
                    GodelTracker.getInstance().a("trust_manager_error", "invalid_host");
                    JuspayLogger.b("JuspayTrustManager", "certificate_host_not_valid " + e3, e3);
                    return false;
                }
            } catch (Exception e4) {
                GodelTracker.getInstance().a("trust_manager_error", "invalid_date");
                JuspayLogger.b("JuspayTrustManager", "certificate_date_not_valid ", e4);
                return false;
            }
        } catch (Exception e5) {
            JuspayLogger.b("JuspayTrustManager", "Certificate casting error: " + e5);
        }
        return z;
    }

    private boolean b(X509Certificate x509Certificate) {
        try {
            x509Certificate.verify(x509Certificate.getPublicKey());
            JuspayLogger.b("JuspayTrustManager", "Self Signed!" + x509Certificate.getSubjectDN());
            return true;
        } catch (Exception e) {
            JuspayLogger.b("JuspayTrustManager", "Exception while checking self sign" + e);
            return false;
        }
    }

    public String a(X509Certificate x509Certificate) {
        try {
            String str = null;
            for (Rdn rdn : new LdapName(x509Certificate.getSubjectX500Principal().getName()).a()) {
                if ("CN".equalsIgnoreCase(rdn.c())) {
                    str = rdn.b().toString();
                }
            }
            return str;
        } catch (InvalidNameException e) {
            return null;
        }
    }

    public void a(String str, X509Certificate x509Certificate) throws URISyntaxException, CertificateParsingException, SSLPeerUnverifiedException {
        String a;
        String host = new URI(str).getHost();
        Collection<List<?>> subjectAlternativeNames = x509Certificate.getSubjectAlternativeNames();
        if (a(host) || InetAddressUtils.isIPv6Address(host)) {
            throw new SSLPeerUnverifiedException("IP address are not allowed: Please check https://tools.ietf.org/html/rfc6066 " + str);
        }
        boolean z = false;
        for (List<?> list : subjectAlternativeNames) {
            if (list.size() == 2 && ((Integer) list.get(0)).intValue() == 2) {
                z = true;
                if (b(host, (String) list.get(1))) {
                    return;
                }
            }
        }
        if (z || (a = a(x509Certificate)) == null || !a(host, a)) {
            throw new SSLPeerUnverifiedException("No host name in the certificate did not match the requested host name: " + str);
        }
    }

    private boolean a(String str) {
        String[] split = str.split("\\.");
        if (split.length != 4) {
            return false;
        }
        for (String str2 : split) {
            try {
                int parseInt = Integer.parseInt(str2);
                if (parseInt < 0 || parseInt > 255) {
                    return false;
                }
            } catch (NumberFormatException e) {
                return false;
            }
        }
        return true;
    }

    private boolean a(String str, String str2) {
        return str.equalsIgnoreCase(str2);
    }

    private boolean b(String str, String str2) {
        if (str.equalsIgnoreCase(str2)) {
            return true;
        }
        String[] split = str2.split("\\.");
        String[] split2 = str.split("\\.");
        if (split.length != split2.length) {
            return false;
        }
        for (int i = 0; i < split.length; i++) {
            if (!Pattern.compile(split[i].replace(b.DEFAULT_PAYMENT_URLS, ".*")).matcher(split2[i]).matches()) {
                return false;
            }
        }
        return true;
    }
}