BasicCertificateChainCleaner.smali 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. .class public final Lokhttp3/internal/tls/BasicCertificateChainCleaner;
  2. .super Lokhttp3/internal/tls/CertificateChainCleaner;
  3. .source ""
  4. # static fields
  5. .field private static final MAX_SIGNERS:I = 0x9
  6. # instance fields
  7. .field private final trustRootIndex:Lokhttp3/internal/tls/TrustRootIndex;
  8. # direct methods
  9. .method public constructor <init>(Lokhttp3/internal/tls/TrustRootIndex;)V
  10. .locals 0
  11. invoke-direct {p0}, Lokhttp3/internal/tls/CertificateChainCleaner;-><init>()V
  12. iput-object p1, p0, Lokhttp3/internal/tls/BasicCertificateChainCleaner;->trustRootIndex:Lokhttp3/internal/tls/TrustRootIndex;
  13. return-void
  14. .end method
  15. .method private verifySignature(Ljava/security/cert/X509Certificate;Ljava/security/cert/X509Certificate;)Z
  16. .locals 2
  17. invoke-virtual {p1}, Ljava/security/cert/X509Certificate;->getIssuerDN()Ljava/security/Principal;
  18. move-result-object v0
  19. invoke-virtual {p2}, Ljava/security/cert/X509Certificate;->getSubjectDN()Ljava/security/Principal;
  20. move-result-object v1
  21. invoke-interface {v0, v1}, Ljava/security/Principal;->equals(Ljava/lang/Object;)Z
  22. move-result v0
  23. const/4 v1, 0x0
  24. if-nez v0, :cond_0
  25. return v1
  26. :cond_0
  27. :try_start_0
  28. invoke-virtual {p2}, Ljava/security/cert/X509Certificate;->getPublicKey()Ljava/security/PublicKey;
  29. move-result-object p2
  30. invoke-virtual {p1, p2}, Ljava/security/cert/X509Certificate;->verify(Ljava/security/PublicKey;)V
  31. :try_end_0
  32. .catch Ljava/security/GeneralSecurityException; {:try_start_0 .. :try_end_0} :catch_0
  33. const/4 p1, 0x1
  34. return p1
  35. :catch_0
  36. return v1
  37. .end method
  38. # virtual methods
  39. .method public clean(Ljava/util/List;Ljava/lang/String;)Ljava/util/List;
  40. .locals 6
  41. .annotation system Ldalvik/annotation/Signature;
  42. value = {
  43. "(",
  44. "Ljava/util/List<",
  45. "Ljava/security/cert/Certificate;",
  46. ">;",
  47. "Ljava/lang/String;",
  48. ")",
  49. "Ljava/util/List<",
  50. "Ljava/security/cert/Certificate;",
  51. ">;"
  52. }
  53. .end annotation
  54. .annotation system Ldalvik/annotation/Throws;
  55. value = {
  56. Ljavax/net/ssl/SSLPeerUnverifiedException;
  57. }
  58. .end annotation
  59. new-instance p2, Ljava/util/ArrayDeque;
  60. invoke-direct {p2, p1}, Ljava/util/ArrayDeque;-><init>(Ljava/util/Collection;)V
  61. new-instance p1, Ljava/util/ArrayList;
  62. invoke-direct {p1}, Ljava/util/ArrayList;-><init>()V
  63. invoke-interface {p2}, Ljava/util/Deque;->removeFirst()Ljava/lang/Object;
  64. move-result-object v0
  65. invoke-interface {p1, v0}, Ljava/util/List;->add(Ljava/lang/Object;)Z
  66. const/4 v0, 0x0
  67. const/4 v1, 0x0
  68. :goto_0
  69. const/16 v2, 0x9
  70. if-ge v0, v2, :cond_7
  71. invoke-interface {p1}, Ljava/util/List;->size()I
  72. move-result v2
  73. const/4 v3, 0x1
  74. sub-int/2addr v2, v3
  75. invoke-interface {p1, v2}, Ljava/util/List;->get(I)Ljava/lang/Object;
  76. move-result-object v2
  77. check-cast v2, Ljava/security/cert/X509Certificate;
  78. iget-object v4, p0, Lokhttp3/internal/tls/BasicCertificateChainCleaner;->trustRootIndex:Lokhttp3/internal/tls/TrustRootIndex;
  79. invoke-interface {v4, v2}, Lokhttp3/internal/tls/TrustRootIndex;->findByIssuerAndSignature(Ljava/security/cert/X509Certificate;)Ljava/security/cert/X509Certificate;
  80. move-result-object v4
  81. if-eqz v4, :cond_3
  82. invoke-interface {p1}, Ljava/util/List;->size()I
  83. move-result v1
  84. if-gt v1, v3, :cond_0
  85. invoke-virtual {v2, v4}, Ljava/security/cert/X509Certificate;->equals(Ljava/lang/Object;)Z
  86. move-result v1
  87. if-nez v1, :cond_1
  88. :cond_0
  89. invoke-interface {p1, v4}, Ljava/util/List;->add(Ljava/lang/Object;)Z
  90. :cond_1
  91. invoke-direct {p0, v4, v4}, Lokhttp3/internal/tls/BasicCertificateChainCleaner;->verifySignature(Ljava/security/cert/X509Certificate;Ljava/security/cert/X509Certificate;)Z
  92. move-result v1
  93. if-eqz v1, :cond_2
  94. return-object p1
  95. :cond_2
  96. const/4 v1, 0x1
  97. goto :goto_1
  98. :cond_3
  99. invoke-interface {p2}, Ljava/util/Deque;->iterator()Ljava/util/Iterator;
  100. move-result-object v3
  101. :cond_4
  102. invoke-interface {v3}, Ljava/util/Iterator;->hasNext()Z
  103. move-result v4
  104. if-eqz v4, :cond_5
  105. invoke-interface {v3}, Ljava/util/Iterator;->next()Ljava/lang/Object;
  106. move-result-object v4
  107. check-cast v4, Ljava/security/cert/X509Certificate;
  108. invoke-direct {p0, v2, v4}, Lokhttp3/internal/tls/BasicCertificateChainCleaner;->verifySignature(Ljava/security/cert/X509Certificate;Ljava/security/cert/X509Certificate;)Z
  109. move-result v5
  110. if-eqz v5, :cond_4
  111. invoke-interface {v3}, Ljava/util/Iterator;->remove()V
  112. invoke-interface {p1, v4}, Ljava/util/List;->add(Ljava/lang/Object;)Z
  113. :goto_1
  114. add-int/lit8 v0, v0, 0x1
  115. goto :goto_0
  116. :cond_5
  117. if-eqz v1, :cond_6
  118. return-object p1
  119. :cond_6
  120. new-instance p1, Ljavax/net/ssl/SSLPeerUnverifiedException;
  121. new-instance p2, Ljava/lang/StringBuilder;
  122. invoke-direct {p2}, Ljava/lang/StringBuilder;-><init>()V
  123. const-string v0, "Failed to find a trusted cert that signed "
  124. invoke-virtual {p2, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  125. invoke-virtual {p2, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
  126. invoke-virtual {p2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  127. move-result-object p2
  128. invoke-direct {p1, p2}, Ljavax/net/ssl/SSLPeerUnverifiedException;-><init>(Ljava/lang/String;)V
  129. throw p1
  130. :cond_7
  131. new-instance p2, Ljavax/net/ssl/SSLPeerUnverifiedException;
  132. new-instance v0, Ljava/lang/StringBuilder;
  133. invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
  134. const-string v1, "Certificate chain too long: "
  135. invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  136. invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
  137. invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  138. move-result-object p1
  139. invoke-direct {p2, p1}, Ljavax/net/ssl/SSLPeerUnverifiedException;-><init>(Ljava/lang/String;)V
  140. goto :goto_3
  141. :goto_2
  142. throw p2
  143. :goto_3
  144. goto :goto_2
  145. .end method
  146. .method public equals(Ljava/lang/Object;)Z
  147. .locals 2
  148. const/4 v0, 0x1
  149. if-ne p1, p0, :cond_0
  150. return v0
  151. :cond_0
  152. instance-of v1, p1, Lokhttp3/internal/tls/BasicCertificateChainCleaner;
  153. if-eqz v1, :cond_1
  154. check-cast p1, Lokhttp3/internal/tls/BasicCertificateChainCleaner;
  155. iget-object p1, p1, Lokhttp3/internal/tls/BasicCertificateChainCleaner;->trustRootIndex:Lokhttp3/internal/tls/TrustRootIndex;
  156. iget-object v1, p0, Lokhttp3/internal/tls/BasicCertificateChainCleaner;->trustRootIndex:Lokhttp3/internal/tls/TrustRootIndex;
  157. invoke-virtual {p1, v1}, Ljava/lang/Object;->equals(Ljava/lang/Object;)Z
  158. move-result p1
  159. if-eqz p1, :cond_1
  160. goto :goto_0
  161. :cond_1
  162. const/4 v0, 0x0
  163. :goto_0
  164. return v0
  165. .end method
  166. .method public hashCode()I
  167. .locals 1
  168. iget-object v0, p0, Lokhttp3/internal/tls/BasicCertificateChainCleaner;->trustRootIndex:Lokhttp3/internal/tls/TrustRootIndex;
  169. invoke-virtual {v0}, Ljava/lang/Object;->hashCode()I
  170. move-result v0
  171. return v0
  172. .end method