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);
}
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);
}
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);
}
}
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);
}
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();
}
Aggregations