package org.jmrtd.cert; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.InvalidKeyException; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.Provider; import java.security.PublicKey; import java.security.Security; import java.security.SignatureException; import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.interfaces.RSAPublicKey; import java.security.spec.RSAPublicKeySpec; import java.util.Date; import java.util.logging.Logger; import net.sf.scuba.data.Country; import o.AbstractC15291gmf; import o.C15288gmc; import o.C15290gme; import o.glH; import o.glK; import o.glL; import o.glP; import o.glQ; import o.glS; import o.glW; import o.glZ; import org.ejbca.cvc.AuthorizationRoleEnum; import org.ejbca.cvc.CVCertificate; import org.ejbca.cvc.exception.ConstructionException; import org.jmrtd.cert.CVCAuthorizationTemplate; /* loaded from: classes6.dex */ public class CardVerifiableCertificate extends Certificate { private static final Logger LOGGER = Logger.getLogger("org.jmrtd"); private static final long serialVersionUID = -3585440601605666288L; private CVCertificate cvCertificate; private transient KeyFactory rsaKeyFactory; /* JADX INFO: Access modifiers changed from: protected */ public CardVerifiableCertificate(CVCertificate cVCertificate) { super("CVC"); try { this.rsaKeyFactory = KeyFactory.getInstance("RSA"); } catch (NoSuchAlgorithmException e) { Logger logger = LOGGER; StringBuilder sb = new StringBuilder("Exception: "); sb.append(e.getMessage()); logger.severe(sb.toString()); } this.cvCertificate = cVCertificate; } public CardVerifiableCertificate(CVCPrincipal cVCPrincipal, CVCPrincipal cVCPrincipal2, PublicKey publicKey, String str, Date date, Date date2, CVCAuthorizationTemplate.Role role, CVCAuthorizationTemplate.Permission permission, byte[] bArr) { super("CVC"); try { glL gll = new glL(cVCPrincipal.getCountry().toAlpha2Code(), cVCPrincipal.getMnemonic(), cVCPrincipal.getSeqNumber()); glW glw = new glW(cVCPrincipal2.getCountry().toAlpha2Code(), cVCPrincipal2.getMnemonic(), cVCPrincipal2.getSeqNumber()); AuthorizationRoleEnum fromRole = CVCAuthorizationTemplate.fromRole(role); CVCertificate cVCertificate = new CVCertificate(new glQ(gll, C15290gme.e(publicKey, str, fromRole), glw, fromRole, CVCAuthorizationTemplate.fromPermission(permission), date, date2)); this.cvCertificate = cVCertificate; cVCertificate.c(new glK(glS.SIGNATURE, bArr)); this.cvCertificate.f(); } catch (ConstructionException e) { throw new IllegalArgumentException(e.getMessage()); } } @Override // java.security.cert.Certificate public byte[] getEncoded() throws CertificateEncodingException { try { return this.cvCertificate.d(); } catch (IOException e) { throw new CertificateEncodingException(e.getMessage()); } } @Override // java.security.cert.Certificate public String toString() { return this.cvCertificate.toString(); } @Override // java.security.cert.Certificate public void verify(PublicKey publicKey) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { for (Provider provider : Security.getProviders()) { try { this.cvCertificate.a(publicKey, provider.getName()); return; } catch (NoSuchAlgorithmException unused) { } } throw new NoSuchAlgorithmException("Tried all security providers: None was able to provide this signature algorithm."); } @Override // java.security.cert.Certificate public void verify(PublicKey publicKey, String str) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { this.cvCertificate.a(publicKey, str); } @Override // java.security.cert.Certificate public boolean equals(Object obj) { if (obj == null) { return false; } if (this == obj) { return true; } if (getClass().equals(obj.getClass())) { return this.cvCertificate.equals(((CardVerifiableCertificate) obj).cvCertificate); } return false; } @Override // java.security.cert.Certificate public int hashCode() { return (this.cvCertificate.hashCode() << 1) - 1030507011; } public CVCPrincipal getAuthorityReference() throws CertificateException { try { glQ glq = (glQ) this.cvCertificate.e(glS.CERTIFICATE_BODY); glL gll = (glL) glq.b.get(glS.CA_REFERENCE); return new CVCPrincipal(Country.getInstance(((AbstractC15291gmf) gll).c.toUpperCase()), gll.b, gll.e); } catch (NoSuchFieldException e) { throw new CertificateException(e.getMessage()); } } public CVCAuthorizationTemplate getAuthorizationTemplate() throws CertificateException { try { return new CVCAuthorizationTemplate((org.ejbca.cvc.CVCAuthorizationTemplate) ((glQ) this.cvCertificate.e(glS.CERTIFICATE_BODY)).e(glS.HOLDER_AUTH_TEMPLATE)); } catch (NoSuchFieldException e) { throw new CertificateException(e.getMessage()); } } public byte[] getCertBodyData() throws CertificateException, IOException { try { return ((glQ) this.cvCertificate.e(glS.CERTIFICATE_BODY)).d(); } catch (NoSuchFieldException e) { throw new CertificateException(e.getMessage()); } } public CVCPrincipal getHolderReference() throws CertificateException { try { glW glw = (glW) ((glQ) this.cvCertificate.e(glS.CERTIFICATE_BODY)).e(glS.HOLDER_REFERENCE); return new CVCPrincipal(Country.getInstance(((AbstractC15291gmf) glw).c.toUpperCase()), glw.b, glw.e); } catch (NoSuchFieldException e) { throw new CertificateException(e.getMessage()); } } public Date getNotAfter() throws CertificateException { try { return ((glZ) ((glQ) this.cvCertificate.e(glS.CERTIFICATE_BODY)).e(glS.EXPIRATION_DATE)).e; } catch (NoSuchFieldException e) { throw new CertificateException(e.getMessage()); } } public Date getNotBefore() throws CertificateException { try { return ((glZ) ((glQ) this.cvCertificate.e(glS.CERTIFICATE_BODY)).e(glS.EFFECTIVE_DATE)).e; } catch (NoSuchFieldException e) { throw new CertificateException(e.getMessage()); } } /* JADX WARN: Multi-variable type inference failed */ @Override // java.security.cert.Certificate public PublicKey getPublicKey() { try { glP glp = (glP) ((glQ) this.cvCertificate.e(glS.CERTIFICATE_BODY)).e(glS.PUBLIC_KEY); if (glp.getAlgorithm().equals("RSA")) { RSAPublicKey rSAPublicKey = (RSAPublicKey) glp; try { return this.rsaKeyFactory.generatePublic(new RSAPublicKeySpec(rSAPublicKey.getModulus(), rSAPublicKey.getPublicExponent())); } catch (GeneralSecurityException e) { Logger logger = LOGGER; StringBuilder sb = new StringBuilder("Exception: "); sb.append(e.getMessage()); logger.severe(sb.toString()); } } return glp; } catch (NoSuchFieldException e2) { Logger logger2 = LOGGER; StringBuilder sb2 = new StringBuilder("Exception: "); sb2.append(e2.getMessage()); logger2.severe(sb2.toString()); return null; } } public String getSigAlgName() { try { return glH.c((C15288gmc) ((glP) ((glQ) this.cvCertificate.e(glS.CERTIFICATE_BODY)).e(glS.PUBLIC_KEY)).e(glS.OID)); } catch (NoSuchFieldException unused) { return null; } } public String getSigAlgOID() { try { return ((C15288gmc) ((glP) ((glQ) this.cvCertificate.e(glS.CERTIFICATE_BODY)).e(glS.PUBLIC_KEY)).e(glS.OID)).a("", true); } catch (NoSuchFieldException unused) { return null; } } public byte[] getSignature() throws CertificateException { try { return ((glK) this.cvCertificate.e(glS.SIGNATURE)).d; } catch (NoSuchFieldException e) { throw new CertificateException(e.getMessage()); } } }