Search in sources :

Example 1 with Provider

use of java.security.Provider in project camel by apache.

the class ApnsUtils method getAlgorithm.

public static String getAlgorithm() {
    List<String> keys = new LinkedList<String>();
    List<String> trusts = new LinkedList<String>();
    for (Provider p : Security.getProviders()) {
        for (Service s : p.getServices()) {
            if ("KeyManagerFactory".equals(s.getType()) && s.getAlgorithm().endsWith("509")) {
                keys.add(s.getAlgorithm());
            } else if ("TrustManagerFactory".equals(s.getType()) && s.getAlgorithm().endsWith("509")) {
                trusts.add(s.getAlgorithm());
            }
        }
    }
    keys.retainAll(trusts);
    return keys.get(0);
}
Also used : Service(java.security.Provider.Service) LinkedList(java.util.LinkedList) Provider(java.security.Provider)

Example 2 with Provider

use of java.security.Provider in project actor-platform by actorapp.

the class PRNGFixes method installLinuxPRNGSecureRandom.

/**
     * Installs a Linux PRNG-backed {@code SecureRandom} implementation as the
     * default. Does nothing if the implementation is already the default or if
     * there is not need to install the implementation.
     *
     * @throws SecurityException if the fix is needed but could not be applied.
     */
private static void installLinuxPRNGSecureRandom() throws SecurityException {
    if (Build.VERSION.SDK_INT > VERSION_CODE_JELLY_BEAN_MR2) {
        // No need to apply the fix
        return;
    }
    // Install a Linux PRNG-based SecureRandom implementation as the
    // default, if not yet installed.
    Provider[] secureRandomProviders = Security.getProviders("SecureRandom.SHA1PRNG");
    if ((secureRandomProviders == null) || (secureRandomProviders.length < 1) || (!LinuxPRNGSecureRandomProvider.class.equals(secureRandomProviders[0].getClass()))) {
        Security.insertProviderAt(new LinuxPRNGSecureRandomProvider(), 1);
    }
    // Assert that new SecureRandom() and
    // SecureRandom.getInstance("SHA1PRNG") return a SecureRandom backed
    // by the Linux PRNG-based SecureRandom implementation.
    SecureRandom rng1 = new SecureRandom();
    if (!LinuxPRNGSecureRandomProvider.class.equals(rng1.getProvider().getClass())) {
        throw new SecurityException("new SecureRandom() backed by wrong Provider: " + rng1.getProvider().getClass());
    }
    SecureRandom rng2;
    try {
        rng2 = SecureRandom.getInstance("SHA1PRNG");
    } catch (NoSuchAlgorithmException e) {
        throw new SecurityException("SHA1PRNG not available", e);
    }
    if (!LinuxPRNGSecureRandomProvider.class.equals(rng2.getProvider().getClass())) {
        throw new SecurityException("SecureRandom.getInstance(\"SHA1PRNG\") backed by wrong" + " Provider: " + rng2.getProvider().getClass());
    }
}
Also used : SecureRandom(java.security.SecureRandom) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Provider(java.security.Provider)

Example 3 with Provider

use of java.security.Provider in project Android-Terminal-Emulator by jackpal.

the class PRNGFixes method installLinuxPRNGSecureRandom.

/**
     * Installs a Linux PRNG-backed {@code SecureRandom} implementation as the
     * default. Does nothing if the implementation is already the default or if
     * there is not need to install the implementation.
     *
     * @throws SecurityException if the fix is needed but could not be applied.
     */
