SslClient$Builder.smali 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. .class public Lokhttp3/internal/tls/SslClient$Builder;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # annotations
  5. .annotation system Ldalvik/annotation/EnclosingClass;
  6. value = Lokhttp3/internal/tls/SslClient;
  7. .end annotation
  8. .annotation system Ldalvik/annotation/InnerClass;
  9. accessFlags = 0x9
  10. name = "Builder"
  11. .end annotation
  12. # instance fields
  13. .field private final certificates:Ljava/util/List;
  14. .annotation system Ldalvik/annotation/Signature;
  15. value = {
  16. "Ljava/util/List<",
  17. "Ljava/security/cert/X509Certificate;",
  18. ">;"
  19. }
  20. .end annotation
  21. .end field
  22. .field private final chainCertificates:Ljava/util/List;
  23. .annotation system Ldalvik/annotation/Signature;
  24. value = {
  25. "Ljava/util/List<",
  26. "Ljava/security/cert/X509Certificate;",
  27. ">;"
  28. }
  29. .end annotation
  30. .end field
  31. .field private keyPair:Ljava/security/KeyPair;
  32. .field private keyStoreType:Ljava/lang/String;
  33. # direct methods
  34. .method public constructor <init>()V
  35. .locals 1
  36. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  37. new-instance v0, Ljava/util/ArrayList;
  38. invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V
  39. iput-object v0, p0, Lokhttp3/internal/tls/SslClient$Builder;->chainCertificates:Ljava/util/List;
  40. new-instance v0, Ljava/util/ArrayList;
  41. invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V
  42. iput-object v0, p0, Lokhttp3/internal/tls/SslClient$Builder;->certificates:Ljava/util/List;
  43. invoke-static {}, Ljava/security/KeyStore;->getDefaultType()Ljava/lang/String;
  44. move-result-object v0
  45. iput-object v0, p0, Lokhttp3/internal/tls/SslClient$Builder;->keyStoreType:Ljava/lang/String;
  46. return-void
  47. .end method
  48. .method private newEmptyKeyStore([C)Ljava/security/KeyStore;
  49. .locals 2
  50. .annotation system Ldalvik/annotation/Throws;
  51. value = {
  52. Ljava/security/GeneralSecurityException;
  53. }
  54. .end annotation
  55. :try_start_0
  56. iget-object v0, p0, Lokhttp3/internal/tls/SslClient$Builder;->keyStoreType:Ljava/lang/String;
  57. invoke-static {v0}, Ljava/security/KeyStore;->getInstance(Ljava/lang/String;)Ljava/security/KeyStore;
  58. move-result-object v0
  59. const/4 v1, 0x0
  60. invoke-virtual {v0, v1, p1}, Ljava/security/KeyStore;->load(Ljava/io/InputStream;[C)V
  61. :try_end_0
  62. .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
  63. return-object v0
  64. :catch_0
  65. move-exception p1
  66. new-instance v0, Ljava/lang/AssertionError;
  67. invoke-direct {v0, p1}, Ljava/lang/AssertionError;-><init>(Ljava/lang/Object;)V
  68. throw v0
  69. .end method
  70. # virtual methods
  71. .method public addTrustedCertificate(Ljava/security/cert/X509Certificate;)Lokhttp3/internal/tls/SslClient$Builder;
  72. .locals 1
  73. iget-object v0, p0, Lokhttp3/internal/tls/SslClient$Builder;->certificates:Ljava/util/List;
  74. invoke-interface {v0, p1}, Ljava/util/List;->add(Ljava/lang/Object;)Z
  75. return-object p0
  76. .end method
  77. .method public build()Lokhttp3/internal/tls/SslClient;
  78. .locals 6
  79. :try_start_0
  80. const-string v0, "password"
  81. invoke-virtual {v0}, Ljava/lang/String;->toCharArray()[C
  82. move-result-object v0
  83. invoke-direct {p0, v0}, Lokhttp3/internal/tls/SslClient$Builder;->newEmptyKeyStore([C)Ljava/security/KeyStore;
  84. move-result-object v1
  85. iget-object v2, p0, Lokhttp3/internal/tls/SslClient$Builder;->keyPair:Ljava/security/KeyPair;
  86. if-eqz v2, :cond_0
  87. iget-object v2, p0, Lokhttp3/internal/tls/SslClient$Builder;->chainCertificates:Ljava/util/List;
  88. iget-object v3, p0, Lokhttp3/internal/tls/SslClient$Builder;->chainCertificates:Ljava/util/List;
  89. invoke-interface {v3}, Ljava/util/List;->size()I
  90. move-result v3
  91. new-array v3, v3, [Ljava/security/cert/Certificate;
  92. invoke-interface {v2, v3}, Ljava/util/List;->toArray([Ljava/lang/Object;)[Ljava/lang/Object;
  93. move-result-object v2
  94. check-cast v2, [Ljava/security/cert/Certificate;
  95. const-string v3, "private"
  96. iget-object v4, p0, Lokhttp3/internal/tls/SslClient$Builder;->keyPair:Ljava/security/KeyPair;
  97. invoke-virtual {v4}, Ljava/security/KeyPair;->getPrivate()Ljava/security/PrivateKey;
  98. move-result-object v4
  99. invoke-virtual {v1, v3, v4, v0, v2}, Ljava/security/KeyStore;->setKeyEntry(Ljava/lang/String;Ljava/security/Key;[C[Ljava/security/cert/Certificate;)V
  100. :cond_0
  101. const/4 v2, 0x0
  102. const/4 v3, 0x0
  103. :goto_0
  104. iget-object v4, p0, Lokhttp3/internal/tls/SslClient$Builder;->certificates:Ljava/util/List;
  105. invoke-interface {v4}, Ljava/util/List;->size()I
  106. move-result v4
  107. if-ge v3, v4, :cond_1
  108. new-instance v4, Ljava/lang/StringBuilder;
  109. invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V
  110. const-string v5, "cert_"
  111. invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  112. invoke-virtual {v4, v3}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
  113. invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  114. move-result-object v4
  115. iget-object v5, p0, Lokhttp3/internal/tls/SslClient$Builder;->certificates:Ljava/util/List;
  116. invoke-interface {v5, v3}, Ljava/util/List;->get(I)Ljava/lang/Object;
  117. move-result-object v5
  118. check-cast v5, Ljava/security/cert/Certificate;
  119. invoke-virtual {v1, v4, v5}, Ljava/security/KeyStore;->setCertificateEntry(Ljava/lang/String;Ljava/security/cert/Certificate;)V
  120. add-int/lit8 v3, v3, 0x1
  121. goto :goto_0
  122. :cond_1
  123. invoke-static {}, Ljavax/net/ssl/KeyManagerFactory;->getDefaultAlgorithm()Ljava/lang/String;
  124. move-result-object v3
  125. invoke-static {v3}, Ljavax/net/ssl/KeyManagerFactory;->getInstance(Ljava/lang/String;)Ljavax/net/ssl/KeyManagerFactory;
  126. move-result-object v3
  127. invoke-virtual {v3, v1, v0}, Ljavax/net/ssl/KeyManagerFactory;->init(Ljava/security/KeyStore;[C)V
  128. invoke-static {}, Ljavax/net/ssl/TrustManagerFactory;->getDefaultAlgorithm()Ljava/lang/String;
  129. move-result-object v0
  130. invoke-static {v0}, Ljavax/net/ssl/TrustManagerFactory;->getInstance(Ljava/lang/String;)Ljavax/net/ssl/TrustManagerFactory;
  131. move-result-object v0
  132. invoke-virtual {v0, v1}, Ljavax/net/ssl/TrustManagerFactory;->init(Ljava/security/KeyStore;)V
  133. invoke-virtual {v0}, Ljavax/net/ssl/TrustManagerFactory;->getTrustManagers()[Ljavax/net/ssl/TrustManager;
  134. move-result-object v0
  135. array-length v1, v0
  136. const/4 v4, 0x1
  137. if-ne v1, v4, :cond_2
  138. aget-object v1, v0, v2
  139. instance-of v1, v1, Ljavax/net/ssl/X509TrustManager;
  140. if-eqz v1, :cond_2
  141. const-string v1, "TLS"
  142. invoke-static {v1}, Ljavax/net/ssl/SSLContext;->getInstance(Ljava/lang/String;)Ljavax/net/ssl/SSLContext;
  143. move-result-object v1
  144. invoke-virtual {v3}, Ljavax/net/ssl/KeyManagerFactory;->getKeyManagers()[Ljavax/net/ssl/KeyManager;
  145. move-result-object v3
  146. new-instance v4, Ljava/security/SecureRandom;
  147. invoke-direct {v4}, Ljava/security/SecureRandom;-><init>()V
  148. invoke-virtual {v1, v3, v0, v4}, Ljavax/net/ssl/SSLContext;->init([Ljavax/net/ssl/KeyManager;[Ljavax/net/ssl/TrustManager;Ljava/security/SecureRandom;)V
  149. new-instance v3, Lokhttp3/internal/tls/SslClient;
  150. aget-object v0, v0, v2
  151. check-cast v0, Ljavax/net/ssl/X509TrustManager;
  152. const/4 v2, 0x0
  153. invoke-direct {v3, v1, v0, v2}, Lokhttp3/internal/tls/SslClient;-><init>(Ljavax/net/ssl/SSLContext;Ljavax/net/ssl/X509TrustManager;Lokhttp3/internal/tls/SslClient$1;)V
  154. return-object v3
  155. :cond_2
  156. new-instance v1, Ljava/lang/IllegalStateException;
  157. new-instance v2, Ljava/lang/StringBuilder;
  158. invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
  159. const-string v3, "Unexpected default trust managers:"
  160. invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  161. invoke-static {v0}, Ljava/util/Arrays;->toString([Ljava/lang/Object;)Ljava/lang/String;
  162. move-result-object v0
  163. invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  164. invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  165. move-result-object v0
  166. invoke-direct {v1, v0}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
  167. throw v1
  168. :try_end_0
  169. .catch Ljava/security/GeneralSecurityException; {:try_start_0 .. :try_end_0} :catch_0
  170. :catch_0
  171. move-exception v0
  172. new-instance v1, Ljava/lang/AssertionError;
  173. invoke-direct {v1, v0}, Ljava/lang/AssertionError;-><init>(Ljava/lang/Object;)V
  174. goto :goto_2
  175. :goto_1
  176. throw v1
  177. :goto_2
  178. goto :goto_1
  179. .end method
  180. .method public varargs certificateChain(Ljava/security/KeyPair;Ljava/security/cert/X509Certificate;[Ljava/security/cert/X509Certificate;)Lokhttp3/internal/tls/SslClient$Builder;
  181. .locals 0
  182. iput-object p1, p0, Lokhttp3/internal/tls/SslClient$Builder;->keyPair:Ljava/security/KeyPair;
  183. iget-object p1, p0, Lokhttp3/internal/tls/SslClient$Builder;->chainCertificates:Ljava/util/List;
  184. invoke-interface {p1, p2}, Ljava/util/List;->add(Ljava/lang/Object;)Z
  185. iget-object p1, p0, Lokhttp3/internal/tls/SslClient$Builder;->chainCertificates:Ljava/util/List;
  186. invoke-static {p3}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;
  187. move-result-object p2
  188. invoke-interface {p1, p2}, Ljava/util/List;->addAll(Ljava/util/Collection;)Z
  189. iget-object p1, p0, Lokhttp3/internal/tls/SslClient$Builder;->certificates:Ljava/util/List;
  190. invoke-static {p3}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;
  191. move-result-object p2
  192. invoke-interface {p1, p2}, Ljava/util/List;->addAll(Ljava/util/Collection;)Z
  193. return-object p0
  194. .end method
  195. .method public varargs certificateChain(Lokhttp3/internal/tls/HeldCertificate;[Lokhttp3/internal/tls/HeldCertificate;)Lokhttp3/internal/tls/SslClient$Builder;
  196. .locals 3
  197. array-length v0, p2
  198. new-array v0, v0, [Ljava/security/cert/X509Certificate;
  199. const/4 v1, 0x0
  200. :goto_0
  201. array-length v2, p2
  202. if-ge v1, v2, :cond_0
  203. aget-object v2, p2, v1
  204. iget-object v2, v2, Lokhttp3/internal/tls/HeldCertificate;->certificate:Ljava/security/cert/X509Certificate;
  205. aput-object v2, v0, v1
  206. add-int/lit8 v1, v1, 0x1
  207. goto :goto_0
  208. :cond_0
  209. iget-object p2, p1, Lokhttp3/internal/tls/HeldCertificate;->keyPair:Ljava/security/KeyPair;
  210. iget-object p1, p1, Lokhttp3/internal/tls/HeldCertificate;->certificate:Ljava/security/cert/X509Certificate;
  211. invoke-virtual {p0, p2, p1, v0}, Lokhttp3/internal/tls/SslClient$Builder;->certificateChain(Ljava/security/KeyPair;Ljava/security/cert/X509Certificate;[Ljava/security/cert/X509Certificate;)Lokhttp3/internal/tls/SslClient$Builder;
  212. move-result-object p1
  213. return-object p1
  214. .end method
  215. .method public keyStoreType(Ljava/lang/String;)Lokhttp3/internal/tls/SslClient$Builder;
  216. .locals 0
  217. iput-object p1, p0, Lokhttp3/internal/tls/SslClient$Builder;->keyStoreType:Ljava/lang/String;
  218. return-object p0
  219. .end method