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