private static void installLinuxPRNGSecureRandom() throws SecurityException {
    if (AndroidCompat.SDK > VERSION_CODE_JELLY_BEAN_MR2) {
        // No need to apply the fix
        return;
    }
    // Install a Linux PRNG-based SecureRandom implementation as the
    // default, if not yet installed.
    Provider[] secureRandomProviders = Security.getProviders("SecureRandom.SHA1PRNG");
    if ((secureRandomProviders == null) || (secureRandomProviders.length < 1) || (!LinuxPRNGSecureRandomProvider.class.equals(secureRandomProviders[0].getClass()))) {
        Security.insertProviderAt(new LinuxPRNGSecureRandomProvider(), 1);
    }
    // Assert that new SecureRandom() and
    // SecureRandom.getInstance("SHA1PRNG") return a SecureRandom backed
    // by the Linux PRNG-based SecureRandom implementation.
    SecureRandom rng1 = new SecureRandom();
    if (!LinuxPRNGSecureRandomProvider.class.equals(rng1.getProvider().getClass())) {
        throw new SecurityException("new SecureRandom() backed by wrong Provider: " + rng1.getProvider().getClass());
    }
    SecureRandom rng2;
    try {
        rng2 = SecureRandom.getInstance("SHA1PRNG");
    } catch (NoSuchAlgorithmException e) {
        throw new SecurityException("SHA1PRNG not available", e);
    }
    if (!LinuxPRNGSecureRandomProvider.class.equals(rng2.getProvider().getClass())) {
        throw new SecurityException("SecureRandom.getInstance(\"SHA1PRNG\") backed by wrong" + " Provider: " + rng2.getProvider().getClass());
    }
}
Also used : SecureRandom(java.security.SecureRandom) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Provider(java.security.Provider)

Example 4 with Provider

use of java.security.Provider in project android-pbe by nelenkov.

the class Crypto method listAlgorithms.

public static void listAlgorithms(String algFilter) {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String providerStr = String.format("%s/%s/%f\n", p.getName(), p.getInfo(), p.getVersion());
        Log.d(TAG, providerStr);
        Set<Service> services = p.getServices();
        List<String> algs = new ArrayList<String>();
        for (Service s : services) {
            boolean match = true;
            if (algFilter != null) {
                match = s.getAlgorithm().toLowerCase().contains(algFilter.toLowerCase());
            }
            if (match) {
                String algStr = String.format("\t%s/%s/%s", s.getType(), s.getAlgorithm(), s.getClassName());
                algs.add(algStr);
            }
        }
        Collections.sort(algs);
        for (String alg : algs) {
            Log.d(TAG, "\t" + alg);
        }
        Log.d(TAG, "");
    }
}
Also used : ArrayList(java.util.ArrayList) Service(java.security.Provider.Service) Provider(java.security.Provider)

Example 5 with Provider

use of java.security.Provider in project robovm by robovm.

the class X509CertificateObject method getSigAlgName.

/**
     * return a more "meaningful" representation for the signature algorithm used in
     * the certficate.
     */
public String getSigAlgName() {
    Provider prov = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME);
    if (prov != null) {
        String algName = prov.getProperty("Alg.Alias.Signature." + this.getSigAlgOID());
        if (algName != null) {
            return algName;
        }
    }
    Provider[] provs = Security.getProviders();
    //
    for (int i = 0; i != provs.length; i++) {
        String algName = provs[i].getProperty("Alg.Alias.Signature." + this.getSigAlgOID());
        if (algName != null) {
            return algName;
        }
    }
    return this.getSigAlgOID();
}
Also used : DERBitString(org.bouncycastle.asn1.DERBitString) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) ASN1String(org.bouncycastle.asn1.ASN1String) Provider(java.security.Provider) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Aggregations

Provider (java.security.Provider)229 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)49 ArrayList (java.util.ArrayList)25 MessageDigest (java.security.MessageDigest)21 KeyStore (java.security.KeyStore)19 List (java.util.List)18 Service (java.security.Provider.Service)15 ExemptionMechanism (javax.crypto.ExemptionMechanism)14 SpiEngUtils (org.apache.harmony.security.tests.support.SpiEngUtils)14 InvalidKeyException (java.security.InvalidKeyException)13 IOException (java.io.IOException)12 Key (java.security.Key)12 NoSuchProviderException (java.security.NoSuchProviderException)12 SecureRandom (java.security.SecureRandom)12 SecretKey (javax.crypto.SecretKey)12 KeyStoreException (java.security.KeyStoreException)11 Cipher (javax.crypto.Cipher)11 KeyGenerator (javax.crypto.KeyGenerator)11 MyExemptionMechanismSpi.tmpKey (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey)11 CertificateException (java.security.cert.CertificateException)10