package org.bouncycastle.asn1.eac; import java.io.IOException; import org.bouncycastle.asn1.ASN1ApplicationSpecific; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1EncodableVector; import org.bouncycastle.asn1.ASN1InputStream; import org.bouncycastle.asn1.ASN1Object; import org.bouncycastle.asn1.ASN1Primitive; import org.bouncycastle.asn1.DERApplicationSpecific; import org.bouncycastle.asn1.DEROctetString; /* loaded from: classes6.dex */ public class CertificateBody extends ASN1Object { private static final int CAR = 2; private static final int CEfD = 32; private static final int CExD = 64; private static final int CHA = 16; private static final int CHR = 8; private static final int CPI = 1; private static final int PK = 4; public static final int profileType = 127; public static final int requestType = 13; private DERApplicationSpecific certificateEffectiveDate; private DERApplicationSpecific certificateExpirationDate; private CertificateHolderAuthorization certificateHolderAuthorization; private DERApplicationSpecific certificateHolderReference; private DERApplicationSpecific certificateProfileIdentifier; private int certificateType = 0; private DERApplicationSpecific certificationAuthorityReference; private PublicKeyDataObject publicKey; ASN1InputStream seq; @Override // org.bouncycastle.asn1.ASN1Object, org.bouncycastle.asn1.ASN1Encodable public ASN1Primitive toASN1Primitive() { try { int i = this.certificateType; if (i == 127) { return profileToASN1Object(); } if (i == 13) { return requestToASN1Object(); } return null; } catch (IOException unused) { return null; } } public PublicKeyDataObject getPublicKey() { return this.publicKey; } public CertificationAuthorityReference getCertificationAuthorityReference() throws IOException { if ((this.certificateType & 2) == 2) { return new CertificationAuthorityReference(this.certificationAuthorityReference.getContents()); } throw new IOException("Certification authority reference not set"); } public int getCertificateType() { return this.certificateType; } public DERApplicationSpecific getCertificateProfileIdentifier() { return this.certificateProfileIdentifier; } public CertificateHolderReference getCertificateHolderReference() { return new CertificateHolderReference(this.certificateHolderReference.getContents()); } public CertificateHolderAuthorization getCertificateHolderAuthorization() throws IOException { if ((this.certificateType & 16) == 16) { return this.certificateHolderAuthorization; } throw new IOException("Certificate Holder Authorisation not set"); } public PackedDate getCertificateExpirationDate() throws IOException { if ((this.certificateType & 64) == 64) { return new PackedDate(this.certificateExpirationDate.getContents()); } throw new IOException("certificate Expiration Date not set"); } public PackedDate getCertificateEffectiveDate() { if ((this.certificateType & 32) == 32) { return new PackedDate(this.certificateEffectiveDate.getContents()); } return null; } private void setPublicKey(PublicKeyDataObject publicKeyDataObject) { this.publicKey = PublicKeyDataObject.getInstance(publicKeyDataObject); this.certificateType |= 4; } private void setIso7816CertificateBody(ASN1ApplicationSpecific aSN1ApplicationSpecific) throws IOException { if (aSN1ApplicationSpecific.getApplicationTag() != 78) { throw new IOException("Bad tag : not an iso7816 CERTIFICATE_CONTENT_TEMPLATE"); } ASN1InputStream aSN1InputStream = new ASN1InputStream(aSN1ApplicationSpecific.getContents()); while (true) { ASN1Primitive readObject = aSN1InputStream.readObject(); if (readObject == null) { aSN1InputStream.close(); return; } if (!(readObject instanceof DERApplicationSpecific)) { StringBuilder sb = new StringBuilder("Not a valid iso7816 content : not a DERApplicationSpecific Object :"); sb.append(EACTags.encodeTag(aSN1ApplicationSpecific)); sb.append(readObject.getClass()); throw new IOException(sb.toString()); } DERApplicationSpecific dERApplicationSpecific = (DERApplicationSpecific) readObject; int applicationTag = dERApplicationSpecific.getApplicationTag(); if (applicationTag == 2) { setCertificationAuthorityReference(dERApplicationSpecific); } else if (applicationTag == 32) { setCertificateHolderReference(dERApplicationSpecific); } else if (applicationTag == 41) { setCertificateProfileIdentifier(dERApplicationSpecific); } else if (applicationTag == 73) { setPublicKey(PublicKeyDataObject.getInstance(dERApplicationSpecific.getObject(16))); } else if (applicationTag == 76) { setCertificateHolderAuthorization(new CertificateHolderAuthorization(dERApplicationSpecific)); } else if (applicationTag == 36) { setCertificateExpirationDate(dERApplicationSpecific); } else { if (applicationTag != 37) { this.certificateType = 0; StringBuilder sb2 = new StringBuilder("Not a valid iso7816 DERApplicationSpecific tag "); sb2.append(dERApplicationSpecific.getApplicationTag()); throw new IOException(sb2.toString()); } setCertificateEffectiveDate(dERApplicationSpecific); } } } private void setCertificationAuthorityReference(DERApplicationSpecific dERApplicationSpecific) throws IllegalArgumentException { if (dERApplicationSpecific.getApplicationTag() != 2) { throw new IllegalArgumentException("Not an Iso7816Tags.ISSUER_IDENTIFICATION_NUMBER tag"); } this.certificationAuthorityReference = dERApplicationSpecific; this.certificateType |= 2; } private void setCertificateProfileIdentifier(DERApplicationSpecific dERApplicationSpecific) throws IllegalArgumentException { if (dERApplicationSpecific.getApplicationTag() == 41) { this.certificateProfileIdentifier = dERApplicationSpecific; this.certificateType |= 1; } else { StringBuilder sb = new StringBuilder("Not an Iso7816Tags.INTERCHANGE_PROFILE tag :"); sb.append(EACTags.encodeTag(dERApplicationSpecific)); throw new IllegalArgumentException(sb.toString()); } } private void setCertificateHolderReference(DERApplicationSpecific dERApplicationSpecific) throws IllegalArgumentException { if (dERApplicationSpecific.getApplicationTag() != 32) { throw new IllegalArgumentException("Not an Iso7816Tags.CARDHOLDER_NAME tag"); } this.certificateHolderReference = dERApplicationSpecific; this.certificateType |= 8; } private void setCertificateHolderAuthorization(CertificateHolderAuthorization certificateHolderAuthorization) { this.certificateHolderAuthorization = certificateHolderAuthorization; this.certificateType |= 16; } private void setCertificateExpirationDate(DERApplicationSpecific dERApplicationSpecific) throws IllegalArgumentException { if (dERApplicationSpecific.getApplicationTag() != 36) { throw new IllegalArgumentException("Not an Iso7816Tags.APPLICATION_EXPIRATION_DATE tag"); } this.certificateExpirationDate = dERApplicationSpecific; this.certificateType |= 64; } private void setCertificateEffectiveDate(DERApplicationSpecific dERApplicationSpecific) throws IllegalArgumentException { if (dERApplicationSpecific.getApplicationTag() == 37) { this.certificateEffectiveDate = dERApplicationSpecific; this.certificateType |= 32; } else { StringBuilder sb = new StringBuilder("Not an Iso7816Tags.APPLICATION_EFFECTIVE_DATE tag :"); sb.append(EACTags.encodeTag(dERApplicationSpecific)); throw new IllegalArgumentException(sb.toString()); } } private ASN1Primitive requestToASN1Object() throws IOException { ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector(); aSN1EncodableVector.add(this.certificateProfileIdentifier); aSN1EncodableVector.add(new DERApplicationSpecific(false, 73, (ASN1Encodable) this.publicKey)); aSN1EncodableVector.add(this.certificateHolderReference); return new DERApplicationSpecific(78, aSN1EncodableVector); } private ASN1Primitive profileToASN1Object() throws IOException { ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector(); aSN1EncodableVector.add(this.certificateProfileIdentifier); aSN1EncodableVector.add(this.certificationAuthorityReference); aSN1EncodableVector.add(new DERApplicationSpecific(false, 73, (ASN1Encodable) this.publicKey)); aSN1EncodableVector.add(this.certificateHolderReference); aSN1EncodableVector.add(this.certificateHolderAuthorization); aSN1EncodableVector.add(this.certificateEffectiveDate); aSN1EncodableVector.add(this.certificateExpirationDate); return new DERApplicationSpecific(78, aSN1EncodableVector); } public static CertificateBody getInstance(Object obj) throws IOException { if (obj instanceof CertificateBody) { return (CertificateBody) obj; } if (obj != null) { return new CertificateBody(ASN1ApplicationSpecific.getInstance(obj)); } return null; } public CertificateBody(DERApplicationSpecific dERApplicationSpecific, CertificationAuthorityReference certificationAuthorityReference, PublicKeyDataObject publicKeyDataObject, CertificateHolderReference certificateHolderReference, CertificateHolderAuthorization certificateHolderAuthorization, PackedDate packedDate, PackedDate packedDate2) { setCertificateProfileIdentifier(dERApplicationSpecific); setCertificationAuthorityReference(new DERApplicationSpecific(2, certificationAuthorityReference.getEncoded())); setPublicKey(publicKeyDataObject); setCertificateHolderReference(new DERApplicationSpecific(32, certificateHolderReference.getEncoded())); setCertificateHolderAuthorization(certificateHolderAuthorization); try { setCertificateEffectiveDate(new DERApplicationSpecific(false, 37, (ASN1Encodable) new DEROctetString(packedDate.getEncoding()))); setCertificateExpirationDate(new DERApplicationSpecific(false, 36, (ASN1Encodable) new DEROctetString(packedDate2.getEncoding()))); } catch (IOException e) { StringBuilder sb = new StringBuilder("unable to encode dates: "); sb.append(e.getMessage()); throw new IllegalArgumentException(sb.toString()); } } private CertificateBody(ASN1ApplicationSpecific aSN1ApplicationSpecific) throws IOException { setIso7816CertificateBody(aSN1ApplicationSpecific); } }