639 lines
15 KiB
Smali
639 lines
15 KiB
Smali
.class public final Lokhttp3/internal/tls/OkHostnameVerifier;
|
|
.super Ljava/lang/Object;
|
|
.source "OkHostnameVerifier.java"
|
|
|
|
# interfaces
|
|
.implements Ljavax/net/ssl/HostnameVerifier;
|
|
|
|
|
|
# static fields
|
|
.field private static final ALT_DNS_NAME:I = 0x2
|
|
|
|
.field private static final ALT_IPA_NAME:I = 0x7
|
|
|
|
.field public static final INSTANCE:Lokhttp3/internal/tls/OkHostnameVerifier;
|
|
|
|
|
|
# direct methods
|
|
.method static constructor <clinit>()V
|
|
.locals 1
|
|
|
|
.prologue
|
|
new-instance v0, Lokhttp3/internal/tls/OkHostnameVerifier;
|
|
|
|
invoke-direct {v0}, Lokhttp3/internal/tls/OkHostnameVerifier;-><init>()V
|
|
|
|
sput-object v0, Lokhttp3/internal/tls/OkHostnameVerifier;->INSTANCE:Lokhttp3/internal/tls/OkHostnameVerifier;
|
|
|
|
return-void
|
|
.end method
|
|
|
|
.method private constructor <init>()V
|
|
.locals 0
|
|
|
|
.prologue
|
|
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
|
|
|
|
return-void
|
|
.end method
|
|
|
|
.method public static allSubjectAltNames(Ljava/security/cert/X509Certificate;)Ljava/util/List;
|
|
.locals 5
|
|
.param p0, "certificate" # Ljava/security/cert/X509Certificate;
|
|
.annotation system Ldalvik/annotation/Signature;
|
|
value = {
|
|
"(",
|
|
"Ljava/security/cert/X509Certificate;",
|
|
")",
|
|
"Ljava/util/List",
|
|
"<",
|
|
"Ljava/lang/String;",
|
|
">;"
|
|
}
|
|
.end annotation
|
|
|
|
.prologue
|
|
const/4 v3, 0x7
|
|
|
|
invoke-static {p0, v3}, Lokhttp3/internal/tls/OkHostnameVerifier;->getSubjectAltNames(Ljava/security/cert/X509Certificate;I)Ljava/util/List;
|
|
|
|
move-result-object v1
|
|
|
|
.local v1, "altIpaNames":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
|
|
const/4 v3, 0x2
|
|
|
|
invoke-static {p0, v3}, Lokhttp3/internal/tls/OkHostnameVerifier;->getSubjectAltNames(Ljava/security/cert/X509Certificate;I)Ljava/util/List;
|
|
|
|
move-result-object v0
|
|
|
|
.local v0, "altDnsNames":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
|
|
new-instance v2, Ljava/util/ArrayList;
|
|
|
|
invoke-interface {v1}, Ljava/util/List;->size()I
|
|
|
|
move-result v3
|
|
|
|
invoke-interface {v0}, Ljava/util/List;->size()I
|
|
|
|
move-result v4
|
|
|
|
add-int/2addr v3, v4
|
|
|
|
invoke-direct {v2, v3}, Ljava/util/ArrayList;-><init>(I)V
|
|
|
|
.local v2, "result":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
|
|
invoke-interface {v2, v1}, Ljava/util/List;->addAll(Ljava/util/Collection;)Z
|
|
|
|
invoke-interface {v2, v0}, Ljava/util/List;->addAll(Ljava/util/Collection;)Z
|
|
|
|
return-object v2
|
|
.end method
|
|
|
|
.method private static getSubjectAltNames(Ljava/security/cert/X509Certificate;I)Ljava/util/List;
|
|
.locals 11
|
|
.param p0, "certificate" # Ljava/security/cert/X509Certificate;
|
|
.param p1, "type" # I
|
|
.annotation system Ldalvik/annotation/Signature;
|
|
value = {
|
|
"(",
|
|
"Ljava/security/cert/X509Certificate;",
|
|
"I)",
|
|
"Ljava/util/List",
|
|
"<",
|
|
"Ljava/lang/String;",
|
|
">;"
|
|
}
|
|
.end annotation
|
|
|
|
.prologue
|
|
new-instance v5, Ljava/util/ArrayList;
|
|
|
|
invoke-direct {v5}, Ljava/util/ArrayList;-><init>()V
|
|
|
|
.local v5, "result":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
|
|
:try_start_0
|
|
invoke-virtual {p0}, Ljava/security/cert/X509Certificate;->getSubjectAlternativeNames()Ljava/util/Collection;
|
|
|
|
move-result-object v7
|
|
|
|
.local v7, "subjectAltNames":Ljava/util/Collection;, "Ljava/util/Collection<*>;"
|
|
if-nez v7, :cond_1
|
|
|
|
invoke-static {}, Ljava/util/Collections;->emptyList()Ljava/util/List;
|
|
|
|
move-result-object v5
|
|
|
|
.end local v5 # "result":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
|
|
.end local v7 # "subjectAltNames":Ljava/util/Collection;, "Ljava/util/Collection<*>;"
|
|
:cond_0
|
|
:goto_0
|
|
return-object v5
|
|
|
|
.restart local v5 # "result":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
|
|
.restart local v7 # "subjectAltNames":Ljava/util/Collection;, "Ljava/util/Collection<*>;"
|
|
:cond_1
|
|
invoke-interface {v7}, Ljava/util/Collection;->iterator()Ljava/util/Iterator;
|
|
|
|
move-result-object v8
|
|
|
|
:cond_2
|
|
:goto_1
|
|
invoke-interface {v8}, Ljava/util/Iterator;->hasNext()Z
|
|
|
|
move-result v9
|
|
|
|
if-eqz v9, :cond_0
|
|
|
|
invoke-interface {v8}, Ljava/util/Iterator;->next()Ljava/lang/Object;
|
|
|
|
move-result-object v6
|
|
|
|
.local v6, "subjectAltName":Ljava/lang/Object;
|
|
move-object v0, v6
|
|
|
|
check-cast v0, Ljava/util/List;
|
|
|
|
move-object v4, v0
|
|
|
|
.local v4, "entry":Ljava/util/List;, "Ljava/util/List<*>;"
|
|
if-eqz v4, :cond_2
|
|
|
|
invoke-interface {v4}, Ljava/util/List;->size()I
|
|
|
|
move-result v9
|
|
|
|
const/4 v10, 0x2
|
|
|
|
if-lt v9, v10, :cond_2
|
|
|
|
const/4 v9, 0x0
|
|
|
|
invoke-interface {v4, v9}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object v2
|
|
|
|
check-cast v2, Ljava/lang/Integer;
|
|
|
|
.local v2, "altNameType":Ljava/lang/Integer;
|
|
if-eqz v2, :cond_2
|
|
|
|
invoke-virtual {v2}, Ljava/lang/Integer;->intValue()I
|
|
|
|
move-result v9
|
|
|
|
if-ne v9, p1, :cond_2
|
|
|
|
const/4 v9, 0x1
|
|
|
|
invoke-interface {v4, v9}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object v1
|
|
|
|
check-cast v1, Ljava/lang/String;
|
|
|
|
.local v1, "altName":Ljava/lang/String;
|
|
if-eqz v1, :cond_2
|
|
|
|
invoke-interface {v5, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z
|
|
:try_end_0
|
|
.catch Ljava/security/cert/CertificateParsingException; {:try_start_0 .. :try_end_0} :catch_0
|
|
|
|
goto :goto_1
|
|
|
|
.end local v1 # "altName":Ljava/lang/String;
|
|
.end local v2 # "altNameType":Ljava/lang/Integer;
|
|
.end local v4 # "entry":Ljava/util/List;, "Ljava/util/List<*>;"
|
|
.end local v6 # "subjectAltName":Ljava/lang/Object;
|
|
.end local v7 # "subjectAltNames":Ljava/util/Collection;, "Ljava/util/Collection<*>;"
|
|
:catch_0
|
|
move-exception v3
|
|
|
|
.local v3, "e":Ljava/security/cert/CertificateParsingException;
|
|
invoke-static {}, Ljava/util/Collections;->emptyList()Ljava/util/List;
|
|
|
|
move-result-object v5
|
|
|
|
goto :goto_0
|
|
.end method
|
|
|
|
.method private verifyHostname(Ljava/lang/String;Ljava/lang/String;)Z
|
|
.locals 8
|
|
.param p1, "hostname" # Ljava/lang/String;
|
|
.param p2, "pattern" # Ljava/lang/String;
|
|
|
|
.prologue
|
|
const/4 v7, -0x1
|
|
|
|
const/16 v6, 0x2e
|
|
|
|
const/4 v3, 0x1
|
|
|
|
const/4 v2, 0x0
|
|
|
|
if-eqz p1, :cond_0
|
|
|
|
invoke-virtual {p1}, Ljava/lang/String;->length()I
|
|
|
|
move-result v4
|
|
|
|
if-eqz v4, :cond_0
|
|
|
|
const-string v4, "."
|
|
|
|
invoke-virtual {p1, v4}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z
|
|
|
|
move-result v4
|
|
|
|
if-nez v4, :cond_0
|
|
|
|
const-string v4, ".."
|
|
|
|
invoke-virtual {p1, v4}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
|
|
|
|
move-result v4
|
|
|
|
if-eqz v4, :cond_1
|
|
|
|
:cond_0
|
|
:goto_0
|
|
return v2
|
|
|
|
:cond_1
|
|
if-eqz p2, :cond_0
|
|
|
|
invoke-virtual {p2}, Ljava/lang/String;->length()I
|
|
|
|
move-result v4
|
|
|
|
if-eqz v4, :cond_0
|
|
|
|
const-string v4, "."
|
|
|
|
invoke-virtual {p2, v4}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z
|
|
|
|
move-result v4
|
|
|
|
if-nez v4, :cond_0
|
|
|
|
const-string v4, ".."
|
|
|
|
invoke-virtual {p2, v4}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
|
|
|
|
move-result v4
|
|
|
|
if-nez v4, :cond_0
|
|
|
|
const-string v4, "."
|
|
|
|
invoke-virtual {p1, v4}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
|
|
|
|
move-result v4
|
|
|
|
if-nez v4, :cond_2
|
|
|
|
new-instance v4, Ljava/lang/StringBuilder;
|
|
|
|
invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V
|
|
|
|
invoke-virtual {v4, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
|
|
|
|
move-result-object v4
|
|
|
|
invoke-virtual {v4, v6}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;
|
|
|
|
move-result-object v4
|
|
|
|
invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
|
|
|
|
move-result-object p1
|
|
|
|
:cond_2
|
|
const-string v4, "."
|
|
|
|
invoke-virtual {p2, v4}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
|
|
|
|
move-result v4
|
|
|
|
if-nez v4, :cond_3
|
|
|
|
new-instance v4, Ljava/lang/StringBuilder;
|
|
|
|
invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V
|
|
|
|
invoke-virtual {v4, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
|
|
|
|
move-result-object v4
|
|
|
|
invoke-virtual {v4, v6}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;
|
|
|
|
move-result-object v4
|
|
|
|
invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
|
|
|
|
move-result-object p2
|
|
|
|
:cond_3
|
|
sget-object v4, Ljava/util/Locale;->US:Ljava/util/Locale;
|
|
|
|
invoke-virtual {p2, v4}, Ljava/lang/String;->toLowerCase(Ljava/util/Locale;)Ljava/lang/String;
|
|
|
|
move-result-object p2
|
|
|
|
const-string v4, "*"
|
|
|
|
invoke-virtual {p2, v4}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z
|
|
|
|
move-result v4
|
|
|
|
if-nez v4, :cond_4
|
|
|
|
invoke-virtual {p1, p2}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
|
|
|
|
move-result v2
|
|
|
|
goto :goto_0
|
|
|
|
:cond_4
|
|
const-string v4, "*."
|
|
|
|
invoke-virtual {p2, v4}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z
|
|
|
|
move-result v4
|
|
|
|
if-eqz v4, :cond_0
|
|
|
|
const/16 v4, 0x2a
|
|
|
|
invoke-virtual {p2, v4, v3}, Ljava/lang/String;->indexOf(II)I
|
|
|
|
move-result v4
|
|
|
|
if-ne v4, v7, :cond_0
|
|
|
|
invoke-virtual {p1}, Ljava/lang/String;->length()I
|
|
|
|
move-result v4
|
|
|
|
invoke-virtual {p2}, Ljava/lang/String;->length()I
|
|
|
|
move-result v5
|
|
|
|
if-lt v4, v5, :cond_0
|
|
|
|
const-string v4, "*."
|
|
|
|
invoke-virtual {v4, p2}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
|
|
|
|
move-result v4
|
|
|
|
if-nez v4, :cond_0
|
|
|
|
invoke-virtual {p2, v3}, Ljava/lang/String;->substring(I)Ljava/lang/String;
|
|
|
|
move-result-object v0
|
|
|
|
.local v0, "suffix":Ljava/lang/String;
|
|
invoke-virtual {p1, v0}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
|
|
|
|
move-result v4
|
|
|
|
if-eqz v4, :cond_0
|
|
|
|
invoke-virtual {p1}, Ljava/lang/String;->length()I
|
|
|
|
move-result v4
|
|
|
|
invoke-virtual {v0}, Ljava/lang/String;->length()I
|
|
|
|
move-result v5
|
|
|
|
sub-int v1, v4, v5
|
|
|
|
.local v1, "suffixStartIndexInHostname":I
|
|
if-lez v1, :cond_5
|
|
|
|
add-int/lit8 v4, v1, -0x1
|
|
|
|
invoke-virtual {p1, v6, v4}, Ljava/lang/String;->lastIndexOf(II)I
|
|
|
|
move-result v4
|
|
|
|
if-ne v4, v7, :cond_0
|
|
|
|
:cond_5
|
|
move v2, v3
|
|
|
|
goto/16 :goto_0
|
|
.end method
|
|
|
|
.method private verifyHostname(Ljava/lang/String;Ljava/security/cert/X509Certificate;)Z
|
|
.locals 8
|
|
.param p1, "hostname" # Ljava/lang/String;
|
|
.param p2, "certificate" # Ljava/security/cert/X509Certificate;
|
|
|
|
.prologue
|
|
sget-object v6, Ljava/util/Locale;->US:Ljava/util/Locale;
|
|
|
|
invoke-virtual {p1, v6}, Ljava/lang/String;->toLowerCase(Ljava/util/Locale;)Ljava/lang/String;
|
|
|
|
move-result-object p1
|
|
|
|
const/4 v2, 0x0
|
|
|
|
.local v2, "hasDns":Z
|
|
const/4 v6, 0x2
|
|
|
|
invoke-static {p2, v6}, Lokhttp3/internal/tls/OkHostnameVerifier;->getSubjectAltNames(Ljava/security/cert/X509Certificate;I)Ljava/util/List;
|
|
|
|
move-result-object v0
|
|
|
|
.local v0, "altNames":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
|
|
const/4 v3, 0x0
|
|
|
|
.local v3, "i":I
|
|
invoke-interface {v0}, Ljava/util/List;->size()I
|
|
|
|
move-result v5
|
|
|
|
.local v5, "size":I
|
|
:goto_0
|
|
if-ge v3, v5, :cond_1
|
|
|
|
const/4 v2, 0x1
|
|
|
|
invoke-interface {v0, v3}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object v6
|
|
|
|
check-cast v6, Ljava/lang/String;
|
|
|
|
invoke-direct {p0, p1, v6}, Lokhttp3/internal/tls/OkHostnameVerifier;->verifyHostname(Ljava/lang/String;Ljava/lang/String;)Z
|
|
|
|
move-result v6
|
|
|
|
if-eqz v6, :cond_0
|
|
|
|
const/4 v6, 0x1
|
|
|
|
:goto_1
|
|
return v6
|
|
|
|
:cond_0
|
|
add-int/lit8 v3, v3, 0x1
|
|
|
|
goto :goto_0
|
|
|
|
:cond_1
|
|
if-nez v2, :cond_2
|
|
|
|
invoke-virtual {p2}, Ljava/security/cert/X509Certificate;->getSubjectX500Principal()Ljavax/security/auth/x500/X500Principal;
|
|
|
|
move-result-object v4
|
|
|
|
.local v4, "principal":Ljavax/security/auth/x500/X500Principal;
|
|
new-instance v6, Lokhttp3/internal/tls/DistinguishedNameParser;
|
|
|
|
invoke-direct {v6, v4}, Lokhttp3/internal/tls/DistinguishedNameParser;-><init>(Ljavax/security/auth/x500/X500Principal;)V
|
|
|
|
const-string v7, "cn"
|
|
|
|
invoke-virtual {v6, v7}, Lokhttp3/internal/tls/DistinguishedNameParser;->findMostSpecific(Ljava/lang/String;)Ljava/lang/String;
|
|
|
|
move-result-object v1
|
|
|
|
.local v1, "cn":Ljava/lang/String;
|
|
if-eqz v1, :cond_2
|
|
|
|
invoke-direct {p0, p1, v1}, Lokhttp3/internal/tls/OkHostnameVerifier;->verifyHostname(Ljava/lang/String;Ljava/lang/String;)Z
|
|
|
|
move-result v6
|
|
|
|
goto :goto_1
|
|
|
|
.end local v1 # "cn":Ljava/lang/String;
|
|
.end local v4 # "principal":Ljavax/security/auth/x500/X500Principal;
|
|
:cond_2
|
|
const/4 v6, 0x0
|
|
|
|
goto :goto_1
|
|
.end method
|
|
|
|
.method private verifyIpAddress(Ljava/lang/String;Ljava/security/cert/X509Certificate;)Z
|
|
.locals 4
|
|
.param p1, "ipAddress" # Ljava/lang/String;
|
|
.param p2, "certificate" # Ljava/security/cert/X509Certificate;
|
|
|
|
.prologue
|
|
const/4 v3, 0x7
|
|
|
|
invoke-static {p2, v3}, Lokhttp3/internal/tls/OkHostnameVerifier;->getSubjectAltNames(Ljava/security/cert/X509Certificate;I)Ljava/util/List;
|
|
|
|
move-result-object v0
|
|
|
|
.local v0, "altNames":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
|
|
const/4 v1, 0x0
|
|
|
|
.local v1, "i":I
|
|
invoke-interface {v0}, Ljava/util/List;->size()I
|
|
|
|
move-result v2
|
|
|
|
.local v2, "size":I
|
|
:goto_0
|
|
if-ge v1, v2, :cond_1
|
|
|
|
invoke-interface {v0, v1}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object v3
|
|
|
|
check-cast v3, Ljava/lang/String;
|
|
|
|
invoke-virtual {p1, v3}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z
|
|
|
|
move-result v3
|
|
|
|
if-eqz v3, :cond_0
|
|
|
|
const/4 v3, 0x1
|
|
|
|
:goto_1
|
|
return v3
|
|
|
|
:cond_0
|
|
add-int/lit8 v1, v1, 0x1
|
|
|
|
goto :goto_0
|
|
|
|
:cond_1
|
|
const/4 v3, 0x0
|
|
|
|
goto :goto_1
|
|
.end method
|
|
|
|
|
|
# virtual methods
|
|
.method public verify(Ljava/lang/String;Ljava/security/cert/X509Certificate;)Z
|
|
.locals 1
|
|
.param p1, "host" # Ljava/lang/String;
|
|
.param p2, "certificate" # Ljava/security/cert/X509Certificate;
|
|
|
|
.prologue
|
|
invoke-static {p1}, Lokhttp3/internal/Util;->verifyAsIpAddress(Ljava/lang/String;)Z
|
|
|
|
move-result v0
|
|
|
|
if-eqz v0, :cond_0
|
|
|
|
invoke-direct {p0, p1, p2}, Lokhttp3/internal/tls/OkHostnameVerifier;->verifyIpAddress(Ljava/lang/String;Ljava/security/cert/X509Certificate;)Z
|
|
|
|
move-result v0
|
|
|
|
:goto_0
|
|
return v0
|
|
|
|
:cond_0
|
|
invoke-direct {p0, p1, p2}, Lokhttp3/internal/tls/OkHostnameVerifier;->verifyHostname(Ljava/lang/String;Ljava/security/cert/X509Certificate;)Z
|
|
|
|
move-result v0
|
|
|
|
goto :goto_0
|
|
.end method
|
|
|
|
.method public verify(Ljava/lang/String;Ljavax/net/ssl/SSLSession;)Z
|
|
.locals 4
|
|
.param p1, "host" # Ljava/lang/String;
|
|
.param p2, "session" # Ljavax/net/ssl/SSLSession;
|
|
|
|
.prologue
|
|
const/4 v3, 0x0
|
|
|
|
:try_start_0
|
|
invoke-interface {p2}, Ljavax/net/ssl/SSLSession;->getPeerCertificates()[Ljava/security/cert/Certificate;
|
|
|
|
move-result-object v0
|
|
|
|
.local v0, "certificates":[Ljava/security/cert/Certificate;
|
|
const/4 v2, 0x0
|
|
|
|
aget-object v2, v0, v2
|
|
|
|
check-cast v2, Ljava/security/cert/X509Certificate;
|
|
|
|
invoke-virtual {p0, p1, v2}, Lokhttp3/internal/tls/OkHostnameVerifier;->verify(Ljava/lang/String;Ljava/security/cert/X509Certificate;)Z
|
|
:try_end_0
|
|
.catch Ljavax/net/ssl/SSLException; {:try_start_0 .. :try_end_0} :catch_0
|
|
|
|
move-result v2
|
|
|
|
.end local v0 # "certificates":[Ljava/security/cert/Certificate;
|
|
:goto_0
|
|
return v2
|
|
|
|
:catch_0
|
|
move-exception v1
|
|
|
|
.local v1, "e":Ljavax/net/ssl/SSLException;
|
|
move v2, v3
|
|
|
|
goto :goto_0
|
|
.end method
|