List of usage examples for java.security KeyStore getDefaultType
public static final String getDefaultType()
From source file:com.dsna.android.main.MainActivity.java
private KeyStore loadLocalTrustKeystore() { KeyStore localTrustStore;/* w w w . j a va 2 s .c o m*/ try { localTrustStore = KeyStore.getInstance(KeyStore.getDefaultType()); InputStream in = getResources().openRawResource(R.raw.dsnatrustkeystore); try { //System.out.println(FileUtil.readString(in)); localTrustStore.load(in, "kthdsna".toCharArray()); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CertificateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return localTrustStore; } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:android.core.SSLSocketTest.java
/** * Loads a keystore from a base64-encoded String. Returns the KeyManager[] * for the result.// ww w . j a v a 2 s . com */ private KeyManager[] getKeyManagers(String keys) throws Exception { byte[] bytes = new Base64().decode(keys.getBytes()); InputStream inputStream = new ByteArrayInputStream(bytes); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(inputStream, PASSWORD.toCharArray()); inputStream.close(); String algorithm = KeyManagerFactory.getDefaultAlgorithm(); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm); keyManagerFactory.init(keyStore, PASSWORD.toCharArray()); return keyManagerFactory.getKeyManagers(); }
From source file:org.wso2.developerstudio.eclipse.qos.project.ui.dashboard.QoSDashboardPage.java
private void readKeyStore() { try {/*from ww w . ja v a2 s.com*/ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); String filePath = preferenceStore.getString("org.wso2.developerstudio.eclipse.platform.ui", ClientTrustStorePreferencePage.TRUST_STORE_LOCATION, null, null); String password = preferenceStore.getString("org.wso2.developerstudio.eclipse.platform.ui", ClientTrustStorePreferencePage.TRUST_STORE_PASSWORD, null, null); //Fixing TOOLS-2272 - checked filePath and password for null if (filePath != null && password != null) { keyStore.load(new FileInputStream(new File(filePath)), password.toCharArray()); String[] split = filePath.split(File.separator); String alis = null; Enumeration<String> aliases = keyStore.aliases(); while (aliases.hasMoreElements()) { alis = (String) aliases.nextElement(); break; } keyStoreMap.put(split[split.length - 1], alis); } } catch (Exception e) { log.error("Custom Key-store not found", e); } }
From source file:se.leap.bitmaskclient.ProviderAPI.java
private javax.net.ssl.SSLSocketFactory getProviderSSLSocketFactory() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, KeyManagementException { String provider_cert_string = preferences.getString(Provider.CA_CERT, ""); java.security.cert.Certificate provider_certificate = ConfigHelper .parseX509CertificateFromString(provider_cert_string); // Create a KeyStore containing our trusted CAs String keyStoreType = KeyStore.getDefaultType(); KeyStore keyStore = KeyStore.getInstance(keyStoreType); keyStore.load(null, null);//from www . j ava2s. c o m keyStore.setCertificateEntry("provider_ca_certificate", provider_certificate); // Create a TrustManager that trusts the CAs in our KeyStore String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm); tmf.init(keyStore); // Create an SSLContext that uses our TrustManager SSLContext context = SSLContext.getInstance("TLS"); context.init(null, tmf.getTrustManagers(), null); return context.getSocketFactory(); }
From source file:org.cloudifysource.restclient.GSRestClient.java
/** * Returns a HTTP client configured to use SSL. * * @return HTTP client configured to use SSL * @throws RestException//w w w . ja v a 2 s.c om * Reporting different failures while creating the HTTP client */ public final DefaultHttpClient getSSLHttpClient() throws RestException { try { final KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); // TODO : support self-signed certs if configured by user upon // "connect" trustStore.load(null, null); final SSLSocketFactory sf = new RestSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); final HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); final SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme(HTTPS, sf, url.getPort())); final ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (final KeyStoreException e) { throw new RestException(e); } catch (final NoSuchAlgorithmException e) { throw new RestException(e); } catch (final CertificateException e) { throw new RestException(e); } catch (final IOException e) { throw new RestException(e); } catch (final KeyManagementException e) { throw new RestException(e); } catch (final UnrecoverableKeyException e) { throw new RestException(e); } }
From source file:com.verisign.epp.codec.verificationcode.EPPVerificationCodeTst.java
/** * Loads the trust store file into the <code>PKIXParameters</code> used to * verify the certificate chain The Java Trust Store is loaded with the * trusted VSP certificates./*from ww w .j av a 2 s. co m*/ * * @param aTrustStoreName * Trust store file name * * @return Initialized <code>PKIXParameters</code> instance. * * @throws Exception * Error initializing the PKIX parameters */ public static PKIXParameters loadPKIXParameters(String aTrustStoreName) throws Exception { trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream trustStoreFile = new FileInputStream(aTrustStoreName); trustStore.load(trustStoreFile, null); PKIXParameters pkixParameters = new PKIXParameters(trustStore); pkixParameters.setRevocationEnabled(false); // Initialize the verification code validator verificationCodeValidator = new TrustAnchorVerificationCodeValidator(trustStore); return pkixParameters; }
From source file:de.stklcode.jvault.connector.HTTPVaultConnector.java
/** * Create a custom socket factory from trusted CA certificate. * * @return The factory.//from w w w. j av a2 s .c o m * @throws TlsException An error occured during initialization of the SSL context. * @since 0.8.0 */ private SSLConnectionSocketFactory createSSLSocketFactory() throws TlsException { try { // Create Keystore with trusted certificate. KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, null); keyStore.setCertificateEntry("trustedCert", trustedCaCert); // Initialize TrustManager. TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(keyStore); // Create context usint this TrustManager. SSLContext context = SSLContext.getInstance(tlsVersion); context.init(null, tmf.getTrustManagers(), new SecureRandom()); return new SSLConnectionSocketFactory(context, null, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); } catch (CertificateException | NoSuchAlgorithmException | KeyStoreException | IOException | KeyManagementException e) { throw new TlsException(Error.INIT_SSL_CONTEXT, e); } }
From source file:org.apache.juddi.samples.JuddiAdminService.java
void printStatusSingleNode(Transport transport, String authtoken) throws Exception { String replicationUrl = clerkManager.getClientConfig().getUDDINode(curentnode).getReplicationUrl(); SSLContext sc = SSLContext.getInstance("SSLv3"); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(new FileInputStream(System.getProperty("javax.net.ssl.keyStore")), System.getProperty("javax.net.ssl.keyStorePassword").toCharArray()); kmf.init(ks, System.getProperty("javax.net.ssl.keyStorePassword").toCharArray()); sc.init(kmf.getKeyManagers(), null, null); UDDIReplicationPortType uddiReplicationPort = new UDDIService().getUDDIReplicationPort(); ((BindingProvider) uddiReplicationPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, replicationUrl);/*from ww w . j a v a2 s. co m*/ ((BindingProvider) uddiReplicationPort).getRequestContext() .put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", sc.getSocketFactory()); /*((BindingProvider) uddiReplicationPort).getRequestContext() .put( JAXWSProperties.SSL_SOCKET_FACTORY, sc.getSocketFactory());*/ String doPing = uddiReplicationPort.doPing(new DoPing()); System.out.println(doPing + ".., success"); }
From source file:com.mhise.util.MHISEUtil.java
public static KeyStore getServerKeyStore(String url) { KeyStore ks = null;// ww w . j a v a 2s . c o m try { MHISETrustManager.allowAllSSL(); HttpsURLConnection connection = (HttpsURLConnection) (new URL(url)).openConnection(); connection.connect(); Certificate[] certs = connection.getServerCertificates(); ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(null, null); ks.setCertificateEntry("servercert", certs[0]); Log.i("MHISEUtil-->getServerKeyStore", certs[0].getPublicKey().toString()); } catch (Exception e) { Logger.debug("MHISEUtil-->getServerKeyStore", "Exception" + e); e.printStackTrace(); } return ks; }
From source file:io.swagger.client.ApiClient.java
private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException { try {//from w w w. j a v a2 s. com KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, password); return keyStore; } catch (IOException e) { throw new AssertionError(e); } }