use of java.security.Provider in project robovm by robovm.
the class myCertPathBuilder method testCertPathBuilder08.
/**
* Test for <code>getInstance(String algorithm, Provider provider)</code> method
* Assertion: throws IllegalArgumentException when provider is null
*/
public void testCertPathBuilder08() throws NoSuchAlgorithmException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
Provider prov = null;
for (int t = 0; t < validValues.length; t++) {
try {
CertPathBuilder.getInstance(validValues[t], prov);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e1) {
}
}
}
use of java.security.Provider in project robovm by robovm.
the class ProviderTest method test_Provider_Properties.
/**
* Makes sure all provider properties either point to a class
* implementation that exists or are aliases to known algorithms.
*/
public void test_Provider_Properties() throws Exception {
/*
* A useful reference on Provider properties
* <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/crypto/HowToImplAProvider.html>
* How to Implement a Provider in the Java ™ Cryptography Architecture
* </a>
*/
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
// check Provider.id proprieties
assertEquals(provider.getName(), provider.get("Provider.id name"));
assertEquals(String.valueOf(provider.getVersion()), provider.get("Provider.id version"));
assertEquals(provider.getInfo(), provider.get("Provider.id info"));
assertEquals(provider.getClass().getName(), provider.get("Provider.id className"));
// build map of all known aliases and implementations
Map<String, String> aliases = new HashMap<String, String>();
Map<String, String> implementations = new HashMap<String, String>();
for (Entry<Object, Object> entry : provider.entrySet()) {
Object k = entry.getKey();
Object v = entry.getValue();
assertEquals(String.class, k.getClass());
assertEquals(String.class, v.getClass());
String key = (String) k;
String value = (String) v;
// skip Provider.id keys, we check well known ones values above
if (key.startsWith("Provider.id ")) {
continue;
}
// skip property settings such as: "Signature.SHA1withDSA ImplementedIn" "Software"
if (key.indexOf(' ') != -1) {
continue;
}
Matcher m = alias.matcher(key);
if (m.find()) {
String type = m.group(1);
aliases.put(key, type + "." + value);
} else {
implementations.put(key, value);
}
}
// verify implementation classes are available
for (Entry<String, String> entry : implementations.entrySet()) {
String typeAndAlgorithm = entry.getKey();
String className = entry.getValue();
try {
assertNotNull(Class.forName(className, true, provider.getClass().getClassLoader()));
} catch (ClassNotFoundException e) {
// Sun forgot their own class
if (!className.equals("sun.security.pkcs11.P11MAC")) {
fail("Could not find class " + className + " for " + typeAndAlgorithm);
}
}
}
// make sure all aliases point to some known implementation
for (Entry<String, String> entry : aliases.entrySet()) {
String alias = entry.getKey();
String actual = entry.getValue();
assertTrue("Could not find implementation " + actual + " for alias " + alias, implementations.containsKey(actual));
}
}
}
use of java.security.Provider in project robovm by robovm.
the class SecureRandomTest method test_getInstance.
public void test_getInstance() throws Exception {
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
Set<Provider.Service> services = provider.getServices();
for (Provider.Service service : services) {
String type = service.getType();
if (!type.equals("SecureRandom")) {
continue;
}
String algorithm = service.getAlgorithm();
try {
SecureRandom sr1 = SecureRandom.getInstance(algorithm);
assertEquals(algorithm, sr1.getAlgorithm());
test_SecureRandom(sr1);
// SecureRandom.getInstance(String, Provider)
SecureRandom sr2 = SecureRandom.getInstance(algorithm, provider);
assertEquals(algorithm, sr2.getAlgorithm());
assertEquals(provider, sr2.getProvider());
test_SecureRandom(sr2);
// SecureRandom.getInstance(String, String)
SecureRandom sr3 = SecureRandom.getInstance(algorithm, provider.getName());
assertEquals(algorithm, sr3.getAlgorithm());
assertEquals(provider, sr3.getProvider());
test_SecureRandom(sr3);
System.out.println("SecureRandomTest " + algorithm + " and provider " + provider.getName());
} catch (Exception e) {
throw new Exception("Problem testing SecureRandom." + algorithm + ", provider: " + provider.getName(), e);
}
}
}
}
use of java.security.Provider in project robovm by robovm.
the class KeyStoreTest method test_KeyStore_create.
public void test_KeyStore_create() throws Exception {
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
Set<Provider.Service> services = provider.getServices();
for (Provider.Service service : services) {
String type = service.getType();
if (!type.equals("KeyStore")) {
continue;
}
String algorithm = service.getAlgorithm();
KeyStore ks = KeyStore.getInstance(algorithm, provider);
assertEquals(provider, ks.getProvider());
assertEquals(algorithm, ks.getType());
}
}
}
use of java.security.Provider in project robovm by robovm.
the class KeyStoreTest method keyStores.
public static List<KeyStore> keyStores() throws Exception {
List<KeyStore> keyStores = new ArrayList<KeyStore>();
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
Set<Provider.Service> services = provider.getServices();
for (Provider.Service service : services) {
String type = service.getType();
if (!type.equals("KeyStore")) {
continue;
}
String algorithm = service.getAlgorithm();
KeyStore ks = KeyStore.getInstance(algorithm, provider);
assertEquals(provider, ks.getProvider());
assertEquals(algorithm, ks.getType());
if (!isUnsupported(ks)) {
keyStores.add(ks);
}
}
}
return keyStores;
}
Aggregations