HttpsUtils.smali

.class public Lcom/zhy/http/okhttp/https/HttpsUtils;
.super Ljava/lang/Object;
.source "HttpsUtils.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/zhy/http/okhttp/https/HttpsUtils$MyTrustManager;,
        Lcom/zhy/http/okhttp/https/HttpsUtils$UnSafeTrustManager;,
        Lcom/zhy/http/okhttp/https/HttpsUtils$UnSafeHostnameVerifier;,
        Lcom/zhy/http/okhttp/https/HttpsUtils$SSLParams;
    }
.end annotation


# direct methods
.method static constructor <clinit>()V
    .registers 1

    return-void
.end method

.method public constructor <init>()V
    .registers 1

    .line 27
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 193
    return-void
.end method

.method static synthetic access$100([Ljavax/net/ssl/TrustManager;)Ljavax/net/ssl/X509TrustManager;
    .registers 2
    .param p0, "x0"    # [Ljavax/net/ssl/TrustManager;

    .line 27
    invoke-static {p0}, Lcom/zhy/http/okhttp/https/HttpsUtils;->chooseTrustManager([Ljavax/net/ssl/TrustManager;)Ljavax/net/ssl/X509TrustManager;

    move-result-object v0

    return-object v0
.end method

.method private static chooseTrustManager([Ljavax/net/ssl/TrustManager;)Ljavax/net/ssl/X509TrustManager;
    .registers 6
    .param p0, "trustManagers"    # [Ljavax/net/ssl/TrustManager;

    .line 182
    move-object v0, p0

    .local v0, "arr$":[Ljavax/net/ssl/TrustManager;
    array-length v1, v0

    .local v1, "len$":I
    const/4 v2, 0x0

    .local v2, "i$":I
    :goto_3
    if-ge v2, v1, :cond_12

    aget-object v3, v0, v2

    .line 184
    .local v3, "trustManager":Ljavax/net/ssl/TrustManager;
    instance-of v4, v3, Ljavax/net/ssl/X509TrustManager;

    if-eqz v4, :cond_f

    .line 186
    move-object v4, v3

    check-cast v4, Ljavax/net/ssl/X509TrustManager;

    return-object v4

    .line 182
    .end local v3    # "trustManager":Ljavax/net/ssl/TrustManager;
    :cond_f
    add-int/lit8 v2, v2, 0x1

    goto :goto_3

    .line 189
    .end local v0    # "arr$":[Ljavax/net/ssl/TrustManager;
    .end local v1    # "len$":I
    .end local v2    # "i$":I
    :cond_12
    const/4 v0, 0x0

    return-object v0
.end method

.method public static getSslSocketFactory([Ljava/io/InputStream;Ljava/io/InputStream;Ljava/lang/String;)Lcom/zhy/http/okhttp/https/HttpsUtils$SSLParams;
    .registers 11
    .param p0, "certificates"    # [Ljava/io/InputStream;
    .param p1, "bksFile"    # Ljava/io/InputStream;
    .param p2, "password"    # Ljava/lang/String;

    .line 37
    new-instance v0, Lcom/zhy/http/okhttp/https/HttpsUtils$SSLParams;

    invoke-direct {v0}, Lcom/zhy/http/okhttp/https/HttpsUtils$SSLParams;-><init>()V

    .line 40
    .local v0, "sslParams":Lcom/zhy/http/okhttp/https/HttpsUtils$SSLParams;
    :try_start_5
    invoke-static {p0}, Lcom/zhy/http/okhttp/https/HttpsUtils;->prepareTrustManager([Ljava/io/InputStream;)[Ljavax/net/ssl/TrustManager;

    move-result-object v1

    .line 41
    .local v1, "trustManagers":[Ljavax/net/ssl/TrustManager;
    invoke-static {p1, p2}, Lcom/zhy/http/okhttp/https/HttpsUtils;->prepareKeyManager(Ljava/io/InputStream;Ljava/lang/String;)[Ljavax/net/ssl/KeyManager;

    move-result-object v2

    .line 42
    .local v2, "keyManagers":[Ljavax/net/ssl/KeyManager;
    const-string v3, "TLS"

    invoke-static {v3}, Ljavax/net/ssl/SSLContext;->getInstance(Ljava/lang/String;)Ljavax/net/ssl/SSLContext;

    move-result-object v3

    .line 43
    .local v3, "sslContext":Ljavax/net/ssl/SSLContext;
    const/4 v4, 0x0

    .line 44
    .local v4, "trustManager":Ljavax/net/ssl/X509TrustManager;
    const/4 v5, 0x0

    if-eqz v1, :cond_22

    .line 46
    new-instance v6, Lcom/zhy/http/okhttp/https/HttpsUtils$MyTrustManager;

    invoke-static {v1}, Lcom/zhy/http/okhttp/https/HttpsUtils;->chooseTrustManager([Ljavax/net/ssl/TrustManager;)Ljavax/net/ssl/X509TrustManager;

    move-result-object v7

    invoke-direct {v6, v7}, Lcom/zhy/http/okhttp/https/HttpsUtils$MyTrustManager;-><init>(Ljavax/net/ssl/X509TrustManager;)V

    move-object v4, v6

    goto :goto_28

    .line 49
    :cond_22
    new-instance v6, Lcom/zhy/http/okhttp/https/HttpsUtils$UnSafeTrustManager;

    invoke-direct {v6, v5}, Lcom/zhy/http/okhttp/https/HttpsUtils$UnSafeTrustManager;-><init>(Lcom/zhy/http/okhttp/https/HttpsUtils$1;)V

    move-object v4, v6

    .line 51
    :goto_28
    const/4 v6, 0x1

    new-array v6, v6, [Ljavax/net/ssl/TrustManager;

    const/4 v7, 0x0

    aput-object v4, v6, v7

    invoke-virtual {v3, v2, v6, v5}, Ljavax/net/ssl/SSLContext;->init([Ljavax/net/ssl/KeyManager;[Ljavax/net/ssl/TrustManager;Ljava/security/SecureRandom;)V

    .line 52
    invoke-virtual {v3}, Ljavax/net/ssl/SSLContext;->getSocketFactory()Ljavax/net/ssl/SSLSocketFactory;

    move-result-object v5

    iput-object v5, v0, Lcom/zhy/http/okhttp/https/HttpsUtils$SSLParams;->sSLSocketFactory:Ljavax/net/ssl/SSLSocketFactory;

    .line 53
    iput-object v4, v0, Lcom/zhy/http/okhttp/https/HttpsUtils$SSLParams;->trustManager:Ljavax/net/ssl/X509TrustManager;
    :try_end_39
    .catch Ljava/security/NoSuchAlgorithmException; {:try_start_5 .. :try_end_39} :catch_48
    .catch Ljava/security/KeyManagementException; {:try_start_5 .. :try_end_39} :catch_41
    .catch Ljava/security/KeyStoreException; {:try_start_5 .. :try_end_39} :catch_3a

    .line 54
    return-object v0

    .line 61
    .end local v1    # "trustManagers":[Ljavax/net/ssl/TrustManager;
    .end local v2    # "keyManagers":[Ljavax/net/ssl/KeyManager;
    .end local v3    # "sslContext":Ljavax/net/ssl/SSLContext;
    .end local v4    # "trustManager":Ljavax/net/ssl/X509TrustManager;
    :catch_3a
    move-exception v1

    .line 63
    .local v1, "e":Ljava/security/KeyStoreException;
    new-instance v2, Ljava/lang/AssertionError;

    invoke-direct {v2, v1}, Ljava/lang/AssertionError;-><init>(Ljava/lang/Object;)V

    throw v2

    .line 58
    .end local v1    # "e":Ljava/security/KeyStoreException;
    :catch_41
    move-exception v1

    .line 60
    .local v1, "e":Ljava/security/KeyManagementException;
    new-instance v2, Ljava/lang/AssertionError;

    invoke-direct {v2, v1}, Ljava/lang/AssertionError;-><init>(Ljava/lang/Object;)V

    throw v2

    .line 55
    .end local v1    # "e":Ljava/security/KeyManagementException;
    :catch_48
    move-exception v1

    .line 57
    .local v1, "e":Ljava/security/NoSuchAlgorithmException;
    new-instance v2, Ljava/lang/AssertionError;

    invoke-direct {v2, v1}, Ljava/lang/AssertionError;-><init>(Ljava/lang/Object;)V

    throw v2
.end method

.method private static prepareKeyManager(Ljava/io/InputStream;Ljava/lang/String;)[Ljavax/net/ssl/KeyManager;
    .registers 6
    .param p0, "bksFile"    # Ljava/io/InputStream;
    .param p1, "password"    # Ljava/lang/String;

    .line 150
    const/4 v0, 0x0

    if-eqz p0, :cond_46

    if-nez p1, :cond_6

    goto :goto_46

    .line 152
    :cond_6
    :try_start_6
    const-string v1, "BKS"

    invoke-static {v1}, Ljava/security/KeyStore;->getInstance(Ljava/lang/String;)Ljava/security/KeyStore;

    move-result-object v1

    .line 153
    .local v1, "clientKeyStore":Ljava/security/KeyStore;
    invoke-virtual {p1}, Ljava/lang/String;->toCharArray()[C

    move-result-object v2

    invoke-virtual {v1, p0, v2}, Ljava/security/KeyStore;->load(Ljava/io/InputStream;[C)V

    .line 154
    invoke-static {}, Ljavax/net/ssl/KeyManagerFactory;->getDefaultAlgorithm()Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Ljavax/net/ssl/KeyManagerFactory;->getInstance(Ljava/lang/String;)Ljavax/net/ssl/KeyManagerFactory;

    move-result-object v2

    .line 155
    .local v2, "keyManagerFactory":Ljavax/net/ssl/KeyManagerFactory;
    invoke-virtual {p1}, Ljava/lang/String;->toCharArray()[C

    move-result-object v3

    invoke-virtual {v2, v1, v3}, Ljavax/net/ssl/KeyManagerFactory;->init(Ljava/security/KeyStore;[C)V

    .line 156
    invoke-virtual {v2}, Ljavax/net/ssl/KeyManagerFactory;->getKeyManagers()[Ljavax/net/ssl/KeyManager;

    move-result-object v0
    :try_end_26
    .catch Ljava/security/KeyStoreException; {:try_start_6 .. :try_end_26} :catch_40
    .catch Ljava/security/NoSuchAlgorithmException; {:try_start_6 .. :try_end_26} :catch_3b
    .catch Ljava/security/UnrecoverableKeyException; {:try_start_6 .. :try_end_26} :catch_36
    .catch Ljava/security/cert/CertificateException; {:try_start_6 .. :try_end_26} :catch_31
    .catch Ljava/io/IOException; {:try_start_6 .. :try_end_26} :catch_2c
    .catch Ljava/lang/Exception; {:try_start_6 .. :try_end_26} :catch_27

    return-object v0

    .line 173
    .end local v1    # "clientKeyStore":Ljava/security/KeyStore;
    .end local v2    # "keyManagerFactory":Ljavax/net/ssl/KeyManagerFactory;
    :catch_27
    move-exception v1

    .line 175
    .local v1, "e":Ljava/lang/Exception;
    invoke-virtual {v1}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_45

    .line 170
    .end local v1    # "e":Ljava/lang/Exception;
    :catch_2c
    move-exception v1

    .line 172
    .local v1, "e":Ljava/io/IOException;
    invoke-virtual {v1}, Ljava/io/IOException;->printStackTrace()V

    .end local v1    # "e":Ljava/io/IOException;
    goto :goto_44

    .line 167
    :catch_31
    move-exception v1

    .line 169
    .local v1, "e":Ljava/security/cert/CertificateException;
    invoke-virtual {v1}, Ljava/security/cert/CertificateException;->printStackTrace()V

    .end local v1    # "e":Ljava/security/cert/CertificateException;
    goto :goto_44

    .line 164
    :catch_36
    move-exception v1

    .line 166
    .local v1, "e":Ljava/security/UnrecoverableKeyException;
    invoke-virtual {v1}, Ljava/security/UnrecoverableKeyException;->printStackTrace()V

    .end local v1    # "e":Ljava/security/UnrecoverableKeyException;
    goto :goto_44

    .line 161
    :catch_3b
    move-exception v1

    .line 163
    .local v1, "e":Ljava/security/NoSuchAlgorithmException;
    invoke-virtual {v1}, Ljava/security/NoSuchAlgorithmException;->printStackTrace()V

    .end local v1    # "e":Ljava/security/NoSuchAlgorithmException;
    goto :goto_44

    .line 158
    :catch_40
    move-exception v1

    .line 160
    .local v1, "e":Ljava/security/KeyStoreException;
    invoke-virtual {v1}, Ljava/security/KeyStoreException;->printStackTrace()V

    .line 176
    .end local v1    # "e":Ljava/security/KeyStoreException;
    :goto_44
    nop

    .line 177
    :goto_45
    return-object v0

    .line 150
    :cond_46
    :goto_46
    return-object v0
.end method

.method private static varargs prepareTrustManager([Ljava/io/InputStream;)[Ljavax/net/ssl/TrustManager;
    .registers 11
    .param p0, "certificates"    # [Ljava/io/InputStream;

    .line 99
    const/4 v0, 0x0

    if-eqz p0, :cond_61

    array-length v1, p0

    if-gtz v1, :cond_7

    goto :goto_61

    .line 103
    :cond_7
    :try_start_7
    const-string v1, "X.509"

    invoke-static {v1}, Ljava/security/cert/CertificateFactory;->getInstance(Ljava/lang/String;)Ljava/security/cert/CertificateFactory;

    move-result-object v1

    .line 104
    .local v1, "certificateFactory":Ljava/security/cert/CertificateFactory;
    invoke-static {}, Ljava/security/KeyStore;->getDefaultType()Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Ljava/security/KeyStore;->getInstance(Ljava/lang/String;)Ljava/security/KeyStore;

    move-result-object v2

    .line 105
    .local v2, "keyStore":Ljava/security/KeyStore;
    invoke-virtual {v2, v0}, Ljava/security/KeyStore;->load(Ljava/security/KeyStore$LoadStoreParameter;)V

    .line 106
    const/4 v3, 0x0

    .line 107
    .local v3, "index":I
    move-object v4, p0

    .local v4, "arr$":[Ljava/io/InputStream;
    array-length v5, v4

    .local v5, "len$":I
    const/4 v6, 0x0

    .local v6, "i$":I
    :goto_1c
    if-ge v6, v5, :cond_3a

    aget-object v7, v4, v6

    .line 109
    .local v7, "certificate":Ljava/io/InputStream;
    add-int/lit8 v8, v3, 0x1

    .end local v3    # "index":I
    .local v8, "index":I
    invoke-static {v3}, Ljava/lang/Integer;->toString(I)Ljava/lang/String;

    move-result-object v3

    .line 110
    .local v3, "certificateAlias":Ljava/lang/String;
    invoke-virtual {v1, v7}, Ljava/security/cert/CertificateFactory;->generateCertificate(Ljava/io/InputStream;)Ljava/security/cert/Certificate;

    move-result-object v9

    invoke-virtual {v2, v3, v9}, Ljava/security/KeyStore;->setCertificateEntry(Ljava/lang/String;Ljava/security/cert/Certificate;)V
    :try_end_2d
    .catch Ljava/security/NoSuchAlgorithmException; {:try_start_7 .. :try_end_2d} :catch_5b
    .catch Ljava/security/cert/CertificateException; {:try_start_7 .. :try_end_2d} :catch_56
    .catch Ljava/security/KeyStoreException; {:try_start_7 .. :try_end_2d} :catch_51
    .catch Ljava/lang/Exception; {:try_start_7 .. :try_end_2d} :catch_4c

    .line 113
    if-eqz v7, :cond_35

    .line 114
    :try_start_2f
    invoke-virtual {v7}, Ljava/io/InputStream;->close()V
    :try_end_32
    .catch Ljava/io/IOException; {:try_start_2f .. :try_end_32} :catch_33
    .catch Ljava/security/NoSuchAlgorithmException; {:try_start_2f .. :try_end_32} :catch_5b
    .catch Ljava/security/cert/CertificateException; {:try_start_2f .. :try_end_32} :catch_56
    .catch Ljava/security/KeyStoreException; {:try_start_2f .. :try_end_32} :catch_51
    .catch Ljava/lang/Exception; {:try_start_2f .. :try_end_32} :catch_4c

    goto :goto_35

    .line 115
    :catch_33
    move-exception v9

    goto :goto_36

    .line 118
    :cond_35
    :goto_35
    nop

    .line 107
    .end local v3    # "certificateAlias":Ljava/lang/String;
    .end local v7    # "certificate":Ljava/io/InputStream;
    :goto_36
    add-int/lit8 v6, v6, 0x1

    move v3, v8

    goto :goto_1c

    .line 120
    .end local v4    # "arr$":[Ljava/io/InputStream;
    .end local v5    # "len$":I
    .end local v6    # "i$":I
    .end local v8    # "index":I
    .local v3, "index":I
    :cond_3a
    const/4 v4, 0x0

    .line 122
    .local v4, "trustManagerFactory":Ljavax/net/ssl/TrustManagerFactory;
    :try_start_3b
    invoke-static {}, Ljavax/net/ssl/TrustManagerFactory;->getDefaultAlgorithm()Ljava/lang/String;

    move-result-object v5

    invoke-static {v5}, Ljavax/net/ssl/TrustManagerFactory;->getInstance(Ljava/lang/String;)Ljavax/net/ssl/TrustManagerFactory;

    move-result-object v5

    move-object v4, v5

    .line 124
    invoke-virtual {v4, v2}, Ljavax/net/ssl/TrustManagerFactory;->init(Ljava/security/KeyStore;)V

    .line 126
    invoke-virtual {v4}, Ljavax/net/ssl/TrustManagerFactory;->getTrustManagers()[Ljavax/net/ssl/TrustManager;

    move-result-object v0
    :try_end_4b
    .catch Ljava/security/NoSuchAlgorithmException; {:try_start_3b .. :try_end_4b} :catch_5b
    .catch Ljava/security/cert/CertificateException; {:try_start_3b .. :try_end_4b} :catch_56
    .catch Ljava/security/KeyStoreException; {:try_start_3b .. :try_end_4b} :catch_51
    .catch Ljava/lang/Exception; {:try_start_3b .. :try_end_4b} :catch_4c

    .line 128
    .local v0, "trustManagers":[Ljavax/net/ssl/TrustManager;
    return-object v0

    .line 138
    .end local v0    # "trustManagers":[Ljavax/net/ssl/TrustManager;
    .end local v1    # "certificateFactory":Ljava/security/cert/CertificateFactory;
    .end local v2    # "keyStore":Ljava/security/KeyStore;
    .end local v3    # "index":I
    .end local v4    # "trustManagerFactory":Ljavax/net/ssl/TrustManagerFactory;
    :catch_4c
    move-exception v1

    .line 140
    .local v1, "e":Ljava/lang/Exception;
    invoke-virtual {v1}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_60

    .line 135
    .end local v1    # "e":Ljava/lang/Exception;
    :catch_51
    move-exception v1

    .line 137
    .local v1, "e":Ljava/security/KeyStoreException;
    invoke-virtual {v1}, Ljava/security/KeyStoreException;->printStackTrace()V

    .end local v1    # "e":Ljava/security/KeyStoreException;
    goto :goto_5f

    .line 132
    :catch_56
    move-exception v1

    .line 134
    .local v1, "e":Ljava/security/cert/CertificateException;
    invoke-virtual {v1}, Ljava/security/cert/CertificateException;->printStackTrace()V

    .end local v1    # "e":Ljava/security/cert/CertificateException;
    goto :goto_5f

    .line 129
    :catch_5b
    move-exception v1

    .line 131
    .local v1, "e":Ljava/security/NoSuchAlgorithmException;
    invoke-virtual {v1}, Ljava/security/NoSuchAlgorithmException;->printStackTrace()V

    .line 141
    .end local v1    # "e":Ljava/security/NoSuchAlgorithmException;
    :goto_5f
    nop

    .line 142
    :goto_60
    return-object v0

    .line 99
    :cond_61
    :goto_61
    return-object v0
.end method