HeldCertificate$Builder.smali 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. .class public final Lokhttp3/internal/tls/HeldCertificate$Builder;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # annotations
  5. .annotation system Ldalvik/annotation/EnclosingClass;
  6. value = Lokhttp3/internal/tls/HeldCertificate;
  7. .end annotation
  8. .annotation system Ldalvik/annotation/InnerClass;
  9. accessFlags = 0x19
  10. name = "Builder"
  11. .end annotation
  12. # instance fields
  13. .field private altNames:Ljava/util/List;
  14. .annotation system Ldalvik/annotation/Signature;
  15. value = {
  16. "Ljava/util/List<",
  17. "Ljava/lang/String;",
  18. ">;"
  19. }
  20. .end annotation
  21. .end field
  22. .field private final duration:J
  23. .field private hostname:Ljava/lang/String;
  24. .field private issuedBy:Lokhttp3/internal/tls/HeldCertificate;
  25. .field private keyPair:Ljava/security/KeyPair;
  26. .field private maxIntermediateCas:I
  27. .field private serialNumber:Ljava/lang/String;
  28. # direct methods
  29. .method static constructor <clinit>()V
  30. .locals 1
  31. new-instance v0, Lorg/bouncycastle/jce/provider/BouncyCastleProvider;
  32. invoke-direct {v0}, Lorg/bouncycastle/jce/provider/BouncyCastleProvider;-><init>()V
  33. invoke-static {v0}, Ljava/security/Security;->addProvider(Ljava/security/Provider;)I
  34. return-void
  35. .end method
  36. .method public constructor <init>()V
  37. .locals 2
  38. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  39. const-wide/32 v0, 0x5265c00
  40. iput-wide v0, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->duration:J
  41. new-instance v0, Ljava/util/ArrayList;
  42. invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V
  43. iput-object v0, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->altNames:Ljava/util/List;
  44. const-string v0, "1"
  45. iput-object v0, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->serialNumber:Ljava/lang/String;
  46. return-void
  47. .end method
  48. # virtual methods
  49. .method public build()Lokhttp3/internal/tls/HeldCertificate;
  50. .locals 10
  51. .annotation system Ldalvik/annotation/Throws;
  52. value = {
  53. Ljava/security/GeneralSecurityException;
  54. }
  55. .end annotation
  56. iget-object v0, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->keyPair:Ljava/security/KeyPair;
  57. if-eqz v0, :cond_0
  58. goto :goto_0
  59. :cond_0
  60. invoke-virtual {p0}, Lokhttp3/internal/tls/HeldCertificate$Builder;->generateKeyPair()Ljava/security/KeyPair;
  61. move-result-object v0
  62. :goto_0
  63. iget-object v1, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->hostname:Ljava/lang/String;
  64. const-string v2, "CN="
  65. if-eqz v1, :cond_1
  66. new-instance v1, Ljavax/security/auth/x500/X500Principal;
  67. new-instance v3, Ljava/lang/StringBuilder;
  68. invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V
  69. invoke-virtual {v3, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  70. iget-object v2, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->hostname:Ljava/lang/String;
  71. invoke-virtual {v3, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  72. invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  73. move-result-object v2
  74. invoke-direct {v1, v2}, Ljavax/security/auth/x500/X500Principal;-><init>(Ljava/lang/String;)V
  75. goto :goto_1
  76. :cond_1
  77. new-instance v1, Ljavax/security/auth/x500/X500Principal;
  78. new-instance v3, Ljava/lang/StringBuilder;
  79. invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V
  80. invoke-virtual {v3, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  81. invoke-static {}, Ljava/util/UUID;->randomUUID()Ljava/util/UUID;
  82. move-result-object v2
  83. invoke-virtual {v3, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
  84. invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  85. move-result-object v2
  86. invoke-direct {v1, v2}, Ljavax/security/auth/x500/X500Principal;-><init>(Ljava/lang/String;)V
  87. :goto_1
  88. iget-object v2, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->issuedBy:Lokhttp3/internal/tls/HeldCertificate;
  89. if-eqz v2, :cond_2
  90. iget-object v3, v2, Lokhttp3/internal/tls/HeldCertificate;->keyPair:Ljava/security/KeyPair;
  91. iget-object v2, v2, Lokhttp3/internal/tls/HeldCertificate;->certificate:Ljava/security/cert/X509Certificate;
  92. invoke-virtual {v2}, Ljava/security/cert/X509Certificate;->getSubjectX500Principal()Ljavax/security/auth/x500/X500Principal;
  93. move-result-object v2
  94. goto :goto_2
  95. :cond_2
  96. move-object v3, v0
  97. move-object v2, v1
  98. :goto_2
  99. invoke-static {}, Ljava/lang/System;->currentTimeMillis()J
  100. move-result-wide v4
  101. new-instance v6, Lorg/bouncycastle/x509/i;
  102. invoke-direct {v6}, Lorg/bouncycastle/x509/i;-><init>()V
  103. new-instance v7, Ljava/math/BigInteger;
  104. iget-object v8, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->serialNumber:Ljava/lang/String;
  105. invoke-direct {v7, v8}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V
  106. invoke-virtual {v6, v7}, Lorg/bouncycastle/x509/i;->a(Ljava/math/BigInteger;)V
  107. invoke-virtual {v6, v2}, Lorg/bouncycastle/x509/i;->a(Ljavax/security/auth/x500/X500Principal;)V
  108. new-instance v2, Ljava/util/Date;
  109. invoke-direct {v2, v4, v5}, Ljava/util/Date;-><init>(J)V
  110. invoke-virtual {v6, v2}, Lorg/bouncycastle/x509/i;->b(Ljava/util/Date;)V
  111. new-instance v2, Ljava/util/Date;
  112. const-wide/32 v7, 0x5265c00
  113. add-long/2addr v4, v7
  114. invoke-direct {v2, v4, v5}, Ljava/util/Date;-><init>(J)V
  115. invoke-virtual {v6, v2}, Lorg/bouncycastle/x509/i;->a(Ljava/util/Date;)V
  116. invoke-virtual {v6, v1}, Lorg/bouncycastle/x509/i;->b(Ljavax/security/auth/x500/X500Principal;)V
  117. invoke-virtual {v0}, Ljava/security/KeyPair;->getPublic()Ljava/security/PublicKey;
  118. move-result-object v1
  119. invoke-virtual {v6, v1}, Lorg/bouncycastle/x509/i;->a(Ljava/security/PublicKey;)V
  120. const-string v1, "SHA256WithRSAEncryption"
  121. invoke-virtual {v6, v1}, Lorg/bouncycastle/x509/i;->a(Ljava/lang/String;)V
  122. iget v1, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->maxIntermediateCas:I
  123. const/4 v2, 0x1
  124. if-lez v1, :cond_3
  125. sget-object v4, Lorg/bouncycastle/asn1/k2/e0;->T0:Lorg/bouncycastle/asn1/l;
  126. new-instance v5, Lorg/bouncycastle/asn1/k2/h;
  127. invoke-direct {v5, v1}, Lorg/bouncycastle/asn1/k2/h;-><init>(I)V
  128. invoke-virtual {v6, v4, v2, v5}, Lorg/bouncycastle/x509/i;->a(Lorg/bouncycastle/asn1/a1;ZLorg/bouncycastle/asn1/d;)V
  129. :cond_3
  130. iget-object v1, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->altNames:Ljava/util/List;
  131. invoke-interface {v1}, Ljava/util/List;->isEmpty()Z
  132. move-result v1
  133. if-nez v1, :cond_6
  134. iget-object v1, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->altNames:Ljava/util/List;
  135. invoke-interface {v1}, Ljava/util/List;->size()I
  136. move-result v1
  137. new-array v1, v1, [Lorg/bouncycastle/asn1/d;
  138. const/4 v4, 0x0
  139. iget-object v5, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->altNames:Ljava/util/List;
  140. invoke-interface {v5}, Ljava/util/List;->size()I
  141. move-result v5
  142. :goto_3
  143. if-ge v4, v5, :cond_5
  144. iget-object v7, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->altNames:Ljava/util/List;
  145. invoke-interface {v7, v4}, Ljava/util/List;->get(I)Ljava/lang/Object;
  146. move-result-object v7
  147. check-cast v7, Ljava/lang/String;
  148. invoke-static {v7}, Lokhttp3/internal/Util;->verifyAsIpAddress(Ljava/lang/String;)Z
  149. move-result v8
  150. if-eqz v8, :cond_4
  151. const/4 v8, 0x7
  152. goto :goto_4
  153. :cond_4
  154. const/4 v8, 0x2
  155. :goto_4
  156. new-instance v9, Lorg/bouncycastle/asn1/k2/m;
  157. invoke-direct {v9, v8, v7}, Lorg/bouncycastle/asn1/k2/m;-><init>(ILjava/lang/String;)V
  158. aput-object v9, v1, v4
  159. add-int/lit8 v4, v4, 0x1
  160. goto :goto_3
  161. :cond_5
  162. sget-object v4, Lorg/bouncycastle/asn1/k2/e0;->S0:Lorg/bouncycastle/asn1/l;
  163. new-instance v5, Lorg/bouncycastle/asn1/f1;
  164. invoke-direct {v5, v1}, Lorg/bouncycastle/asn1/f1;-><init>([Lorg/bouncycastle/asn1/d;)V
  165. invoke-virtual {v6, v4, v2, v5}, Lorg/bouncycastle/x509/i;->a(Lorg/bouncycastle/asn1/a1;ZLorg/bouncycastle/asn1/d;)V
  166. :cond_6
  167. invoke-virtual {v3}, Ljava/security/KeyPair;->getPrivate()Ljava/security/PrivateKey;
  168. move-result-object v1
  169. const-string v2, "BC"
  170. invoke-virtual {v6, v1, v2}, Lorg/bouncycastle/x509/i;->a(Ljava/security/PrivateKey;Ljava/lang/String;)Ljava/security/cert/X509Certificate;
  171. move-result-object v1
  172. new-instance v2, Lokhttp3/internal/tls/HeldCertificate;
  173. invoke-direct {v2, v1, v0}, Lokhttp3/internal/tls/HeldCertificate;-><init>(Ljava/security/cert/X509Certificate;Ljava/security/KeyPair;)V
  174. return-object v2
  175. .end method
  176. .method public ca(I)Lokhttp3/internal/tls/HeldCertificate$Builder;
  177. .locals 0
  178. iput p1, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->maxIntermediateCas:I
  179. return-object p0
  180. .end method
  181. .method public commonName(Ljava/lang/String;)Lokhttp3/internal/tls/HeldCertificate$Builder;
  182. .locals 0
  183. iput-object p1, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->hostname:Ljava/lang/String;
  184. return-object p0
  185. .end method
  186. .method public generateKeyPair()Ljava/security/KeyPair;
  187. .locals 3
  188. .annotation system Ldalvik/annotation/Throws;
  189. value = {
  190. Ljava/security/GeneralSecurityException;
  191. }
  192. .end annotation
  193. const-string v0, "RSA"
  194. const-string v1, "BC"
  195. invoke-static {v0, v1}, Ljava/security/KeyPairGenerator;->getInstance(Ljava/lang/String;Ljava/lang/String;)Ljava/security/KeyPairGenerator;
  196. move-result-object v0
  197. new-instance v1, Ljava/security/SecureRandom;
  198. invoke-direct {v1}, Ljava/security/SecureRandom;-><init>()V
  199. const/16 v2, 0x400
  200. invoke-virtual {v0, v2, v1}, Ljava/security/KeyPairGenerator;->initialize(ILjava/security/SecureRandom;)V
  201. invoke-virtual {v0}, Ljava/security/KeyPairGenerator;->generateKeyPair()Ljava/security/KeyPair;
  202. move-result-object v0
  203. return-object v0
  204. .end method
  205. .method public issuedBy(Lokhttp3/internal/tls/HeldCertificate;)Lokhttp3/internal/tls/HeldCertificate$Builder;
  206. .locals 0
  207. iput-object p1, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->issuedBy:Lokhttp3/internal/tls/HeldCertificate;
  208. return-object p0
  209. .end method
  210. .method public keyPair(Ljava/security/KeyPair;)Lokhttp3/internal/tls/HeldCertificate$Builder;
  211. .locals 0
  212. iput-object p1, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->keyPair:Ljava/security/KeyPair;
  213. return-object p0
  214. .end method
  215. .method public serialNumber(Ljava/lang/String;)Lokhttp3/internal/tls/HeldCertificate$Builder;
  216. .locals 0
  217. iput-object p1, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->serialNumber:Ljava/lang/String;
  218. return-object p0
  219. .end method
  220. .method public subjectAlternativeName(Ljava/lang/String;)Lokhttp3/internal/tls/HeldCertificate$Builder;
  221. .locals 1
  222. iget-object v0, p0, Lokhttp3/internal/tls/HeldCertificate$Builder;->altNames:Ljava/util/List;
  223. invoke-interface {v0, p1}, Ljava/util/List;->add(Ljava/lang/Object;)Z
  224. return-object p0
  225. .end method