what-the-bank/sources/org/jmrtd/lds/ChipAuthenticationPublicKey...

141 lines
5.4 KiB
Java

package org.jmrtd.lds;
import java.math.BigInteger;
import java.security.Provider;
import java.security.PublicKey;
import java.util.logging.Logger;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DLSequence;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.jmrtd.JMRTDSecurityProvider;
import org.jmrtd.Util;
/* loaded from: classes6.dex */
public class ChipAuthenticationPublicKeyInfo extends SecurityInfo {
private static final long serialVersionUID = 5687291829854501771L;
private BigInteger keyId;
private String oid;
private SubjectPublicKeyInfo subjectPublicKeyInfo;
private static final Logger LOGGER = Logger.getLogger("org.jmrtd");
private static final Provider BC_PROVIDER = JMRTDSecurityProvider.getBouncyCastleProvider();
/* JADX INFO: Access modifiers changed from: package-private */
public ChipAuthenticationPublicKeyInfo(String str, SubjectPublicKeyInfo subjectPublicKeyInfo) {
this(str, subjectPublicKeyInfo, null);
}
public ChipAuthenticationPublicKeyInfo(PublicKey publicKey, BigInteger bigInteger) {
this(Util.inferProtocolIdentifier(publicKey), Util.toSubjectPublicKeyInfo(Util.reconstructPublicKey(publicKey)), bigInteger);
}
public ChipAuthenticationPublicKeyInfo(PublicKey publicKey) {
this(publicKey, (BigInteger) null);
}
/* JADX INFO: Access modifiers changed from: package-private */
public ChipAuthenticationPublicKeyInfo(String str, SubjectPublicKeyInfo subjectPublicKeyInfo, BigInteger bigInteger) {
this.oid = str;
this.subjectPublicKeyInfo = subjectPublicKeyInfo;
this.keyId = bigInteger;
checkFields();
}
@Override // org.jmrtd.lds.SecurityInfo
@Deprecated
public ASN1Primitive getDERObject() {
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
aSN1EncodableVector.add(new ASN1ObjectIdentifier(this.oid));
aSN1EncodableVector.add((ASN1Sequence) this.subjectPublicKeyInfo.toASN1Primitive());
BigInteger bigInteger = this.keyId;
if (bigInteger != null) {
aSN1EncodableVector.add(new ASN1Integer(bigInteger));
}
return new DLSequence(aSN1EncodableVector);
}
@Override // org.jmrtd.lds.SecurityInfo
public String getProtocolOIDString() {
return toProtocolOIDString(this.oid);
}
public PublicKey getSubjectPublicKey() {
return Util.toPublicKey(this.subjectPublicKeyInfo);
}
protected void checkFields() {
try {
if (checkRequiredIdentifier(this.oid)) {
return;
}
StringBuilder sb = new StringBuilder("Wrong identifier: ");
sb.append(this.oid);
throw new IllegalArgumentException(sb.toString());
} catch (Exception e) {
Logger logger = LOGGER;
StringBuilder sb2 = new StringBuilder("Exception: ");
sb2.append(e.getMessage());
logger.severe(sb2.toString());
throw new IllegalArgumentException("Malformed ChipAuthenticationInfo.");
}
}
public static boolean checkRequiredIdentifier(String str) {
return ID_PK_DH.equals(str) || ID_PK_ECDH.equals(str);
}
public String toString() {
StringBuilder sb = new StringBuilder("ChipAuthenticationPublicKeyInfo [protocol: ");
sb.append(toProtocolOIDString(this.oid));
sb.append(", chipAuthenticationPublicKey: ");
sb.append(Util.getDetailedPublicKeyAlgorithm(getSubjectPublicKey()));
sb.append(", keyId: ");
BigInteger bigInteger = this.keyId;
sb.append(bigInteger == null ? "-" : bigInteger.toString());
sb.append("]");
return sb.toString();
}
public int hashCode() {
int hashCode = this.oid.hashCode();
BigInteger bigInteger = this.keyId;
int hashCode2 = bigInteger == null ? 111 : bigInteger.hashCode();
SubjectPublicKeyInfo subjectPublicKeyInfo = this.subjectPublicKeyInfo;
return ((hashCode + hashCode2 + (subjectPublicKeyInfo != null ? subjectPublicKeyInfo.hashCode() : 111)) * 1337) + 123;
}
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (!ChipAuthenticationPublicKeyInfo.class.equals(obj.getClass())) {
return false;
}
ChipAuthenticationPublicKeyInfo chipAuthenticationPublicKeyInfo = (ChipAuthenticationPublicKeyInfo) obj;
if (!this.oid.equals(chipAuthenticationPublicKeyInfo.oid)) {
return false;
}
BigInteger bigInteger = this.keyId;
return ((bigInteger == null && chipAuthenticationPublicKeyInfo.keyId == null) || (bigInteger != null && bigInteger.equals(chipAuthenticationPublicKeyInfo.keyId))) && this.subjectPublicKeyInfo.equals(chipAuthenticationPublicKeyInfo.subjectPublicKeyInfo);
}
private static String toProtocolOIDString(String str) {
return ID_PK_DH.equals(str) ? "id-PK-DH" : ID_PK_ECDH.equals(str) ? "id-PK-ECDH" : str;
}
@Override // org.jmrtd.lds.SecurityInfo
public String getObjectIdentifier() {
return this.oid;
}
public BigInteger getKeyId() {
return this.keyId;
}
}