Refine search
/** * @see SSLContexts#createDefault() */ public static final SSLContext getPreferredSSLContext(final SecureRandom secureRandom) { try { final SSLContext sslcontext = SSLContext.getInstance("TLS"); // http://download.java.net/jdk9/docs/technotes/guides/security/jsse/JSSERefGuide.html sslcontext.init(null, null, secureRandom); return sslcontext; } catch (final NoSuchAlgorithmException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } catch (final KeyManagementException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } } }
/** * Removes the specified {@code Certificate} from this {@code Identity}. * * @param certificate * the {@code Certificate} to be removed. * @throws KeyManagementException * if the certificate is not found. */ public void removeCertificate(Certificate certificate) throws KeyManagementException { if (certificates != null) { if (!certificates.contains(certificate)) { throw new KeyManagementException("Certificate not found"); } certificates.removeElement(certificate); } }
private void initHttps(HttpURLConnection httpURLConnection) { if (httpURLConnection instanceof HttpsURLConnection) { // 设置SSLContext SSLContext sslcontext = null; try { sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[]{myX509TrustManager}, null); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(sslcontext.getSocketFactory()); } }
SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new SecureRandom()); SSLSocketFactory factory = sc.getSocketFactory(); socket = factory.createSocket(host, port); } catch (NoSuchAlgorithmException ex) { throw new IOException(ex.toString()); } catch (KeyManagementException ex) { throw new IOException(ex.toString());
SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustManagers, null); SSLContext.setDefault(sslContext); return sslContext; } catch (CertificateException e) { throw new AiravataSecurityException("Error in initializing the trust store."); } catch (NoSuchAlgorithmException e) { logger.error(e.getMessage(), e); throw new AiravataSecurityException("Error in initializing the trust store."); } catch (KeyStoreException e) { logger.error(e.getMessage(), e); throw new AiravataSecurityException("Error in initializing the trust store."); } catch (KeyManagementException e) { logger.error(e.getMessage(), e); throw new AiravataSecurityException("Error in initializing the trust store."); } catch (FileNotFoundException e) {
private SSLContext createSslContext(OptionMap options) { try { SSLContext context = SSLContext.getInstance("TLSv1.2"); KeyManager[] keyManagers = null; TrustManager[] trustManagers = null; context.init(keyManagers, trustManagers, null); return context; } catch (UnrecoverableKeyException e) { throw new MisconfigurationException("core.KEY_STORE", e.getMessage(), e); } catch (KeyManagementException e) { throw new MisconfigurationException("core.KEY_MANAGEMENT", e.getMessage(), e);
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException { try { return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort); } catch (NoSuchAlgorithmException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyManagementException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyStoreException e) { throw new IOException(e + " " + e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e + " " + e.getMessage()); } }
protected DefaultHttpClient getHttpsClient() { try { SSLContext sslContext = SSLUtils.getSSLContext(); X509TrustManager tm = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] {tm}, new SecureRandom()); SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", nmsUrl.getPort(), socketFactory)); BasicClientConnectionManager mgr = new BasicClientConnectionManager(registry); return new DefaultHttpClient(mgr); } catch (NoSuchAlgorithmException ex) { throw new CloudRuntimeException(ex.getMessage()); } catch (KeyManagementException ex) { throw new CloudRuntimeException(ex.getMessage()); } }
public boolean calls() { boolean isRet = false; //https try { this.callHttps(); isRet = true; } catch (UnrecoverableKeyException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (KeyManagementException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (CertificateException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (KeyStoreException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (NoSuchAlgorithmException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (IOException e) { _log.error("", e); this.errInfo = e.getMessage(); } catch (Exception e) { _log.error("", e); this.errInfo = e.getMessage(); } return isRet; }
private static SSLContext getSSLContext() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); TrustStrategy allTrust = new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }; return org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(trustStore, allTrust).build(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
@Override public void run() { try { mServer.idCardOcr(mFaceBitmap, nCurrentCartType); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } }).start();
/** * Disable SSL and hostname verification for given HTTP connection * * @param conn * a {@link org.eclipse.jgit.transport.http.HttpConnection} * object. * @throws java.io.IOException * @since 4.3 */ public static void disableSslVerify(HttpConnection conn) throws IOException { final TrustManager[] trustAllCerts = new TrustManager[] { new DummyX509TrustManager() }; try { conn.configure(null, trustAllCerts, null); conn.setHostnameVerifier(new DummyHostnameVerifier()); } catch (KeyManagementException e) { throw new IOException(e.getMessage()); } catch (NoSuchAlgorithmException e) { throw new IOException(e.getMessage()); } }
@Override public void addCertificate(X509Certificate certificate) throws KeyManagementException { keystore.addTrustedSslCertificate(certificate, certificate.getSubjectX500Principal().getName()); try { keystore.save(); } catch(KeyStoreException e) { throw new KeyManagementException("Cannot add certificate to keystore: "+e.toString(), e); } catch(IOException e) { throw new KeyManagementException("Cannot add certificate to keystore: "+e.toString(), e); } catch(NoSuchAlgorithmException e) { throw new KeyManagementException("Cannot add certificate to keystore: "+e.toString(), e); } catch(CertificateException e) { throw new KeyManagementException("Cannot add certificate to keystore: "+e.toString(), e); } hashCode = null; // signal to recalculate the hashcode due to changed contents } /*
private void testRabbitMQConnection() { Connection connection; factory.setHost(hostname); factory.setPort(port); factory.setVirtualHost(virtualHost); factory.setUsername(username); factory.setPassword(password); if (enableSSL) { try { factory.useSslProtocol(); } catch (NoSuchAlgorithmException ex) { throw new IllegalArgumentException("Could not Enable SSL: " + ex.toString()); } catch (KeyManagementException ex) { throw new IllegalArgumentException("Could not Enable SSL: " + ex.toString()); } } try { connection = factory.newConnection(); connection.close(); } catch (IOException ex) { throw new IllegalArgumentException("Could not connect to RabbitMQ: " + ex.toString()); } }
private HttpClient getHttpClient() { HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties(); if (this.ignoreSsl) { try { SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContextBuilder.build(), NoopHostnameVerifier.INSTANCE); builder.setSSLSocketFactory(sslsf); } catch (NoSuchAlgorithmException e) { logger.log(Level.SEVERE, "Failing to setup the SSLConnectionFactory: " + e.toString()); throw new RuntimeException(e); } catch (KeyStoreException e) { logger.log(Level.SEVERE, "Failing to setup the SSLConnectionFactory: " + e.toString()); throw new RuntimeException(e); } catch (KeyManagementException e) { logger.log(Level.SEVERE, "Failing to setup the SSLConnectionFactory: " + e.toString()); throw new RuntimeException(e); } } return builder.build(); }
/** * <p>Prints this exception's stack trace to <code>System.err</code>. If this * exception has a <i>root</i> exception; the stack trace of the <i>root</i> * exception is also printed to <code>System.err</code>.</p> */ public void printStackTrace() { super.printStackTrace(); if (cause != null) { cause.printStackTrace(); } }
/** * <p>Returns the string representation of this exception. The string * representation contains this exception's class name, its detailed * messsage, and if it has a <i>root</i> exception, the string representation * of the root exception. This string representation is meant for debugging * and is not meant to be interpreted programmatically.</p> * * @return the non-null string representation of this exception. * @see Throwable#getMessage() */ public String toString() { StringBuffer sb = new StringBuffer(this.getClass().getName()) .append(": ").append(super.toString()); if (cause != null) { sb.append("; caused by: ").append(cause.toString()); } return sb.toString(); } }
public DummySSLSocketFactory() { try { SSLContext sslcontent = SSLContext.getInstance("TLS"); sslcontent.init(null, new TrustManager[]{new DummyTrustManager()}, new java.security.SecureRandom()); factory = sslcontent.getSocketFactory(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(System.out); } catch (KeyManagementException e) { e.printStackTrace(System.out); } }
private SSLContext createSslContext(OptionMap options) { try { SSLContext context = SSLContext.getInstance("TLSv1.2"); KeyManager[] keyManagers = null; TrustManager[] trustManagers = null; context.init(keyManagers, trustManagers, null); return context; } catch (UnrecoverableKeyException e) { throw new MisconfigurationException("core.KEY_STORE", e.getMessage(), e); } catch (KeyManagementException e) { throw new MisconfigurationException("core.KEY_MANAGEMENT", e.getMessage(), e);
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort, HttpConnectionParams params) throws IOException { try { return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort); } catch (NoSuchAlgorithmException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyManagementException e) { throw new IOException(e + " " + e.getMessage()); } catch (KeyStoreException e) { throw new IOException(e + " " + e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e + " " + e.getMessage()); } }