package org.bouncycastle.jce.provider; import java.io.IOException; import java.security.AccessController; import java.security.PrivateKey; import java.security.PrivilegedAction; import java.security.Provider; import java.security.PublicKey; import java.util.HashMap; import java.util.Map; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.jcajce.provider.config.ConfigurableProvider; import org.bouncycastle.jcajce.provider.config.ProviderConfiguration; import org.bouncycastle.jcajce.provider.util.AlgorithmProvider; import org.bouncycastle.jcajce.provider.util.AsymmetricKeyInfoConverter; /* loaded from: classes6.dex */ public final class BouncyCastleProvider extends Provider implements ConfigurableProvider { private static final String ASYMMETRIC_PACKAGE = "org.bouncycastle.jcajce.provider.asymmetric."; private static final String DIGEST_PACKAGE = "org.bouncycastle.jcajce.provider.digest."; private static final String KEYSTORE_PACKAGE = "org.bouncycastle.jcajce.provider.keystore."; private static final String SYMMETRIC_PACKAGE = "org.bouncycastle.jcajce.provider.symmetric."; private static String info = "BouncyCastle Security Provider v1.55"; public static final ProviderConfiguration CONFIGURATION = new BouncyCastleProviderConfiguration(); private static final Map keyInfoConverters = new HashMap(); private static final String[] SYMMETRIC_GENERIC = {"PBEPBKDF2", "PBEPKCS12", "TLSKDF"}; private static final String[] SYMMETRIC_MACS = {"SipHash"}; private static final String[] SYMMETRIC_CIPHERS = {"AES", "ARC4", "Blowfish", "Camellia", "CAST5", "CAST6", "ChaCha", "DES", "DESede", "GOST28147", "Grainv1", "Grain128", "HC128", "HC256", "IDEA", "Noekeon", "RC2", "RC5", "RC6", "Rijndael", "Salsa20", "SEED", "Serpent", "Shacal2", "Skipjack", "SM4", "TEA", "Twofish", "Threefish", "VMPC", "VMPCKSA3", "XTEA", "XSalsa20", "OpenSSLPBKDF"}; private static final String[] ASYMMETRIC_GENERIC = {"X509", "IES"}; private static final String[] ASYMMETRIC_CIPHERS = {"DSA", "DH", "EC", "RSA", "GOST", "ECGOST", "ElGamal", "DSTU4145"}; private static final String[] DIGESTS = {"GOST3411", "Keccak", "MD2", "MD4", "MD5", "SHA1", "RIPEMD128", "RIPEMD160", "RIPEMD256", "RIPEMD320", "SHA224", "SHA256", "SHA384", "SHA512", "SHA3", "Skein", "SM3", "Tiger", "Whirlpool", "Blake2b"}; public static final String PROVIDER_NAME = "BC"; private static final String[] KEYSTORES = {PROVIDER_NAME, "PKCS12"}; @Override // org.bouncycastle.jcajce.provider.config.ConfigurableProvider public final void setParameter(String str, Object obj) { ProviderConfiguration providerConfiguration = CONFIGURATION; synchronized (providerConfiguration) { ((BouncyCastleProviderConfiguration) providerConfiguration).setParameter(str, obj); } } @Override // org.bouncycastle.jcajce.provider.config.ConfigurableProvider public final boolean hasAlgorithm(String str, String str2) { StringBuilder sb = new StringBuilder(); sb.append(str); sb.append("."); sb.append(str2); if (!containsKey(sb.toString())) { StringBuilder sb2 = new StringBuilder("Alg.Alias."); sb2.append(str); sb2.append("."); sb2.append(str2); if (!containsKey(sb2.toString())) { return false; } } return true; } @Override // org.bouncycastle.jcajce.provider.config.ConfigurableProvider public final void addKeyInfoConverter(ASN1ObjectIdentifier aSN1ObjectIdentifier, AsymmetricKeyInfoConverter asymmetricKeyInfoConverter) { Map map = keyInfoConverters; synchronized (map) { map.put(aSN1ObjectIdentifier, asymmetricKeyInfoConverter); } } @Override // org.bouncycastle.jcajce.provider.config.ConfigurableProvider public final void addAlgorithm(String str, ASN1ObjectIdentifier aSN1ObjectIdentifier, String str2) { StringBuilder sb = new StringBuilder(); sb.append(str); sb.append("."); sb.append(aSN1ObjectIdentifier); addAlgorithm(sb.toString(), str2); StringBuilder sb2 = new StringBuilder(); sb2.append(str); sb2.append(".OID."); sb2.append(aSN1ObjectIdentifier); addAlgorithm(sb2.toString(), str2); } @Override // org.bouncycastle.jcajce.provider.config.ConfigurableProvider public final void addAlgorithm(String str, String str2) { if (!containsKey(str)) { put(str, str2); return; } StringBuilder sb = new StringBuilder("duplicate provider key ("); sb.append(str); sb.append(") found"); throw new IllegalStateException(sb.toString()); } /* JADX INFO: Access modifiers changed from: private */ public void setup() { loadAlgorithms(DIGEST_PACKAGE, DIGESTS); loadAlgorithms(SYMMETRIC_PACKAGE, SYMMETRIC_GENERIC); loadAlgorithms(SYMMETRIC_PACKAGE, SYMMETRIC_MACS); loadAlgorithms(SYMMETRIC_PACKAGE, SYMMETRIC_CIPHERS); loadAlgorithms(ASYMMETRIC_PACKAGE, ASYMMETRIC_GENERIC); loadAlgorithms(ASYMMETRIC_PACKAGE, ASYMMETRIC_CIPHERS); loadAlgorithms(KEYSTORE_PACKAGE, KEYSTORES); put("X509Store.CERTIFICATE/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCertCollection"); put("X509Store.ATTRIBUTECERTIFICATE/COLLECTION", "org.bouncycastle.jce.provider.X509StoreAttrCertCollection"); put("X509Store.CRL/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCRLCollection"); put("X509Store.CERTIFICATEPAIR/COLLECTION", "org.bouncycastle.jce.provider.X509StoreCertPairCollection"); put("X509Store.CERTIFICATE/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCerts"); put("X509Store.CRL/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCRLs"); put("X509Store.ATTRIBUTECERTIFICATE/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPAttrCerts"); put("X509Store.CERTIFICATEPAIR/LDAP", "org.bouncycastle.jce.provider.X509StoreLDAPCertPairs"); put("X509StreamParser.CERTIFICATE", "org.bouncycastle.jce.provider.X509CertParser"); put("X509StreamParser.ATTRIBUTECERTIFICATE", "org.bouncycastle.jce.provider.X509AttrCertParser"); put("X509StreamParser.CRL", "org.bouncycastle.jce.provider.X509CRLParser"); put("X509StreamParser.CERTIFICATEPAIR", "org.bouncycastle.jce.provider.X509CertPairParser"); put("Cipher.BROKENPBEWITHMD5ANDDES", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$BrokePBEWithMD5AndDES"); put("Cipher.BROKENPBEWITHSHA1ANDDES", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$BrokePBEWithSHA1AndDES"); put("Cipher.OLDPBEWITHSHAANDTWOFISH-CBC", "org.bouncycastle.jce.provider.BrokenJCEBlockCipher$OldPBEWithSHAAndTwofish"); put("CertPathValidator.RFC3281", "org.bouncycastle.jce.provider.PKIXAttrCertPathValidatorSpi"); put("CertPathBuilder.RFC3281", "org.bouncycastle.jce.provider.PKIXAttrCertPathBuilderSpi"); put("CertPathValidator.RFC3280", "org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi"); put("CertPathBuilder.RFC3280", "org.bouncycastle.jce.provider.PKIXCertPathBuilderSpi"); put("CertPathValidator.PKIX", "org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi"); put("CertPathBuilder.PKIX", "org.bouncycastle.jce.provider.PKIXCertPathBuilderSpi"); put("CertStore.Collection", "org.bouncycastle.jce.provider.CertStoreCollectionSpi"); put("CertStore.LDAP", "org.bouncycastle.jce.provider.X509LDAPCertStoreSpi"); put("CertStore.Multi", "org.bouncycastle.jce.provider.MultiCertStoreSpi"); put("Alg.Alias.CertStore.X509LDAP", "LDAP"); } private void loadAlgorithms(String str, String[] strArr) { Class cls; for (int i = 0; i != strArr.length; i++) { try { ClassLoader classLoader = getClass().getClassLoader(); if (classLoader != null) { StringBuilder sb = new StringBuilder(); sb.append(str); sb.append(strArr[i]); sb.append("$Mappings"); cls = classLoader.loadClass(sb.toString()); } else { StringBuilder sb2 = new StringBuilder(); sb2.append(str); sb2.append(strArr[i]); sb2.append("$Mappings"); cls = Class.forName(sb2.toString()); } } catch (ClassNotFoundException unused) { cls = null; } if (cls != null) { try { ((AlgorithmProvider) cls.newInstance()).configure(this); } catch (Exception e) { StringBuilder sb3 = new StringBuilder("cannot create instance of "); sb3.append(str); sb3.append(strArr[i]); sb3.append("$Mappings : "); sb3.append(e); throw new InternalError(sb3.toString()); } } } } public static PublicKey getPublicKey(SubjectPublicKeyInfo subjectPublicKeyInfo) throws IOException { AsymmetricKeyInfoConverter asymmetricKeyInfoConverter = getAsymmetricKeyInfoConverter(subjectPublicKeyInfo.getAlgorithm().getAlgorithm()); if (asymmetricKeyInfoConverter == null) { return null; } return asymmetricKeyInfoConverter.generatePublic(subjectPublicKeyInfo); } public static PrivateKey getPrivateKey(PrivateKeyInfo privateKeyInfo) throws IOException { AsymmetricKeyInfoConverter asymmetricKeyInfoConverter = getAsymmetricKeyInfoConverter(privateKeyInfo.getPrivateKeyAlgorithm().getAlgorithm()); if (asymmetricKeyInfoConverter == null) { return null; } return asymmetricKeyInfoConverter.generatePrivate(privateKeyInfo); } private static AsymmetricKeyInfoConverter getAsymmetricKeyInfoConverter(ASN1ObjectIdentifier aSN1ObjectIdentifier) { AsymmetricKeyInfoConverter asymmetricKeyInfoConverter; Map map = keyInfoConverters; synchronized (map) { asymmetricKeyInfoConverter = (AsymmetricKeyInfoConverter) map.get(aSN1ObjectIdentifier); } return asymmetricKeyInfoConverter; } public BouncyCastleProvider() { super(PROVIDER_NAME, 1.55d, info); AccessController.doPrivileged(new PrivilegedAction(this) { // from class: org.bouncycastle.jce.provider.BouncyCastleProvider.1 final BouncyCastleProvider this$0; @Override // java.security.PrivilegedAction public Object run() { this.this$0.setup(); return null; } { this.this$0 = this; } }); } }