List of usage examples for java.security KeyStore getProvider
public final Provider getProvider()
From source file:com.newrelic.agent.transport.DataSenderImpl.java
public static KeyStore getKeyStore() /* 183: */ throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException /* 184: */ {//from w ww.j a v a2s. c om /* 185:187 */ KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); /* 186: */ /* 187:189 */ InputStream in = DataSenderImpl.class.getResourceAsStream("/nrcerts"); /* 188:190 */ if (null == in) { /* 189:191 */ Agent.LOG.fine("Unable to find NR trust store"); /* 190: */ } else { /* 191: */ try /* 192: */ { /* 193:194 */ keystore.load(in, null); /* 194: */ } /* 195: */ finally /* 196: */ { /* 197:196 */ in.close(); /* 198: */ } /* 199: */ } /* 200:200 */ Agent.LOG.finer("SSL Keystore Provider: " + keystore.getProvider().getName()); /* 201: */ /* 202:202 */ return keystore; /* 203: */ }
From source file:net.timewalker.ffmq4.listeners.tcp.io.TcpListener.java
private SSLContext createSSLContext() throws JMSException { try {/*from w w w.j av a 2 s. c o m*/ String sslProtocol = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_PROTOCOL, "SSLv3"); String keyManagerAlgorithm = settings .getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYMANAGER_ALGORITHM, "SunX509"); String keyStoreType = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYSTORE_TYPE, "JKS"); String keyStorePath = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYSTORE_PATH, "../conf/server-keystore.jks"); String keyStorePass = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYSTORE_PASWORD, "ffmqpass"); String keyPass = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYSTORE_KEY_PASSWORD, "ffmqpass"); SSLContext sslContext = SSLContext.getInstance(sslProtocol); log.debug("Created an SSL context : protocol=[" + sslContext.getProtocol() + "] provider=[" + sslContext.getProvider() + "]"); // Load available keys KeyManager[] keyManagers; File keyStoreFile = new File(keyStorePath); if (!keyStoreFile.canRead()) throw new FFMQException("Cannot read keystore file : " + keyStoreFile.getAbsolutePath(), "FS_ERROR"); KeyStore ks = KeyStore.getInstance(keyStoreType); log.debug("Created keystore : type=[" + ks.getType() + "] provider=[" + ks.getProvider() + "]"); char ksPass[] = keyStorePass.toCharArray(); char ctPass[] = keyPass.toCharArray(); log.debug("Loading keystore from " + keyStoreFile.getAbsolutePath()); InputStream kis = new FileInputStream(keyStoreFile); ks.load(kis, ksPass); kis.close(); KeyManagerFactory kmf = KeyManagerFactory.getInstance(keyManagerAlgorithm); log.debug("Created KeyManagerFactory : algorithm=[" + kmf.getAlgorithm() + "] provider=[" + kmf.getProvider() + "]"); log.debug("Initializing KeyManagerFactory with keystore ..."); kmf.init(ks, ctPass); keyManagers = kmf.getKeyManagers(); sslContext.init(keyManagers, null, null); return sslContext; } catch (JMSException e) { throw e; } catch (Exception e) { throw new FFMQException("Cannot create SSL context", "NETWORK_ERROR", e); } }
From source file:org.apache.ws.security.components.crypto.CryptoBase.java
protected static String createKeyStoreErrorMessage(KeyStore keystore) throws KeyStoreException { Enumeration aliases = keystore.aliases(); StringBuffer sb = new StringBuffer(keystore.size() * 7); boolean firstAlias = true; while (aliases.hasMoreElements()) { if (!firstAlias) { sb.append(", "); }//from www .j a va 2 s. co m sb.append(aliases.nextElement()); firstAlias = false; } String msg = " in keystore of type [" + keystore.getType() + "] from provider [" + keystore.getProvider() + "] with size [" + keystore.size() + "] and aliases: {" + sb.toString() + "}"; return msg; }
From source file:org.apache.ws.security.components.crypto.Merlin.java
private static String createKeyStoreErrorMessage(KeyStore keystore) throws KeyStoreException { Enumeration<String> aliases = keystore.aliases(); StringBuilder sb = new StringBuilder(keystore.size() * 7); boolean firstAlias = true; while (aliases.hasMoreElements()) { if (!firstAlias) { sb.append(", "); }// w ww. j a v a2s .co m sb.append(aliases.nextElement()); firstAlias = false; } String msg = " in keystore of type [" + keystore.getType() + "] from provider [" + keystore.getProvider() + "] with size [" + keystore.size() + "] and aliases: {" + sb.toString() + "}"; return msg; }
From source file:org.signserver.server.cryptotokens.PKCS11CryptoToken.java
@Override public Collection<KeyTestResult> testKey(String alias, char[] authCode) throws CryptoTokenOfflineException, KeyStoreException { final KeyStore keyStore = delegate.getActivatedKeyStore(); return CryptoTokenHelper.testKey(keyStore, alias, authCode, keyStore.getProvider().getName()); }
From source file:org.wisdom.engine.ssl.SSLServerContext.java
private KeyManagerFactory getKeyManagerFactoryFromKeyStore(final File maybeRoot, final String path) throws KeyStoreException { KeyManagerFactory kmf;// ww w . j a v a2s. com File file = new File(path); if (!file.isFile()) { // Second chance. file = new File(maybeRoot, path); } LOGGER.info("\t key store: " + file.getAbsolutePath()); final KeyStore keyStore = KeyStore .getInstance(accessor.getConfiguration().getWithDefault("https.keyStoreType", "JKS")); LOGGER.info("\t key store type: " + keyStore.getType()); LOGGER.info("\t key store provider: " + keyStore.getProvider()); final char[] password = accessor.getConfiguration().getWithDefault("https.keyStorePassword", "") .toCharArray(); LOGGER.info("\t key store password length: " + password.length); final String algorithm = accessor.getConfiguration().getWithDefault("https.keyStoreAlgorithm", KeyManagerFactory.getDefaultAlgorithm()); LOGGER.info("\t key store algorithm: " + algorithm); if (file.isFile()) { FileInputStream stream = null; try { stream = new FileInputStream(file); keyStore.load(stream, password); kmf = KeyManagerFactory.getInstance(algorithm); kmf.init(keyStore, password); } catch (final Exception e) { throw new RuntimeException(HTTPSFAIL + e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } } else { throw new RuntimeException( "Cannot load key store from '" + file.getAbsolutePath() + "', " + "the file does not exist"); } return kmf; }
From source file:org.wisdom.engine.ssl.SSLServerContext.java
private TrustManagerFactory getTrustManagerFactoryFromKeyStore(final File maybeRoot, final String path) throws KeyStoreException { final TrustManagerFactory tmf; File file = new File(path); if (!file.isFile()) { // Second chance. file = new File(maybeRoot, path); }//from ww w . j a v a 2s .co m LOGGER.info("\t trust store: " + file.getAbsolutePath()); final KeyStore trustStore = KeyStore .getInstance(accessor.getConfiguration().getWithDefault("https.trustStoreType", "JKS")); LOGGER.info("\t trust store type: " + trustStore.getType()); LOGGER.info("\t trust store provider: " + trustStore.getProvider()); final char[] password = accessor.getConfiguration().getWithDefault("https.trustStorePassword", "") .toCharArray(); LOGGER.info("\t trust store password length: " + password.length); final String algorithm = accessor.getConfiguration().getWithDefault("https.trustStoreAlgorithm", KeyManagerFactory.getDefaultAlgorithm()); LOGGER.info("\t trust store algorithm: " + algorithm); if (file.isFile()) { FileInputStream stream = null; try { stream = new FileInputStream(file); trustStore.load(stream, password); tmf = TrustManagerFactory.getInstance(algorithm); tmf.init(trustStore); } catch (final Exception e) { throw new RuntimeException(HTTPSFAIL + e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } } else { throw new RuntimeException( "Cannot load trust store from '" + file.getAbsolutePath() + "', " + "the file does not exist"); } return tmf; }
From source file:org.wso2.carbon.webapp.ext.cxf.crypto.CXFServerCrypto.java
private String createKeyStoreErrorMessage(KeyStore keystore) throws KeyStoreException { Enumeration<String> aliases = keystore.aliases(); StringBuilder sb = new StringBuilder(keystore.size() * 7); boolean firstAlias = true; while (aliases.hasMoreElements()) { if (!firstAlias) { sb.append(", "); }/*from ww w . ja va 2 s .com*/ sb.append(aliases.nextElement()); firstAlias = false; } String msg = " in keystore of type [" + keystore.getType() + "] from provider [" + keystore.getProvider() + "] with size [" + keystore.size() + "] and aliases: {" + sb.toString() + "}"; return msg; }
From source file:test.unit.be.fedict.eid.applet.service.AppletServiceServletTest.java
private void persistKey(File pkcs12keyStore, PrivateKey privateKey, X509Certificate certificate, char[] keyStorePassword, char[] keyEntryPassword) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, NoSuchProviderException { KeyStore keyStore = KeyStore.getInstance("pkcs12", BouncyCastleProvider.PROVIDER_NAME); keyStore.load(null, keyStorePassword); LOG.debug("keystore security provider: " + keyStore.getProvider().getName()); keyStore.setKeyEntry("default", privateKey, keyEntryPassword, new Certificate[] { certificate }); FileOutputStream keyStoreOut = new FileOutputStream(pkcs12keyStore); keyStore.store(keyStoreOut, keyStorePassword); keyStoreOut.close();/*from w w w . j ava 2 s. c om*/ }