Search in sources :

Example 31 with Service

use of java.security.Provider.Service in project Bytecoder by mirkosertic.

the class GetInstance method getInstance.

public static Instance getInstance(String type, Class<?> clazz, String algorithm, Object param) throws NoSuchAlgorithmException {
    List<Service> services = getServices(type, algorithm);
    NoSuchAlgorithmException failure = null;
    for (Service s : services) {
        try {
            return getInstance(s, clazz, param);
        } catch (NoSuchAlgorithmException e) {
            failure = e;
        }
    }
    if (failure != null) {
        throw failure;
    } else {
        throw new NoSuchAlgorithmException(algorithm + " " + type + " not available");
    }
}
Also used : Service(java.security.Provider.Service)

Example 32 with Service

use of java.security.Provider.Service in project certmgr by hdecarne.

the class KeyPairAlgorithm method getDefaultSet.

/**
 * Get the available key pair algorithms.
 *
 * @param defaultHint The default to return (may be {@code null}). If this algorithm is contained in the default
 *        set, it is also set as the default.
 * @param expertMode Whether only standard algorithms are considered ({@code false}) or all algorithms available on
 *        the current platform ({@code true}).
 * @return The available key pair algorithms
 */
public static DefaultSet<KeyPairAlgorithm> getDefaultSet(@Nullable String defaultHint, boolean expertMode) {
    DefaultSet<KeyPairAlgorithm> keyPairAlgorithms = new DefaultSet<>();
    DefaultSet<String> defaultNames = SecurityDefaults.getKeyAlgorithmNames();
    @Nullable String defaultName = (defaultHint != null && defaultNames.contains(defaultHint) ? defaultHint : defaultNames.getDefault());
    for (Provider provider : SecurityDefaults.getProviders(expertMode)) {
        for (Provider.Service service : provider.getServices()) {
            if (!SERVICE_TYPE_KEY_PAIR_GENERATOR.equals(service.getType())) {
                continue;
            }
            String algorithm = service.getAlgorithm();
            if (!expertMode && !defaultNames.contains(algorithm)) {
                continue;
            }
            KeyPairAlgorithm keyPairAlgorithm = (expertMode ? new ExpertKeyPairAlgorithm(service) : new StandardKeyPairAlgorithm(service));
            if (algorithm.equals(defaultName)) {
                keyPairAlgorithms.addDefault(keyPairAlgorithm);
            } else {
                keyPairAlgorithms.add(keyPairAlgorithm);
            }
        }
    }
    return keyPairAlgorithms;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) Service(java.security.Provider.Service) Nullable(de.carne.check.Nullable) Provider(java.security.Provider)

Example 33 with Service

use of java.security.Provider.Service in project certmgr by hdecarne.

the class PlatformKeyStore method getDefaultSet.

/**
 * Get the available platform key stores.
 *
 * @return The available platform key stores.
 */
public static DefaultSet<PlatformKeyStore> getDefaultSet() {
    DefaultSet<PlatformKeyStore> platformKeyStores = new DefaultSet<>();
    DefaultSet<String> defaultNames = SecurityDefaults.getPlatformKeyStoreNames();
    String defaultName = defaultNames.getDefault();
    for (Provider provider : Security.getProviders()) {
        for (Provider.Service service : provider.getServices()) {
            if (!SERVICE_TYPE_KEY_STORE.equals(service.getType())) {
                continue;
            }
            String algorithm = service.getAlgorithm();
            if (!defaultNames.contains(algorithm)) {
                continue;
            }
            PlatformKeyStore platformKeyStore = new PlatformKeyStore(service);
            if (algorithm.equals(defaultName)) {
                platformKeyStores.addDefault(platformKeyStore);
            } else {
                platformKeyStores.add(platformKeyStore);
            }
        }
    }
    return platformKeyStores;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) Service(java.security.Provider.Service) Provider(java.security.Provider)

Example 34 with Service

use of java.security.Provider.Service 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 35 with Service

use of java.security.Provider.Service in project j2objc by google.

the class KeyFactory method nextSpi.

/**
 * Update the active KeyFactorySpi of this class and return the next
 * implementation for failover. If no more implemenations are
 * available, this method returns null. However, the active spi of
 * this class is never set to null.
 */
private KeyFactorySpi nextSpi(KeyFactorySpi oldSpi) {
    synchronized (lock) {
        // try that spi now
        if ((oldSpi != null) && (oldSpi != spi)) {
            return spi;
        }
        if (serviceIterator == null) {
            return null;
        }
        while (serviceIterator.hasNext()) {
            Service s = serviceIterator.next();
            try {
                Object obj = s.newInstance(null);
                if (obj instanceof KeyFactorySpi == false) {
                    continue;
                }
                KeyFactorySpi spi = (KeyFactorySpi) obj;
                provider = s.getProvider();
                this.spi = spi;
                return spi;
            } catch (NoSuchAlgorithmException e) {
            // ignore
            }
        }
        serviceIterator = null;
        return null;
    }
}
Also used : Service(java.security.Provider.Service)

Aggregations

Service (java.security.Provider.Service)80 Provider (java.security.Provider)17 Instance (sun.security.jca.GetInstance.Instance)11 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)9 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 DefaultSet (de.carne.jfx.util.DefaultSet)3 Nullable (de.carne.check.Nullable)2 KeyPairGenerator (java.security.KeyPairGenerator)2 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)2 DSAPublicKey (java.security.interfaces.DSAPublicKey)2 LinkedList (java.util.LinkedList)2 CoreException (org.eclipse.core.runtime.CoreException)2 KeyFactory (java.security.KeyFactory)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 DSAParams (java.security.interfaces.DSAParams)1 ECPrivateKey (java.security.interfaces.ECPrivateKey)1 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1