181 lines
7.0 KiB
Java
181 lines
7.0 KiB
Java
package org.jmrtd.lds;
|
|
|
|
import com.google.common.primitives.UnsignedBytes;
|
|
import java.util.logging.Logger;
|
|
import org.bouncycastle.asn1.ASN1Encodable;
|
|
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.DEROctetString;
|
|
import org.bouncycastle.asn1.DLSequence;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class TerminalAuthenticationInfo extends SecurityInfo {
|
|
private static final Logger LOGGER = Logger.getLogger("org.jmrtd");
|
|
public static final int VERSION_1 = 1;
|
|
private static final int VERSION_2 = 2;
|
|
private static final long serialVersionUID = 6220506985707094044L;
|
|
private ASN1Sequence efCVCA;
|
|
private String oid;
|
|
private int version;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public TerminalAuthenticationInfo(String str, int i, ASN1Sequence aSN1Sequence) {
|
|
this.oid = str;
|
|
this.version = i;
|
|
this.efCVCA = aSN1Sequence;
|
|
checkFields();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public TerminalAuthenticationInfo(String str, int i) {
|
|
this(str, i, null);
|
|
}
|
|
|
|
public TerminalAuthenticationInfo() {
|
|
this(ID_TA, 1);
|
|
}
|
|
|
|
public TerminalAuthenticationInfo(short s, byte b) {
|
|
this(ID_TA, 1, constructEFCVCA(s, b));
|
|
}
|
|
|
|
@Override // org.jmrtd.lds.SecurityInfo
|
|
@Deprecated
|
|
public ASN1Primitive getDERObject() {
|
|
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
|
|
aSN1EncodableVector.add(new ASN1ObjectIdentifier(this.oid));
|
|
aSN1EncodableVector.add(new ASN1Integer(this.version));
|
|
ASN1Sequence aSN1Sequence = this.efCVCA;
|
|
if (aSN1Sequence != null) {
|
|
aSN1EncodableVector.add(aSN1Sequence);
|
|
}
|
|
return new DLSequence(aSN1EncodableVector);
|
|
}
|
|
|
|
@Override // org.jmrtd.lds.SecurityInfo
|
|
public String getProtocolOIDString() {
|
|
return toProtocolOIDString(this.oid);
|
|
}
|
|
|
|
public int getFileId() {
|
|
return getFileId(this.efCVCA);
|
|
}
|
|
|
|
public byte getShortFileId() {
|
|
return getShortFileId(this.efCVCA);
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder("TerminalAuthenticationInfo [protocol: ");
|
|
sb.append(toProtocolOIDString(this.oid));
|
|
sb.append(", version: ");
|
|
sb.append(this.version);
|
|
sb.append(", fileID: ");
|
|
sb.append(getFileId());
|
|
sb.append(", shortFileID: ");
|
|
sb.append((int) getShortFileId());
|
|
sb.append("]");
|
|
return sb.toString();
|
|
}
|
|
|
|
public int hashCode() {
|
|
String str = this.oid;
|
|
int hashCode = str == null ? 0 : str.hashCode();
|
|
int i = this.version;
|
|
ASN1Sequence aSN1Sequence = this.efCVCA;
|
|
return (hashCode * 7) + 123 + (i * 5) + ((aSN1Sequence == null ? 1 : aSN1Sequence.hashCode()) * 3);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (obj == null) {
|
|
return false;
|
|
}
|
|
if (obj == this) {
|
|
return true;
|
|
}
|
|
if (!TerminalAuthenticationInfo.class.equals(obj.getClass())) {
|
|
return false;
|
|
}
|
|
TerminalAuthenticationInfo terminalAuthenticationInfo = (TerminalAuthenticationInfo) obj;
|
|
ASN1Sequence aSN1Sequence = this.efCVCA;
|
|
if (aSN1Sequence == null && terminalAuthenticationInfo.efCVCA != null) {
|
|
return false;
|
|
}
|
|
if (aSN1Sequence == null || terminalAuthenticationInfo.efCVCA != null) {
|
|
return getDERObject().equals(terminalAuthenticationInfo.getDERObject());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static boolean checkRequiredIdentifier(String str) {
|
|
return ID_TA.equals(str);
|
|
}
|
|
|
|
private void checkFields() {
|
|
try {
|
|
if (!checkRequiredIdentifier(this.oid)) {
|
|
StringBuilder sb = new StringBuilder("Wrong identifier: ");
|
|
sb.append(this.oid);
|
|
throw new IllegalArgumentException(sb.toString());
|
|
}
|
|
int i = this.version;
|
|
if (i != 1 && i != 2) {
|
|
StringBuilder sb2 = new StringBuilder("Wrong version. Was expecting 1 or 2, found ");
|
|
sb2.append(this.version);
|
|
throw new IllegalArgumentException(sb2.toString());
|
|
}
|
|
ASN1Sequence aSN1Sequence = this.efCVCA;
|
|
if (aSN1Sequence != null) {
|
|
if (((DEROctetString) aSN1Sequence.getObjectAt(0)).getOctets().length != 2) {
|
|
throw new IllegalArgumentException("Malformed FID.");
|
|
}
|
|
if (this.efCVCA.size() == 2 && ((DEROctetString) this.efCVCA.getObjectAt(1)).getOctets().length != 1) {
|
|
throw new IllegalArgumentException("Malformed SFI.");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
Logger logger = LOGGER;
|
|
StringBuilder sb3 = new StringBuilder("Exception: ");
|
|
sb3.append(e.getMessage());
|
|
logger.severe(sb3.toString());
|
|
throw new IllegalArgumentException("Malformed TerminalAuthenticationInfo.");
|
|
}
|
|
}
|
|
|
|
private static ASN1Sequence constructEFCVCA(short s, byte b) {
|
|
return b != -1 ? new DLSequence(new ASN1Encodable[]{new DEROctetString(new byte[]{(byte) ((65280 & s) >> 8), (byte) s}), new DEROctetString(new byte[]{b})}) : new DLSequence(new ASN1Encodable[]{new DEROctetString(new byte[]{(byte) ((s & 65280) >> 8), (byte) s})});
|
|
}
|
|
|
|
private static short getFileId(ASN1Sequence aSN1Sequence) {
|
|
if (aSN1Sequence == null) {
|
|
return (short) -1;
|
|
}
|
|
byte[] octets = ((DEROctetString) aSN1Sequence.getObjectAt(0)).getOctets();
|
|
return (short) ((octets[1] & UnsignedBytes.MAX_VALUE) | ((octets[0] & UnsignedBytes.MAX_VALUE) << 8));
|
|
}
|
|
|
|
private static byte getShortFileId(ASN1Sequence aSN1Sequence) {
|
|
if (aSN1Sequence != null && aSN1Sequence.size() == 2) {
|
|
return ((DEROctetString) aSN1Sequence.getObjectAt(1)).getOctets()[0];
|
|
}
|
|
return (byte) -1;
|
|
}
|
|
|
|
private String toProtocolOIDString(String str) {
|
|
return ID_TA.equals(str) ? "id-TA" : ID_TA_RSA.equals(str) ? "id-TA-RSA" : ID_TA_RSA_V1_5_SHA_1.equals(str) ? "id-TA-RSA-v1-5-SHA-1" : ID_TA_RSA_V1_5_SHA_256.equals(str) ? "id-TA-RSA-v1-5-SHA-256" : ID_TA_RSA_PSS_SHA_1.equals(str) ? "id-TA-RSA-PSS-SHA-1" : ID_TA_RSA_PSS_SHA_256.equals(str) ? "id-TA-RSA-PSS-SHA-256" : ID_TA_ECDSA.equals(str) ? "id-TA-ECDSA" : ID_TA_ECDSA_SHA_1.equals(str) ? "id-TA-ECDSA-SHA-1" : ID_TA_ECDSA_SHA_224.equals(str) ? "id-TA-ECDSA-SHA-224" : ID_TA_ECDSA_SHA_256.equals(str) ? "id-TA-ECDSA-SHA-256" : str;
|
|
}
|
|
|
|
public int getVersion() {
|
|
return this.version;
|
|
}
|
|
|
|
@Override // org.jmrtd.lds.SecurityInfo
|
|
public String getObjectIdentifier() {
|
|
return this.oid;
|
|
}
|
|
}
|