use of java.security.Provider in project jdk8u_jdk by JetBrains.
the class PBESealedObject method main.
public static void main(String[] args) {
PBESealedObject test = new PBESealedObject();
Provider sunjce = Security.getProvider("SunJCE");
if (!test.runAll(sunjce, System.out)) {
throw new RuntimeException("One or more tests have failed....");
}
}
use of java.security.Provider in project jdk8u_jdk by JetBrains.
the class TestCipherKeyWrapperTest method main.
public static void main(String[] args) throws Exception {
TestCipherKeyWrapperTest test = new TestCipherKeyWrapperTest();
// AESWrap and DESedeWrap test
for (AlgorithmWrapper algoWrapper : AlgorithmWrapper.values()) {
String algo = algoWrapper.getAlgorithm();
String wrapper = algoWrapper.getWrapper();
try {
int keySize = algoWrapper.getKeySize();
// version of JCE jurisdiction policy files are installed
if (!(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE) && keySize > LINIMITED_KEYSIZE) {
out.println(algo + " will not run if unlimited version of" + " JCE jurisdiction policy files are installed");
continue;
}
test.wrapperAesDESedeKeyTest(algo, wrapper, keySize);
if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
throw new RuntimeException("Expected not throw when algo" + " and wrapAlgo are not match:" + algo);
}
} catch (InvalidKeyException e) {
if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
out.println("Expepted exception when algo" + " and wrapAlgo are not match:" + algo);
} else {
throw e;
}
}
}
test.wrapperBlowfishKeyTest();
// PBE and public wrapper test.
String[] publicPrivateAlgos = new String[] { "DiffieHellman", "DSA", "RSA" };
Provider provider = Security.getProvider(SUN_JCE);
if (provider == null) {
throw new RuntimeException("SUN_JCE provider not exist");
}
test.wrapperPBEKeyTest(provider);
// Public and private key wrap test
test.wrapperPublicPriviteKeyTest(provider, publicPrivateAlgos);
}
use of java.security.Provider in project jdk8u_jdk by JetBrains.
the class TestPRF method main.
public static void main(String[] args) throws Exception {
Provider provider = Security.getProvider("SunJCE");
InputStream in = new FileInputStream(new File(BASE, "prfdata.txt"));
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
int n = 0;
int lineNumber = 0;
byte[] secret = null;
String label = null;
byte[] seed = null;
int length = 0;
byte[] output = null;
while (true) {
String line = reader.readLine();
lineNumber++;
if (line == null) {
break;
}
if (line.startsWith("prf-") == false) {
continue;
}
String data = line.substring(PREFIX_LENGTH);
if (line.startsWith("prf-secret:")) {
secret = parse(data);
} else if (line.startsWith("prf-label:")) {
label = data;
} else if (line.startsWith("prf-seed:")) {
seed = parse(data);
} else if (line.startsWith("prf-length:")) {
length = Integer.parseInt(data);
} else if (line.startsWith("prf-output:")) {
output = parse(data);
System.out.print(".");
n++;
KeyGenerator kg = KeyGenerator.getInstance("SunTlsPrf", provider);
SecretKey inKey;
if (secret == null) {
inKey = null;
} else {
inKey = new SecretKeySpec(secret, "Generic");
}
TlsPrfParameterSpec spec = new TlsPrfParameterSpec(inKey, label, seed, length, null, -1, -1);
kg.init(spec);
SecretKey key = kg.generateKey();
byte[] enc = key.getEncoded();
if (Arrays.equals(output, enc) == false) {
throw new Exception("mismatch line: " + lineNumber);
}
} else {
throw new Exception("Unknown line: " + line);
}
}
if (n == 0) {
throw new Exception("no tests");
}
in.close();
System.out.println();
System.out.println("OK: " + n + " tests");
}
use of java.security.Provider in project android_frameworks_base by AOSPA.
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 AOSPA.
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);
}
}
Aggregations