CrackMe.apk
Download file
package okhttp3;
import java.security.Principal;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import javax.net.ssl.SSLPeerUnverifiedException;
import kotlin.Deprecated;
import kotlin.Metadata;
import kotlin.ReplaceWith;
import kotlin.collections.ArraysKt;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.JvmStatic;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.TypeIntrinsics;
import kotlin.text.StringsKt;
import okhttp3.internal.HostnamesKt;
import okhttp3.internal.tls.CertificateChainCleaner;
import okio.ByteString;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000T\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\"\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0011\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0006\u0018\u0000 \"2\u00020\u0001:\u0003!\"#B!\b\u0000\u0012\f\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003\u0012\n\b\u0002\u0010\u0005\u001a\u0004\u0018\u00010\u0006¢\u0006\u0002\u0010\u0007J)\u0010\f\u001a\u00020\r2\u0006\u0010\u000e\u001a\u00020\u000f2\u0012\u0010\u0010\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00130\u00120\u0011H\u0000¢\u0006\u0002\b\u0014J)\u0010\f\u001a\u00020\r2\u0006\u0010\u000e\u001a\u00020\u000f2\u0012\u0010\u0015\u001a\n\u0012\u0006\b\u0001\u0012\u00020\u00170\u0016\"\u00020\u0017H\u0007¢\u0006\u0002\u0010\u0018J\u001c\u0010\f\u001a\u00020\r2\u0006\u0010\u000e\u001a\u00020\u000f2\f\u0010\u0015\u001a\b\u0012\u0004\u0012\u00020\u00170\u0012J\u0013\u0010\u0019\u001a\u00020\u001a2\b\u0010\u001b\u001a\u0004\u0018\u00010\u0001H\u0002J\u0014\u0010\u001c\u001a\b\u0012\u0004\u0012\u00020\u00040\u00122\u0006\u0010\u000e\u001a\u00020\u000fJ\b\u0010\u001d\u001a\u00020\u001eH\u0016J\u0015\u0010\u001f\u001a\u00020\u00002\u0006\u0010\u0005\u001a\u00020\u0006H\u0000¢\u0006\u0002\b R\u0016\u0010\u0005\u001a\u0004\u0018\u00010\u0006X\u0004¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\tR\u0017\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\b\n\u0000\u001a\u0004\b\n\u0010\u000b¨\u0006$"}, d2 = {"Lokhttp3/CertificatePinner;", "", "pins", "", "Lokhttp3/CertificatePinner$Pin;", "certificateChainCleaner", "Lokhttp3/internal/tls/CertificateChainCleaner;", "(Ljava/util/Set;Lokhttp3/internal/tls/CertificateChainCleaner;)V", "getCertificateChainCleaner$okhttp", "()Lokhttp3/internal/tls/CertificateChainCleaner;", "getPins", "()Ljava/util/Set;", "check", "", "hostname", "", "cleanedPeerCertificatesFn", "Lkotlin/Function0;", "", "Ljava/security/cert/X509Certificate;", "check$okhttp", "peerCertificates", "", "Ljava/security/cert/Certificate;", "(Ljava/lang/String;[Ljava/security/cert/Certificate;)V", "equals", "", "other", "findMatchingPins", "hashCode", "", "withCertificateChainCleaner", "withCertificateChainCleaner$okhttp", "Builder", "Companion", "Pin", "okhttp"}, k = 1, mv = {1, 4, 0})
/* compiled from: CertificatePinner.kt */
public final class CertificatePinner {
public static final Companion Companion = new Companion((DefaultConstructorMarker) null);
public static final CertificatePinner DEFAULT = new Builder().build();
private final CertificateChainCleaner certificateChainCleaner;
private final Set<Pin> pins;
@JvmStatic
public static final String pin(Certificate certificate) {
return Companion.pin(certificate);
}
@JvmStatic
public static final ByteString sha1Hash(X509Certificate x509Certificate) {
return Companion.sha1Hash(x509Certificate);
}
@JvmStatic
public static final ByteString sha256Hash(X509Certificate x509Certificate) {
return Companion.sha256Hash(x509Certificate);
}
public CertificatePinner(Set<Pin> set, CertificateChainCleaner certificateChainCleaner2) {
Intrinsics.checkNotNullParameter(set, "pins");
this.pins = set;
this.certificateChainCleaner = certificateChainCleaner2;
}
public final Set<Pin> getPins() {
return this.pins;
}
/* JADX WARNING: Illegal instructions before constructor call */
/* Code decompiled incorrectly, please refer to instructions dump. */
public /* synthetic */ CertificatePinner(java.util.Set r1, okhttp3.internal.tls.CertificateChainCleaner r2, int r3, kotlin.jvm.internal.DefaultConstructorMarker r4) {
/*
r0 = this;
r3 = r3 & 2
if (r3 == 0) goto L_0x0008
r2 = 0
r3 = r2
okhttp3.internal.tls.CertificateChainCleaner r3 = (okhttp3.internal.tls.CertificateChainCleaner) r3
L_0x0008:
r0.<init>(r1, r2)
return
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.CertificatePinner.<init>(java.util.Set, okhttp3.internal.tls.CertificateChainCleaner, int, kotlin.jvm.internal.DefaultConstructorMarker):void");
}
public final CertificateChainCleaner getCertificateChainCleaner$okhttp() {
return this.certificateChainCleaner;
}
public final void check(String str, List<? extends Certificate> list) throws SSLPeerUnverifiedException {
Intrinsics.checkNotNullParameter(str, "hostname");
Intrinsics.checkNotNullParameter(list, "peerCertificates");
check$okhttp(str, new CertificatePinner$check$1(this, list, str));
}
public final void check$okhttp(String str, Function0<? extends List<? extends X509Certificate>> function0) {
Pin next;
Intrinsics.checkNotNullParameter(str, "hostname");
Intrinsics.checkNotNullParameter(function0, "cleanedPeerCertificatesFn");
List<Pin> findMatchingPins = findMatchingPins(str);
if (!findMatchingPins.isEmpty()) {
List<X509Certificate> list = (List) function0.invoke();
loop0:
for (X509Certificate x509Certificate : list) {
ByteString byteString = null;
ByteString byteString2 = null;
Iterator<Pin> it = findMatchingPins.iterator();
ByteString byteString3 = null;
while (true) {
if (it.hasNext()) {
next = it.next();
String hashAlgorithm = next.getHashAlgorithm();
int hashCode = hashAlgorithm.hashCode();
if (hashCode == -903629273) {
if (!hashAlgorithm.equals("sha256")) {
break loop0;
}
if (byteString == null) {
byteString = Companion.sha256Hash(x509Certificate);
}
if (Intrinsics.areEqual((Object) next.getHash(), (Object) byteString)) {
return;
}
} else if (hashCode != 3528965 || !hashAlgorithm.equals("sha1")) {
break loop0;
} else {
if (byteString3 == null) {
byteString3 = Companion.sha1Hash(x509Certificate);
}
if (Intrinsics.areEqual((Object) next.getHash(), (Object) byteString3)) {
return;
}
}
}
}
throw new AssertionError("unsupported hashAlgorithm: " + next.getHashAlgorithm());
}
StringBuilder sb = new StringBuilder();
sb.append("Certificate pinning failure!");
sb.append("\n Peer certificate chain:");
for (X509Certificate x509Certificate2 : list) {
sb.append("\n ");
sb.append(Companion.pin(x509Certificate2));
sb.append(": ");
Principal subjectDN = x509Certificate2.getSubjectDN();
Intrinsics.checkNotNullExpressionValue(subjectDN, "element.subjectDN");
sb.append(subjectDN.getName());
}
sb.append("\n Pinned certificates for ");
sb.append(str);
sb.append(":");
for (Pin append : findMatchingPins) {
sb.append("\n ");
sb.append(append);
}
String sb2 = sb.toString();
Intrinsics.checkNotNullExpressionValue(sb2, "StringBuilder().apply(builderAction).toString()");
throw new SSLPeerUnverifiedException(sb2);
}
}
@Deprecated(message = "replaced with {@link #check(String, List)}.", replaceWith = @ReplaceWith(expression = "check(hostname, peerCertificates.toList())", imports = {}))
public final void check(String str, Certificate... certificateArr) throws SSLPeerUnverifiedException {
Intrinsics.checkNotNullParameter(str, "hostname");
Intrinsics.checkNotNullParameter(certificateArr, "peerCertificates");
check(str, (List<? extends Certificate>) ArraysKt.toList((T[]) certificateArr));
}
public final List<Pin> findMatchingPins(String str) {
Intrinsics.checkNotNullParameter(str, "hostname");
List<Pin> emptyList = CollectionsKt.emptyList();
for (Object next : this.pins) {
if (((Pin) next).matchesHostname(str)) {
if (emptyList.isEmpty()) {
emptyList = new ArrayList<>();
}
Objects.requireNonNull(emptyList, "null cannot be cast to non-null type kotlin.collections.MutableList<T>");
TypeIntrinsics.asMutableList(emptyList).add(next);
}
}
return emptyList;
}
public final CertificatePinner withCertificateChainCleaner$okhttp(CertificateChainCleaner certificateChainCleaner2) {
Intrinsics.checkNotNullParameter(certificateChainCleaner2, "certificateChainCleaner");
if (Intrinsics.areEqual((Object) this.certificateChainCleaner, (Object) certificateChainCleaner2)) {
return this;
}
return new CertificatePinner(this.pins, certificateChainCleaner2);
}
public boolean equals(Object obj) {
if (obj instanceof CertificatePinner) {
CertificatePinner certificatePinner = (CertificatePinner) obj;
return Intrinsics.areEqual((Object) certificatePinner.pins, (Object) this.pins) && Intrinsics.areEqual((Object) certificatePinner.certificateChainCleaner, (Object) this.certificateChainCleaner);
}
}
public int hashCode() {
int hashCode = (1517 + this.pins.hashCode()) * 41;
CertificateChainCleaner certificateChainCleaner2 = this.certificateChainCleaner;
return hashCode + (certificateChainCleaner2 != null ? certificateChainCleaner2.hashCode() : 0);
}
@Metadata(bv = {1, 0, 3}, d1 = {"\u00002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0003¢\u0006\u0002\u0010\u0005J\u0013\u0010\u000e\u001a\u00020\u000f2\b\u0010\u0010\u001a\u0004\u0018\u00010\u0001H\u0002J\b\u0010\u0011\u001a\u00020\u0012H\u0016J\u000e\u0010\u0013\u001a\u00020\u000f2\u0006\u0010\u0014\u001a\u00020\u0015J\u000e\u0010\u0016\u001a\u00020\u000f2\u0006\u0010\u0017\u001a\u00020\u0003J\b\u0010\u0018\u001a\u00020\u0003H\u0016R\u0011\u0010\u0006\u001a\u00020\u0007¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\tR\u0011\u0010\n\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\r\u0010\f¨\u0006\u0019"}, d2 = {"Lokhttp3/CertificatePinner$Pin;", "", "pattern", "", "pin", "(Ljava/lang/String;Ljava/lang/String;)V", "hash", "Lokio/ByteString;", "getHash", "()Lokio/ByteString;", "hashAlgorithm", "getHashAlgorithm", "()Ljava/lang/String;", "getPattern", "equals", "", "other", "hashCode", "", "matchesCertificate", "certificate", "Ljava/security/cert/X509Certificate;", "matchesHostname", "hostname", "toString", "okhttp"}, k = 1, mv = {1, 4, 0})
/* compiled from: CertificatePinner.kt */
public static final class Pin {
private final ByteString hash;
private final String hashAlgorithm;
private final String pattern;
public Pin(String str, String str2) {
Intrinsics.checkNotNullParameter(str, "pattern");
Intrinsics.checkNotNullParameter(str2, "pin");
if ((StringsKt.startsWith$default(str, "*.", false, 2, (Object) null) && StringsKt.indexOf$default((CharSequence) str, "*", 1, false, 4, (Object) null) == -1) || (StringsKt.startsWith$default(str, "**.", false, 2, (Object) null) && StringsKt.indexOf$default((CharSequence) str, "*", 2, false, 4, (Object) null) == -1) || StringsKt.indexOf$default((CharSequence) str, "*", 0, false, 6, (Object) null) == -1) {
String canonicalHost = HostnamesKt.toCanonicalHost(str);
if (canonicalHost != null) {
this.pattern = canonicalHost;
if (StringsKt.startsWith$default(str2, "sha1/", false, 2, (Object) null)) {
this.hashAlgorithm = "sha1";
ByteString.Companion companion = ByteString.Companion;
String substring = str2.substring(5);
Intrinsics.checkNotNullExpressionValue(substring, "(this as java.lang.String).substring(startIndex)");
ByteString decodeBase64 = companion.decodeBase64(substring);
if (decodeBase64 != null) {
this.hash = decodeBase64;
return;
}
throw new IllegalArgumentException("Invalid pin hash: " + str2);
} else if (StringsKt.startsWith$default(str2, "sha256/", false, 2, (Object) null)) {
this.hashAlgorithm = "sha256";
ByteString.Companion companion2 = ByteString.Companion;
String substring2 = str2.substring(7);
Intrinsics.checkNotNullExpressionValue(substring2, "(this as java.lang.String).substring(startIndex)");
ByteString decodeBase642 = companion2.decodeBase64(substring2);
if (decodeBase642 != null) {
this.hash = decodeBase642;
return;
}
throw new IllegalArgumentException("Invalid pin hash: " + str2);
} else {
throw new IllegalArgumentException("pins must start with 'sha256/' or 'sha1/': " + str2);
}
} else {
throw new IllegalArgumentException("Invalid pattern: " + str);
}
} else {
throw new IllegalArgumentException(("Unexpected pattern: " + str).toString());
}
}
public final String getPattern() {
return this.pattern;
}
public final String getHashAlgorithm() {
return this.hashAlgorithm;
}
public final ByteString getHash() {
return this.hash;
}
public final boolean matchesHostname(String str) {
Intrinsics.checkNotNullParameter(str, "hostname");
if (StringsKt.startsWith$default(this.pattern, "**.", false, 2, (Object) null)) {
int length = this.pattern.length() - 3;
int length2 = str.length() - length;
if (!StringsKt.regionMatches$default(str, str.length() - length, this.pattern, 3, length, false, 16, (Object) null)) {
return false;
}
if (length2 == 0 || str.charAt(length2 - 1) == '.') {
return true;
}
return false;
} else if (!StringsKt.startsWith$default(this.pattern, "*.", false, 2, (Object) null)) {
return Intrinsics.areEqual((Object) str, (Object) this.pattern);
} else {
int length3 = this.pattern.length() - 1;
int length4 = str.length() - length3;
if (!StringsKt.regionMatches$default(str, str.length() - length3, this.pattern, 1, length3, false, 16, (Object) null) || StringsKt.lastIndexOf$default((CharSequence) str, (char) FilenameUtils.EXTENSION_SEPARATOR, length4 - 1, false, 4, (Object) null) != -1) {
return false;
}
}
return true;
}
public final boolean matchesCertificate(X509Certificate x509Certificate) {
Intrinsics.checkNotNullParameter(x509Certificate, "certificate");
String str = this.hashAlgorithm;
int hashCode = str.hashCode();
if (hashCode != -903629273) {
if (hashCode == 3528965 && str.equals("sha1")) {
return Intrinsics.areEqual((Object) this.hash, (Object) CertificatePinner.Companion.sha1Hash(x509Certificate));
}
} else if (str.equals("sha256")) {
return Intrinsics.areEqual((Object) this.hash, (Object) CertificatePinner.Companion.sha256Hash(x509Certificate));
}
return false;
}
public String toString() {
return this.hashAlgorithm + IOUtils.DIR_SEPARATOR_UNIX + this.hash.base64();
}
public boolean equals(Object obj) {
Pin pin = this;
if (this == obj) {
return true;
}
if (!(obj instanceof Pin)) {
return false;
}
Pin pin2 = (Pin) obj;
if (!(!Intrinsics.areEqual((Object) this.pattern, (Object) pin2.pattern)) && !(!Intrinsics.areEqual((Object) this.hashAlgorithm, (Object) pin2.hashAlgorithm)) && !(!Intrinsics.areEqual((Object) this.hash, (Object) pin2.hash))) {
return true;
}
return false;
}
public int hashCode() {
return (((this.pattern.hashCode() * 31) + this.hashAlgorithm.hashCode()) * 31) + this.hash.hashCode();
}
}
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010!\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u000e\n\u0002\u0010\u0011\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J'\u0010\b\u001a\u00020\u00002\u0006\u0010\t\u001a\u00020\n2\u0012\u0010\u0003\u001a\n\u0012\u0006\b\u0001\u0012\u00020\n0\u000b\"\u00020\n¢\u0006\u0002\u0010\fJ\u0006\u0010\r\u001a\u00020\u000eR\u0017\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00050\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0006\u0010\u0007¨\u0006\u000f"}, d2 = {"Lokhttp3/CertificatePinner$Builder;", "", "()V", "pins", "", "Lokhttp3/CertificatePinner$Pin;", "getPins", "()Ljava/util/List;", "add", "pattern", "", "", "(Ljava/lang/String;[Ljava/lang/String;)Lokhttp3/CertificatePinner$Builder;", "build", "Lokhttp3/CertificatePinner;", "okhttp"}, k = 1, mv = {1, 4, 0})
/* compiled from: CertificatePinner.kt */
public static final class Builder {
private final List<Pin> pins = new ArrayList();
public final List<Pin> getPins() {
return this.pins;
}
public final Builder add(String str, String... strArr) {
Intrinsics.checkNotNullParameter(str, "pattern");
Intrinsics.checkNotNullParameter(strArr, "pins");
Builder builder = this;
for (String pin : strArr) {
this.pins.add(new Pin(str, pin));
}
return this;
}
public final CertificatePinner build() {
return new CertificatePinner(CollectionsKt.toSet(this.pins), (CertificateChainCleaner) null, 2, (DefaultConstructorMarker) null);
}
}
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\bH\u0007J\f\u0010\t\u001a\u00020\n*\u00020\u000bH\u0007J\f\u0010\f\u001a\u00020\n*\u00020\u000bH\u0007R\u0010\u0010\u0003\u001a\u00020\u00048\u0006X\u0004¢\u0006\u0002\n\u0000¨\u0006\r"}, d2 = {"Lokhttp3/CertificatePinner$Companion;", "", "()V", "DEFAULT", "Lokhttp3/CertificatePinner;", "pin", "", "certificate", "Ljava/security/cert/Certificate;", "sha1Hash", "Lokio/ByteString;", "Ljava/security/cert/X509Certificate;", "sha256Hash", "okhttp"}, k = 1, mv = {1, 4, 0})
/* compiled from: CertificatePinner.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
@JvmStatic
public final ByteString sha1Hash(X509Certificate x509Certificate) {
Intrinsics.checkNotNullParameter(x509Certificate, "$this$sha1Hash");
ByteString.Companion companion = ByteString.Companion;
PublicKey publicKey = x509Certificate.getPublicKey();
Intrinsics.checkNotNullExpressionValue(publicKey, "publicKey");
byte[] encoded = publicKey.getEncoded();
Intrinsics.checkNotNullExpressionValue(encoded, "publicKey.encoded");
return ByteString.Companion.of$default(companion, encoded, 0, 0, 3, (Object) null).sha1();
}
@JvmStatic
public final ByteString sha256Hash(X509Certificate x509Certificate) {
Intrinsics.checkNotNullParameter(x509Certificate, "$this$sha256Hash");
ByteString.Companion companion = ByteString.Companion;
PublicKey publicKey = x509Certificate.getPublicKey();
Intrinsics.checkNotNullExpressionValue(publicKey, "publicKey");
byte[] encoded = publicKey.getEncoded();
Intrinsics.checkNotNullExpressionValue(encoded, "publicKey.encoded");
return ByteString.Companion.of$default(companion, encoded, 0, 0, 3, (Object) null).sha256();
}
@JvmStatic
public final String pin(Certificate certificate) {
Intrinsics.checkNotNullParameter(certificate, "certificate");
if (certificate instanceof X509Certificate) {
StringBuilder sb = new StringBuilder();
sb.append("sha256/");
Companion companion = this;
sb.append(sha256Hash((X509Certificate) certificate).base64());
return sb.toString();
}
throw new IllegalArgumentException("Certificate pinning requires X509 certificates".toString());
}
}
}
Download file