use of java.security.Provider in project nhin-d by DirectProject.
the class AbstractPKCS11TokenKeyStoreProtectionManager method loadProvider.
protected void loadProvider() throws CryptoException {
try {
if (!StringUtils.isEmpty(this.keyStoreProviderName)) {
if (this.keyStoreProviderName.equals(SUNPKCS11_KEYSTORE_PROVIDER_NAME)) {
// this provider requires a config file
if (StringUtils.isEmpty(this.pcks11ConfigFile))
throw new IllegalStateException("SunPKCS11 providers require a configuration file. There is not one set.");
// check and see if this is one of the same providers that is already loaded
final InputStream inStream = FileUtils.openInputStream(new File(this.pcks11ConfigFile));
final Properties props = new Properties();
props.load(inStream);
IOUtils.closeQuietly(inStream);
boolean providerFound = false;
final String requestedName = props.getProperty("name");
// check if this provider exists
if (!StringUtils.isEmpty(requestedName) && Security.getProvider(requestedName) != null)
providerFound = true;
if (!providerFound) {
// dynamic load... some class loaders may have issues, so use dynamic loading
final Class<?> provider = this.getClass().getClassLoader().loadClass("sun.security.pkcs11.SunPKCS11");
final Constructor<?> ctor = provider.getConstructor(String.class);
Security.addProvider((Provider) ctor.newInstance(this.pcks11ConfigFile));
}
} else {
// create the new provider
final Class<?> provider = this.getClass().getClassLoader().loadClass(this.keyStoreProviderName);
// check if the provider is already loaded
boolean providerFound = false;
for (Provider existingProv : Security.getProviders()) {
if (existingProv.getClass().equals(provider)) {
providerFound = true;
break;
}
}
if (!providerFound)
Security.addProvider((Provider) provider.newInstance());
}
}
} catch (Exception e) {
throw new CryptoException("Error loading PKCS11 provder", e);
}
}
use of java.security.Provider in project jdk8u_jdk by JetBrains.
the class TestPremaster method main.
public static void main(String[] args) throws Exception {
Provider provider = Security.getProvider("SunJCE");
KeyGenerator kg;
kg = KeyGenerator.getInstance("SunTlsRsaPremasterSecret", provider);
try {
kg.generateKey();
throw new Exception("no exception");
} catch (IllegalStateException e) {
System.out.println("OK: " + e);
}
int[] protocolVersions = { 0x0300, 0x0301, 0x0302, 0x0400 };
for (int clientVersion : protocolVersions) {
for (int serverVersion : protocolVersions) {
test(kg, clientVersion, serverVersion);
if (serverVersion >= clientVersion) {
break;
}
}
}
System.out.println("Done.");
}
use of java.security.Provider in project jdk8u_jdk by JetBrains.
the class AccessKeyStore method main.
public static void main(String[] args) throws Exception {
// Check that a security manager has been installed
if (System.getSecurityManager() == null) {
throw new Exception("A security manager has not been installed");
}
Provider p = Security.getProvider("SunMSCAPI");
System.out.println("SunMSCAPI provider classname is " + p.getClass().getName());
KeyStore keyStore = KeyStore.getInstance("Windows-MY", p);
/*
* If a SecurityManager exists then this will trigger a
* SecurityException if the following permission has not
* been granted:
*
* SecurityPermission("authProvider.SunMSCAPI")
*/
try {
keyStore.load(null, null);
if (args.length > 0 && "-deny".equals(args[0])) {
throw new Exception("Expected KeyStore.load to throw a SecurityException");
}
} catch (SecurityException se) {
if (args.length > 0 && "-deny".equals(args[0])) {
System.out.println("Caught the expected exception: " + se);
return;
} else {
throw se;
}
}
int i = 0;
for (Enumeration<String> e = keyStore.aliases(); e.hasMoreElements(); ) {
String alias = e.nextElement();
displayEntry(keyStore, alias, i++);
}
}
use of java.security.Provider in project jdk8u_jdk by JetBrains.
the class GetInstance method main.
public static void main(String[] argv) throws Exception {
Provider stubProvider = new StubProvider();
CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX", stubProvider);
System.out.println("Test passed.");
}
use of java.security.Provider in project jdk8u_jdk by JetBrains.
the class TestJSSE method server.
public static void server(String testProtocol, String testCipher, int testPort, String... exception) throws Exception {
String expectedException = exception.length >= 1 ? exception[0] : null;
out.println(" This is Server");
out.println(" Testing Protocol: " + testProtocol);
out.println(" Testing Cipher: " + testCipher);
out.println(" Testing Port: " + testPort);
Provider p = new sun.security.ec.SunEC();
Security.insertProviderAt(p, 1);
try {
CipherTestUtils.main(new JSSEFactory(null, testPort, testProtocol, testCipher, "Server JSSE"), "Server", expectedException);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations