Search in sources :

Example 41 with Provider

use of java.security.Provider in project OpenAM by OpenRock.

the class Client method initializeJSSE.

/**
     * Initializes JSSE enviroment.
     *
     * @throws Exception if an error occurs while initializing JSSE
     */
private static void initializeJSSE() throws Exception {
    // put SunJSSE at fisrt place, so that JSSE will work
    Provider provider = Security.getProvider("SunJSSE");
    if (provider != null) {
        Security.removeProvider("SunJSSE");
        Security.insertProviderAt(provider, 1);
    }
    String algorithm = SystemPropertiesManager.get(SOAP_TRUST_SECMNGR_ALGO_PROP);
    if (algorithm == null || algorithm.length() <= 0) {
        algorithm = "SunX509";
    }
    JKSKeyProvider jkskp = createKeyProvider();
    KeyStore trustStore = jkskp.getKeyStore();
    KeyManagerFactory kf = KeyManagerFactory.getInstance(algorithm);
    kf.init(trustStore, jkskp.getPrivateKeyPass().toCharArray());
    kms = kf.getKeyManagers();
    defaultX509km = (X509KeyManager) kms[0];
    defineTrustManager(trustStore, algorithm);
}
Also used : JKSKeyProvider(com.sun.identity.saml.xmlsig.JKSKeyProvider) KeyStore(java.security.KeyStore) JKSKeyProvider(com.sun.identity.saml.xmlsig.JKSKeyProvider) Provider(java.security.Provider) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 42 with Provider

use of java.security.Provider in project android_frameworks_base by ResurrectionRemix.

the class ZygoteInit method warmUpJcaProviders.

/**
     * Register AndroidKeyStoreProvider and warm up the providers that are already registered.
     *
     * By doing it here we avoid that each app does it when requesting a service from the
     * provider for the first time.
     */
private static void warmUpJcaProviders() {
    long startTime = SystemClock.uptimeMillis();
    Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "Starting installation of AndroidKeyStoreProvider");
    // AndroidKeyStoreProvider.install() manipulates the list of JCA providers to insert
    // preferred providers. Note this is not done via security.properties as the JCA providers
    // are not on the classpath in the case of, for example, raw dalvikvm runtimes.
    AndroidKeyStoreProvider.install();
    Log.i(TAG, "Installed AndroidKeyStoreProvider in " + (SystemClock.uptimeMillis() - startTime) + "ms.");
    Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
    startTime = SystemClock.uptimeMillis();
    Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
    for (Provider p : Security.getProviders()) {
        p.warmUpServiceProvision();
    }
    Log.i(TAG, "Warmed up JCA providers in " + (SystemClock.uptimeMillis() - startTime) + "ms.");
    Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
Also used : AndroidKeyStoreProvider(android.security.keystore.AndroidKeyStoreProvider) Provider(java.security.Provider)

Example 43 with Provider

use of java.security.Provider in project android_frameworks_base by ResurrectionRemix.

the class AndroidKeyStoreProvider method install.

/**
     * Installs a new instance of this provider (and the
     * {@link AndroidKeyStoreBCWorkaroundProvider}).
     */
public static void install() {
    Provider[] providers = Security.getProviders();
    int bcProviderIndex = -1;
    for (int i = 0; i < providers.length; i++) {
        Provider provider = providers[i];
        if ("BC".equals(provider.getName())) {
            bcProviderIndex = i;
            break;
        }
    }
    Security.addProvider(new AndroidKeyStoreProvider());
    Provider workaroundProvider = new AndroidKeyStoreBCWorkaroundProvider();
    if (bcProviderIndex != -1) {
        // Bouncy Castle provider found -- install the workaround provider above it.
        // insertProviderAt uses 1-based positions.
        Security.insertProviderAt(workaroundProvider, bcProviderIndex + 1);
    } else {
        // Bouncy Castle provider not found -- install the workaround provider at lowest
        // priority.
        Security.addProvider(workaroundProvider);
    }
}
Also used : Provider(java.security.Provider)

Example 44 with Provider

use of java.security.Provider in project android_frameworks_base by ResurrectionRemix.

the class XmlConfigTests method testTrustManagerKeystore.

public void testTrustManagerKeystore() throws Exception {
    XmlConfigSource source = new XmlConfigSource(getContext(), R.xml.bad_pin, true);
    ApplicationConfig appConfig = new ApplicationConfig(source);
    Provider provider = new NetworkSecurityConfigProvider();
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX", provider);
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    keystore.load(null);
    int i = 0;
    for (X509Certificate cert : SystemCertificateSource.getInstance().getCertificates()) {
        keystore.setEntry(String.valueOf(i), new KeyStore.TrustedCertificateEntry(cert), null);
        i++;
    }
    tmf.init(keystore);
    TrustManager[] tms = tmf.getTrustManagers();
    SSLContext context = SSLContext.getInstance("TLS");
    context.init(null, tms, null);
    TestUtils.assertConnectionSucceeds(context, "android.com", 443);
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) Provider(java.security.Provider) TrustManager(javax.net.ssl.TrustManager)

Example 45 with Provider

use of java.security.Provider in project midpoint by Evolveum.

the class CryptoUtil method securitySelfTest.

public static void securitySelfTest(OperationResult parentTestResult) {
    OperationResult result = parentTestResult.createSubresult(CryptoUtil.class.getName() + ".securitySelfTest");
    // Providers
    for (Provider provider : Security.getProviders()) {
        String providerName = provider.getName();
        OperationResult providerResult = result.createSubresult(CryptoUtil.class.getName() + ".securitySelfTest.provider." + providerName);
        try {
            providerResult.addContext("info", provider.getInfo());
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            provider.storeToXML(os, "Crypto provider " + providerName);
            String propXml = os.toString();
            providerResult.addContext("properties", propXml);
            providerResult.recordSuccess();
        } catch (Throwable e) {
            LOGGER.error("Security self test (provider properties) failed: ", e.getMessage(), e);
            providerResult.recordFatalError(e);
        }
    }
    securitySelfTestAlgorithm("AES", "AES/CBC/PKCS5Padding", null, false, result);
    OperationResult cryptoResult = result.getLastSubresult();
    if (cryptoResult.isError()) {
        // Do a test encryption. It happens sometimes that the key generator
        // generates a key that is not supported by the cipher.
        // Fall back to known key size supported by all JCE implementations
        securitySelfTestAlgorithm("AES", "AES/CBC/PKCS5Padding", 128, true, result);
        OperationResult cryptoResult2 = result.getLastSubresult();
        if (cryptoResult2.isSuccess()) {
            cryptoResult.setStatus(OperationResultStatus.HANDLED_ERROR);
        }
    }
    result.computeStatus();
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Provider(java.security.Provider)

Aggregations

Provider (java.security.Provider)243 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)49 ArrayList (java.util.ArrayList)26 MessageDigest (java.security.MessageDigest)21 List (java.util.List)20 Key (java.security.Key)19 KeyStore (java.security.KeyStore)19 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 SecureRandom (java.security.SecureRandom)13 IOException (java.io.IOException)12 NoSuchProviderException (java.security.NoSuchProviderException)12 SecretKey (javax.crypto.SecretKey)12 KeyStoreException (java.security.KeyStoreException)11 CertificateException (java.security.cert.CertificateException)11 Cipher (javax.crypto.Cipher)11 KeyGenerator (javax.crypto.KeyGenerator)11 MyExemptionMechanismSpi.tmpKey (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey)11