OpenSSLRSAPrivateKey.smali
.class Lorg/conscrypt/OpenSSLRSAPrivateKey;
.super Ljava/lang/Object;
.source ""
# interfaces
.implements Ljava/security/interfaces/RSAPrivateKey;
.implements Lorg/conscrypt/OpenSSLKeyHolder;
# static fields
.field private static final serialVersionUID:J = 0x439d6d0855187c6fL
# instance fields
.field transient fetchedParams:Z
.field transient key:Lorg/conscrypt/OpenSSLKey;
.field modulus:Ljava/math/BigInteger;
.field privateExponent:Ljava/math/BigInteger;
# direct methods
.method public constructor <init>(Ljava/security/spec/RSAPrivateKeySpec;)V
.registers 2
invoke-static {p1}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->init(Ljava/security/spec/RSAPrivateKeySpec;)Lorg/conscrypt/OpenSSLKey;
move-result-object p1
invoke-direct {p0, p1}, Lorg/conscrypt/OpenSSLRSAPrivateKey;-><init>(Lorg/conscrypt/OpenSSLKey;)V
return-void
.end method
.method constructor <init>(Lorg/conscrypt/OpenSSLKey;)V
.registers 2
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
iput-object p1, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
return-void
.end method
.method constructor <init>(Lorg/conscrypt/OpenSSLKey;[[B)V
.registers 3
invoke-direct {p0, p1}, Lorg/conscrypt/OpenSSLRSAPrivateKey;-><init>(Lorg/conscrypt/OpenSSLKey;)V
invoke-virtual {p0, p2}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->readParams([[B)V
const/4 p1, 0x1
iput-boolean p1, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->fetchedParams:Z
return-void
.end method
.method static getInstance(Ljava/security/interfaces/RSAPrivateKey;)Lorg/conscrypt/OpenSSLKey;
.registers 11
invoke-interface {p0}, Ljava/security/interfaces/RSAPrivateKey;->getFormat()Ljava/lang/String;
move-result-object v0
if-nez v0, :cond_b
invoke-static {p0}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->wrapPlatformKey(Ljava/security/interfaces/RSAPrivateKey;)Lorg/conscrypt/OpenSSLKey;
move-result-object p0
return-object p0
:cond_b
invoke-interface {p0}, Ljava/security/interfaces/RSAPrivateKey;->getModulus()Ljava/math/BigInteger;
move-result-object v0
invoke-interface {p0}, Ljava/security/interfaces/RSAPrivateKey;->getPrivateExponent()Ljava/math/BigInteger;
move-result-object p0
if-eqz v0, :cond_3e
if-eqz p0, :cond_36
:try_start_17
new-instance v1, Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v0}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v2
const/4 v3, 0x0
invoke-virtual {p0}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v4
const/4 v5, 0x0
const/4 v6, 0x0
const/4 v7, 0x0
const/4 v8, 0x0
const/4 v9, 0x0
invoke-static/range {v2 .. v9}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_new_RSA([B[B[B[B[B[B[B[B)J
move-result-wide v2
invoke-direct {v1, v2, v3}, Lorg/conscrypt/OpenSSLKey;-><init>(J)V
:try_end_2e
.catch Ljava/lang/Exception; {:try_start_17 .. :try_end_2e} :catch_2f
return-object v1
:catch_2f
move-exception p0
new-instance v0, Ljava/security/InvalidKeyException;
invoke-direct {v0, p0}, Ljava/security/InvalidKeyException;-><init>(Ljava/lang/Throwable;)V
throw v0
:cond_36
new-instance p0, Ljava/security/InvalidKeyException;
const-string v0, "privateExponent == null"
invoke-direct {p0, v0}, Ljava/security/InvalidKeyException;-><init>(Ljava/lang/String;)V
throw p0
:cond_3e
new-instance p0, Ljava/security/InvalidKeyException;
const-string v0, "modulus == null"
invoke-direct {p0, v0}, Ljava/security/InvalidKeyException;-><init>(Ljava/lang/String;)V
throw p0
.end method
.method static getInstance(Lorg/conscrypt/OpenSSLKey;)Lorg/conscrypt/OpenSSLRSAPrivateKey;
.registers 3
invoke-virtual {p0}, Lorg/conscrypt/OpenSSLKey;->getNativeRef()Lorg/conscrypt/NativeRef$EVP_PKEY;
move-result-object v0
invoke-static {v0}, Lorg/conscrypt/NativeCrypto;->get_RSA_private_params(Lorg/conscrypt/NativeRef$EVP_PKEY;)[[B
move-result-object v0
const/4 v1, 0x1
aget-object v1, v0, v1
if-eqz v1, :cond_13
new-instance v1, Lorg/conscrypt/OpenSSLRSAPrivateCrtKey;
invoke-direct {v1, p0, v0}, Lorg/conscrypt/OpenSSLRSAPrivateCrtKey;-><init>(Lorg/conscrypt/OpenSSLKey;[[B)V
return-object v1
:cond_13
new-instance v1, Lorg/conscrypt/OpenSSLRSAPrivateKey;
invoke-direct {v1, p0, v0}, Lorg/conscrypt/OpenSSLRSAPrivateKey;-><init>(Lorg/conscrypt/OpenSSLKey;[[B)V
return-object v1
.end method
.method private static init(Ljava/security/spec/RSAPrivateKeySpec;)Lorg/conscrypt/OpenSSLKey;
.registers 11
invoke-virtual {p0}, Ljava/security/spec/RSAPrivateKeySpec;->getModulus()Ljava/math/BigInteger;
move-result-object v0
invoke-virtual {p0}, Ljava/security/spec/RSAPrivateKeySpec;->getPrivateExponent()Ljava/math/BigInteger;
move-result-object p0
if-eqz v0, :cond_33
if-eqz p0, :cond_2b
:try_start_c
new-instance v1, Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v0}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v2
const/4 v3, 0x0
invoke-virtual {p0}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v4
const/4 v5, 0x0
const/4 v6, 0x0
const/4 v7, 0x0
const/4 v8, 0x0
const/4 v9, 0x0
invoke-static/range {v2 .. v9}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_new_RSA([B[B[B[B[B[B[B[B)J
move-result-wide v2
invoke-direct {v1, v2, v3}, Lorg/conscrypt/OpenSSLKey;-><init>(J)V
:try_end_23
.catch Ljava/lang/Exception; {:try_start_c .. :try_end_23} :catch_24
return-object v1
:catch_24
move-exception p0
new-instance v0, Ljava/security/spec/InvalidKeySpecException;
invoke-direct {v0, p0}, Ljava/security/spec/InvalidKeySpecException;-><init>(Ljava/lang/Throwable;)V
throw v0
:cond_2b
new-instance p0, Ljava/security/spec/InvalidKeySpecException;
const-string v0, "privateExponent == null"
invoke-direct {p0, v0}, Ljava/security/spec/InvalidKeySpecException;-><init>(Ljava/lang/String;)V
throw p0
:cond_33
new-instance p0, Ljava/security/spec/InvalidKeySpecException;
const-string v0, "modulus == null"
invoke-direct {p0, v0}, Ljava/security/spec/InvalidKeySpecException;-><init>(Ljava/lang/String;)V
throw p0
.end method
.method private readObject(Ljava/io/ObjectInputStream;)V
.registers 11
invoke-virtual {p1}, Ljava/io/ObjectInputStream;->defaultReadObject()V
new-instance p1, Lorg/conscrypt/OpenSSLKey;
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->modulus:Ljava/math/BigInteger;
invoke-virtual {v0}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v1
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->privateExponent:Ljava/math/BigInteger;
invoke-virtual {v0}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v3
const/4 v2, 0x0
const/4 v4, 0x0
const/4 v5, 0x0
const/4 v6, 0x0
const/4 v7, 0x0
const/4 v8, 0x0
invoke-static/range {v1 .. v8}, Lorg/conscrypt/NativeCrypto;->EVP_PKEY_new_RSA([B[B[B[B[B[B[B[B)J
move-result-wide v0
invoke-direct {p1, v0, v1}, Lorg/conscrypt/OpenSSLKey;-><init>(J)V
iput-object p1, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
const/4 p1, 0x1
iput-boolean p1, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->fetchedParams:Z
return-void
.end method
.method static wrapJCAPrivateKeyForTLSStackOnly(Ljava/security/PrivateKey;Ljava/security/PublicKey;)Lorg/conscrypt/OpenSSLKey;
.registers 5
instance-of v0, p0, Ljava/security/interfaces/RSAKey;
if-eqz v0, :cond_c
move-object v0, p0
check-cast v0, Ljava/security/interfaces/RSAKey;
:goto_7
invoke-interface {v0}, Ljava/security/interfaces/RSAKey;->getModulus()Ljava/math/BigInteger;
move-result-object v0
goto :goto_15
:cond_c
instance-of v0, p1, Ljava/security/interfaces/RSAKey;
if-eqz v0, :cond_14
move-object v0, p1
check-cast v0, Ljava/security/interfaces/RSAKey;
goto :goto_7
:cond_14
const/4 v0, 0x0
:goto_15
if-eqz v0, :cond_26
new-instance p1, Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v0}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v0
invoke-static {p0, v0}, Lorg/conscrypt/NativeCrypto;->getRSAPrivateKeyWrapper(Ljava/security/PrivateKey;[B)J
move-result-wide v0
const/4 p0, 0x1
invoke-direct {p1, v0, v1, p0}, Lorg/conscrypt/OpenSSLKey;-><init>(JZ)V
return-object p1
:cond_26
new-instance v0, Ljava/security/InvalidKeyException;
new-instance v1, Ljava/lang/StringBuilder;
invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
const-string v2, "RSA modulus not available. Private: "
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
const-string p0, ", public: "
invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v1, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object p0
invoke-direct {v0, p0}, Ljava/security/InvalidKeyException;-><init>(Ljava/lang/String;)V
goto :goto_46
:goto_45
throw v0
:goto_46
goto :goto_45
.end method
.method static wrapPlatformKey(Ljava/security/interfaces/RSAPrivateKey;)Lorg/conscrypt/OpenSSLKey;
.registers 4
invoke-static {p0}, Lorg/conscrypt/Platform;->wrapRsaKey(Ljava/security/PrivateKey;)Lorg/conscrypt/OpenSSLKey;
move-result-object v0
if-eqz v0, :cond_7
return-object v0
:cond_7
new-instance v0, Lorg/conscrypt/OpenSSLKey;
invoke-interface {p0}, Ljava/security/interfaces/RSAPrivateKey;->getModulus()Ljava/math/BigInteger;
move-result-object v1
invoke-virtual {v1}, Ljava/math/BigInteger;->toByteArray()[B
move-result-object v1
invoke-static {p0, v1}, Lorg/conscrypt/NativeCrypto;->getRSAPrivateKeyWrapper(Ljava/security/PrivateKey;[B)J
move-result-wide v1
const/4 p0, 0x1
invoke-direct {v0, v1, v2, p0}, Lorg/conscrypt/OpenSSLKey;-><init>(JZ)V
return-object v0
.end method
.method private writeObject(Ljava/io/ObjectOutputStream;)V
.registers 3
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v0}, Lorg/conscrypt/OpenSSLKey;->isHardwareBacked()Z
move-result v0
if-nez v0, :cond_f
invoke-virtual {p0}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->ensureReadParams()V
invoke-virtual {p1}, Ljava/io/ObjectOutputStream;->defaultWriteObject()V
return-void
:cond_f
new-instance p1, Ljava/io/NotSerializableException;
const-string v0, "Hardware backed keys can not be serialized"
invoke-direct {p1, v0}, Ljava/io/NotSerializableException;-><init>(Ljava/lang/String;)V
throw p1
.end method
# virtual methods
.method final declared-synchronized ensureReadParams()V
.registers 2
monitor-enter p0
:try_start_1
iget-boolean v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->fetchedParams:Z
:try_end_3
.catchall {:try_start_1 .. :try_end_3} :catchall_19
if-eqz v0, :cond_7
monitor-exit p0
return-void
:cond_7
:try_start_7
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v0}, Lorg/conscrypt/OpenSSLKey;->getNativeRef()Lorg/conscrypt/NativeRef$EVP_PKEY;
move-result-object v0
invoke-static {v0}, Lorg/conscrypt/NativeCrypto;->get_RSA_private_params(Lorg/conscrypt/NativeRef$EVP_PKEY;)[[B
move-result-object v0
invoke-virtual {p0, v0}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->readParams([[B)V
const/4 v0, 0x1
iput-boolean v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->fetchedParams:Z
:try_end_17
.catchall {:try_start_7 .. :try_end_17} :catchall_19
monitor-exit p0
return-void
:catchall_19
move-exception v0
monitor-exit p0
throw v0
.end method
.method public equals(Ljava/lang/Object;)Z
.registers 6
const/4 v0, 0x1
if-ne p1, p0, :cond_4
return v0
:cond_4
instance-of v1, p1, Lorg/conscrypt/OpenSSLRSAPrivateKey;
if-eqz v1, :cond_15
check-cast p1, Lorg/conscrypt/OpenSSLRSAPrivateKey;
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {p1}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->getOpenSSLKey()Lorg/conscrypt/OpenSSLKey;
move-result-object p1
invoke-virtual {v0, p1}, Lorg/conscrypt/OpenSSLKey;->equals(Ljava/lang/Object;)Z
move-result p1
return p1
:cond_15
instance-of v1, p1, Ljava/security/interfaces/RSAPrivateKey;
const/4 v2, 0x0
if-eqz v1, :cond_3a
invoke-virtual {p0}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->ensureReadParams()V
check-cast p1, Ljava/security/interfaces/RSAPrivateKey;
iget-object v1, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->modulus:Ljava/math/BigInteger;
invoke-interface {p1}, Ljava/security/interfaces/RSAPrivateKey;->getModulus()Ljava/math/BigInteger;
move-result-object v3
invoke-virtual {v1, v3}, Ljava/math/BigInteger;->equals(Ljava/lang/Object;)Z
move-result v1
if-eqz v1, :cond_38
iget-object v1, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->privateExponent:Ljava/math/BigInteger;
invoke-interface {p1}, Ljava/security/interfaces/RSAPrivateKey;->getPrivateExponent()Ljava/math/BigInteger;
move-result-object p1
invoke-virtual {v1, p1}, Ljava/math/BigInteger;->equals(Ljava/lang/Object;)Z
move-result p1
if-eqz p1, :cond_38
goto :goto_39
:cond_38
const/4 v0, 0x0
:goto_39
return v0
:cond_3a
return v2
.end method
.method public final getAlgorithm()Ljava/lang/String;
.registers 2
const-string v0, "RSA"
return-object v0
.end method
.method public final getEncoded()[B
.registers 2
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v0}, Lorg/conscrypt/OpenSSLKey;->isHardwareBacked()Z
move-result v0
if-eqz v0, :cond_a
const/4 v0, 0x0
return-object v0
:cond_a
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v0}, Lorg/conscrypt/OpenSSLKey;->getNativeRef()Lorg/conscrypt/NativeRef$EVP_PKEY;
move-result-object v0
invoke-static {v0}, Lorg/conscrypt/NativeCrypto;->EVP_marshal_private_key(Lorg/conscrypt/NativeRef$EVP_PKEY;)[B
move-result-object v0
return-object v0
.end method
.method public final getFormat()Ljava/lang/String;
.registers 2
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v0}, Lorg/conscrypt/OpenSSLKey;->isHardwareBacked()Z
move-result v0
if-eqz v0, :cond_a
const/4 v0, 0x0
return-object v0
:cond_a
const-string v0, "PKCS#8"
return-object v0
.end method
.method public final getModulus()Ljava/math/BigInteger;
.registers 2
invoke-virtual {p0}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->ensureReadParams()V
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->modulus:Ljava/math/BigInteger;
return-object v0
.end method
.method public getOpenSSLKey()Lorg/conscrypt/OpenSSLKey;
.registers 2
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
return-object v0
.end method
.method public final getPrivateExponent()Ljava/math/BigInteger;
.registers 3
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v0}, Lorg/conscrypt/OpenSSLKey;->isHardwareBacked()Z
move-result v0
if-nez v0, :cond_e
invoke-virtual {p0}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->ensureReadParams()V
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->privateExponent:Ljava/math/BigInteger;
return-object v0
:cond_e
new-instance v0, Ljava/lang/UnsupportedOperationException;
const-string v1, "Private exponent cannot be extracted"
invoke-direct {v0, v1}, Ljava/lang/UnsupportedOperationException;-><init>(Ljava/lang/String;)V
throw v0
.end method
.method public hashCode()I
.registers 3
invoke-virtual {p0}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->ensureReadParams()V
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->modulus:Ljava/math/BigInteger;
invoke-virtual {v0}, Ljava/math/BigInteger;->hashCode()I
move-result v0
const/4 v1, 0x3
add-int/2addr v1, v0
iget-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->privateExponent:Ljava/math/BigInteger;
if-eqz v0, :cond_16
mul-int/lit8 v1, v1, 0x7
invoke-virtual {v0}, Ljava/math/BigInteger;->hashCode()I
move-result v0
add-int/2addr v1, v0
:cond_16
return v1
.end method
.method readParams([[B)V
.registers 5
const/4 v0, 0x0
aget-object v1, p1, v0
if-eqz v1, :cond_32
const/4 v1, 0x2
aget-object v2, p1, v1
if-nez v2, :cond_1b
iget-object v2, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->key:Lorg/conscrypt/OpenSSLKey;
invoke-virtual {v2}, Lorg/conscrypt/OpenSSLKey;->isHardwareBacked()Z
move-result v2
if-eqz v2, :cond_13
goto :goto_1b
:cond_13
new-instance p1, Ljava/lang/NullPointerException;
const-string v0, "privateExponent == null"
invoke-direct {p1, v0}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V
throw p1
:cond_1b
:goto_1b
new-instance v2, Ljava/math/BigInteger;
aget-object v0, p1, v0
invoke-direct {v2, v0}, Ljava/math/BigInteger;-><init>([B)V
iput-object v2, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->modulus:Ljava/math/BigInteger;
aget-object v0, p1, v1
if-eqz v0, :cond_31
new-instance v0, Ljava/math/BigInteger;
aget-object p1, p1, v1
invoke-direct {v0, p1}, Ljava/math/BigInteger;-><init>([B)V
iput-object v0, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->privateExponent:Ljava/math/BigInteger;
:cond_31
return-void
:cond_32
new-instance p1, Ljava/lang/NullPointerException;
const-string v0, "modulus == null"
invoke-direct {p1, v0}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V
throw p1
.end method
.method public toString()Ljava/lang/String;
.registers 4
new-instance v0, Ljava/lang/StringBuilder;
const-string v1, "OpenSSLRSAPrivateKey{"
invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V
invoke-virtual {p0}, Lorg/conscrypt/OpenSSLRSAPrivateKey;->ensureReadParams()V
const-string v1, "modulus="
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
iget-object v1, p0, Lorg/conscrypt/OpenSSLRSAPrivateKey;->modulus:Ljava/math/BigInteger;
const/16 v2, 0x10
invoke-virtual {v1, v2}, Ljava/math/BigInteger;->toString(I)Ljava/lang/String;
move-result-object v1
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object v0
return-object v0
.end method