Java Examples for javax.net.ssl.SSLContext
The following java examples will help you to understand the usage of javax.net.ssl.SSLContext. These source code samples are taken from different open source projects.
Example 1
| Project: javardices-master File: HttpSslContext.java View source code |
public javax.net.ssl.SSLContext getSSLContext() throws Exception { KeyStore keyStore = KeyStore.getInstance("JKS"); char[] KEYSTOREPW = keyStorePasswordStr.toCharArray(); char[] KEYPW = keyPasswordStr.toCharArray(); keyStore.load(new FileInputStream(keyStoreLocation), KEYSTOREPW); javax.net.ssl.KeyManagerFactory kmf = javax.net.ssl.KeyManagerFactory.getInstance("SunX509"); kmf.init(keyStore, KEYPW); //javax.net.ssl.SSLContext sslContext = javax.net.ssl.SSLContext.getInstance("SSLv3"); javax.net.ssl.SSLContext sslContext = javax.net.ssl.SSLContext.getInstance("TLS"); sslContext.init(kmf.getKeyManagers(), null, null); return sslContext; }
Example 2
| Project: find-sec-bugs-master File: WeakTLSProtocol.java View source code |
public static void main(String[] args) {
// BAD
HttpClient client1 = new DefaultHttpClient();
// OK
HttpClient client2 = new SystemDefaultHttpClient();
try {
// BAD
SSLContext context1 = SSLContext.getInstance("SSL");
// OK
SSLContext context2 = SSLContext.getInstance("TLS");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}Example 3
| Project: infinispan-master File: SniConfiguration.java View source code |
private static SslContext createContext(SSLContext sslContext, ClientAuth clientAuth) {
//Unfortunately we need to grap a list of available ciphers from the engine.
//If we won't, JdkSslContext will use common ciphers from DEFAULT and SUPPORTED, which gives us 5 out of ~50 available ciphers
//Of course, we don't need to any specific engine configuration here... just a list of ciphers
String[] ciphers = sslContext.createSSLEngine().getSupportedCipherSuites();
return new JdkSslContext(sslContext, false, Arrays.asList(ciphers), IdentityCipherSuiteFilter.INSTANCE, null, clientAuth);
}Example 4
| Project: tisana4j-master File: RestClientBuilderTest.java View source code |
@Test
public void testBuilder() throws Exception {
RestClient newClient = new RestClientBuilder().withUsername("pippo").withPassword("pasticcio").withSkipValidation(true).withHeaders(new HashMap<String, String>()).withCtx(SSLContext.getInstance("SSL")).withConnectionTimeout(2, TimeUnit.MINUTES).withSocketTimeout(1, TimeUnit.MINUTES).withProxyHostname("proxy.upstream").build();
assertNotNull(newClient);
}Example 5
| Project: flashback-master File: SSLContextGenerator.java View source code |
/** * Create client side SSLContext {@link javax.net.ssl.SSLContext} * * */ public static SSLContext createClientContext(KeyStore keyStore, char[] passphrase) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { String keyManAlg = KeyManagerFactory.getDefaultAlgorithm(); KeyManagerFactory kmf = KeyManagerFactory.getInstance(keyManAlg); kmf.init(keyStore, passphrase); KeyManager[] keyManagers = kmf.getKeyManagers(); return create(keyManagers, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), RandomNumberGenerator.getInstance().getSecureRandom()); }
Example 6
| Project: aws-toolkit-eclipse-master File: CertificateUtils.java View source code |
public static void disableCertValidation() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
}
}Example 7
| Project: email-master File: TestTrustedSocketFactory.java View source code |
@Override
public Socket createSocket(Socket socket, String host, int port, String clientCertificateAlias) throws NoSuchAlgorithmException, KeyManagementException, MessagingException, IOException {
TrustManager[] trustManagers = new TrustManager[] { new VeryTrustingTrustManager() };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
return sslSocketFactory.createSocket(socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true);
}Example 8
| Project: k-9-master File: TestTrustedSocketFactory.java View source code |
@Override
public Socket createSocket(Socket socket, String host, int port, String clientCertificateAlias) throws NoSuchAlgorithmException, KeyManagementException, MessagingException, IOException {
TrustManager[] trustManagers = new TrustManager[] { new VeryTrustingTrustManager() };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
return sslSocketFactory.createSocket(socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true);
}Example 9
| Project: redmine-java-api-master File: NaiveSSLFactory.java View source code |
/**
* @return Return naive SSL socket factory (authorize any SSL/TSL host)
*/
public static SSLSocketFactory createNaiveSSLSocketFactory() {
X509TrustManager manager = new NaiveX509TrustManager();
SSLContext sslcontext = null;
try {
TrustManager[] managers = new TrustManager[] { manager };
sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, managers, null);
} catch (NoSuchAlgorithmExceptionKeyManagementException | e) {
e.printStackTrace();
}
return new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}Example 10
| Project: Yarrn-master File: SslCertificateHelper.java View source code |
public static void trustGeotrustCertificate(final Context context) {
try {
final KeyStore trustStore = KeyStore.getInstance("BKS");
final InputStream in = context.getResources().openRawResource(R.raw.geotrust_cert);
trustStore.load(in, null);
final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(trustStore);
final SSLContext sslCtx = SSLContext.getInstance("TLS");
sslCtx.init(null, tmf.getTrustManagers(), new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslCtx.getSocketFactory());
} catch (final Exception e) {
AQUtility.report(e);
e.printStackTrace();
}
}Example 11
| Project: tinify-java-master File: SSLContext.java View source code |
public static SSLSocketFactory getSocketFactory() {
try {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
Collection<? extends Certificate> certificates = certificateFactory.generateCertificates(certificateStream());
KeyStore keyStore = newEmptyKeyStore();
int index = 0;
for (Certificate certificate : certificates) {
String certificateAlias = Integer.toString(index++);
keyStore.setCertificateEntry(certificateAlias, certificate);
}
if (keyStore.size() == 0) {
/* The resource stream was empty, no certificates were found. */
throw new ConnectionException("Unable to load any CA certificates.", null);
}
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, null);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
javax.net.ssl.SSLContext sslContext = javax.net.ssl.SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
return sslContext.getSocketFactory();
} catch (GeneralSecurityExceptionIOException | e) {
throw new ConnectionException("Error while loading trusted CA certificates.", e);
}
}Example 12
| Project: Android-tcp-long-connection-based-on-Apache-mina-master File: SslContextFactory.java View source code |
public SSLContext newInstance() throws Exception { KeyManagerFactory kmf = this.keyManagerFactory; TrustManagerFactory tmf = this.trustManagerFactory; if (kmf == null) { String algorithm = keyManagerFactoryAlgorithm; if (algorithm == null && keyManagerFactoryAlgorithmUseDefault) { algorithm = KeyManagerFactory.getDefaultAlgorithm(); } if (algorithm != null) { if (keyManagerFactoryProvider == null) { kmf = KeyManagerFactory.getInstance(algorithm); } else { kmf = KeyManagerFactory.getInstance(algorithm, keyManagerFactoryProvider); } } } if (tmf == null) { String algorithm = trustManagerFactoryAlgorithm; if (algorithm == null && trustManagerFactoryAlgorithmUseDefault) { algorithm = TrustManagerFactory.getDefaultAlgorithm(); } if (algorithm != null) { if (trustManagerFactoryProvider == null) { tmf = TrustManagerFactory.getInstance(algorithm); } else { tmf = TrustManagerFactory.getInstance(algorithm, trustManagerFactoryProvider); } } } KeyManager[] keyManagers = null; if (kmf != null) { kmf.init(keyManagerFactoryKeyStore, keyManagerFactoryKeyStorePassword); keyManagers = kmf.getKeyManagers(); } TrustManager[] trustManagers = null; if (tmf != null) { if (trustManagerFactoryParameters != null) { tmf.init(trustManagerFactoryParameters); } else { tmf.init(trustManagerFactoryKeyStore); } trustManagers = tmf.getTrustManagers(); } SSLContext context = null; if (provider == null) { context = SSLContext.getInstance(protocol); } else { context = SSLContext.getInstance(protocol, provider); } context.init(keyManagers, trustManagers, secureRandom); if (clientSessionCacheSize >= 0) { context.getClientSessionContext().setSessionCacheSize(clientSessionCacheSize); } if (clientSessionTimeout >= 0) { context.getClientSessionContext().setSessionTimeout(clientSessionTimeout); } if (serverSessionCacheSize >= 0) { context.getServerSessionContext().setSessionCacheSize(serverSessionCacheSize); } if (serverSessionTimeout >= 0) { context.getServerSessionContext().setSessionTimeout(serverSessionTimeout); } return context; }
Example 13
| Project: httpcomponents-core-master File: SSLTestContexts.java View source code |
public static SSLContext createServerSSLContext() throws Exception {
final URL keyStoreURL = SSLTestContexts.class.getResource("/test.keystore");
final String storePassword = "nopassword";
return SSLContextBuilder.create().loadTrustMaterial(keyStoreURL, storePassword.toCharArray()).loadKeyMaterial(keyStoreURL, storePassword.toCharArray(), storePassword.toCharArray()).build();
}Example 14
| Project: moskito-central-master File: RESTHttpsConnector.java View source code |
/**
* Builds {@link javax.net.ssl.SSLContext} instance according to connector's config.
*
* @return Configured {@link javax.net.ssl.SSLContext} instance or null.
*/
private SSLContext getSslContext() {
SSLContext sslContext = null;
SSLContextBuilder builder = new SSLContextBuilder();
File storeFile = null;
FileInputStream storeStream = null;
try {
if (StringUtils.isNotEmpty(getConnectorConfig().getTrustStoreFilePath())) {
storeFile = new File(getConnectorConfig().getTrustStoreFilePath());
}
if (storeFile != null && storeFile.exists()) {
storeStream = new FileInputStream(storeFile);
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(storeStream, getConnectorConfig().getTrustStorePassword().toCharArray());
if (getConnectorConfig().isTrustSelfSigned()) {
builder.loadTrustMaterial(trustStore, new TrustSelfSignedStrategy());
} else {
builder.loadTrustMaterial(trustStore);
}
} else {
/* default TrustStore will be used */
if (getConnectorConfig().isTrustSelfSigned()) {
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
} else {
builder.loadTrustMaterial(null);
}
}
sslContext = builder.useTLS().build();
} catch (Exception e) {
log.error("Error while initializing SSL context: " + e.getMessage(), e);
} finally {
if (storeStream != null) {
try {
storeStream.close();
} catch (IOException ignored) {
}
}
}
return sslContext;
}Example 15
| Project: Android-Templates-And-Utilities-master File: SelfSignedSSLUtility.java View source code |
public static SSLContext createSSLContext() throws GeneralSecurityException { KeyStore keyStore = loadKeyStore(); SelfSignedTrustManager selfSignedTrustManager = new SelfSignedTrustManager(keyStore); TrustManager[] tms = new TrustManager[] { selfSignedTrustManager }; KeyManager[] kms = null; KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(keyStore, ExampleConfig.SSL_KEYSTORE_PASSWORD.toCharArray()); kms = kmf.getKeyManagers(); SSLContext context = SSLContext.getInstance("TLS"); context.init(kms, tms, new SecureRandom()); return context; }
Example 16
| Project: ant-master File: TrustManager.java View source code |
public static SSLSocketFactory getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final X509TrustManager[] trustAllCerts = new X509TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
return sslSocketFactory;
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 17
| Project: AsyncOkHttp-master File: CustomSSLSocketFactoryCreator.java View source code |
public SSLSocketFactory create() {
SSLSocketFactory sslSocketFactory = null;
X509TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
try {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager[] { tm }, null);
sslSocketFactory = sc.getSocketFactory();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return sslSocketFactory;
}Example 18
| Project: blend4j-master File: SslHacking.java View source code |
public static void disableCertificateCheck() {
javax.net.ssl.TrustManager x509 = new javax.net.ssl.X509TrustManager() {
public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
return;
}
public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
return;
}
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("SSL");
ctx.init(null, new javax.net.ssl.TrustManager[] { x509 }, null);
} catch (java.security.GeneralSecurityException ex) {
}
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
}Example 19
| Project: bnd-master File: HttpsUtil.java View source code |
static void disableServerVerification(URLConnection connection) throws GeneralSecurityException {
if (!(connection instanceof HttpsURLConnection))
return;
HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
}
public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
}
} };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
httpsConnection.setSSLSocketFactory(sslSocketFactory);
HostnameVerifier trustAnyHost = new HostnameVerifier() {
public boolean verify(String string, SSLSession session) {
return true;
}
};
httpsConnection.setHostnameVerifier(trustAnyHost);
}Example 20
| Project: checkstyle-idea-master File: InsecureHTTPURLConfigurationLocation.java View source code |
@NotNull
@Override
protected InputStream resolveFile() throws IOException {
TrustManager[] trustAllCerts = new TrustManager[] { new AllTrustingTrustManager() };
try {
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception ignored) {
}
return super.resolveFile();
}Example 21
| Project: coinbase-java-master File: CoinbaseSSL.java View source code |
public static synchronized SSLContext getSSLContext() { if (sslContext != null) { return sslContext; } KeyStore trustStore = null; InputStream trustStoreInputStream = null; try { if (System.getProperty("java.vm.name").equalsIgnoreCase("Dalvik")) { trustStoreInputStream = CoinbaseSSL.class.getResourceAsStream("/com/coinbase/api/ca-coinbase.bks"); trustStore = KeyStore.getInstance("BKS"); } else { trustStoreInputStream = CoinbaseSSL.class.getResourceAsStream("/com/coinbase/api/ca-coinbase.jks"); trustStore = KeyStore.getInstance("JKS"); } trustStore.load(trustStoreInputStream, "changeit".toCharArray()); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(trustStore); SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, tmf.getTrustManagers(), null); sslContext = ctx; } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (trustStoreInputStream != null) { try { trustStoreInputStream.close(); } catch (IOException ex) { throw new RuntimeException(ex); } } } return sslContext; }
Example 22
| Project: congress-android-master File: HttpManager.java View source code |
public static void init() {
if (initialized)
return;
initialized = true;
OkHttpClient okHttpClient = new OkHttpClient();
// adapted from https://github.com/mapbox/mapbox-android-sdk/pull/244
SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null);
} catch (GeneralSecurityException e) {
throw new AssertionError();
}
okHttpClient.setSslSocketFactory(sslContext.getSocketFactory());
Log.w(Utils.TAG, "Initializing an OkHttpClient instance as the URL stream handler factory forevermore.");
URL.setURLStreamHandlerFactory(okHttpClient);
}Example 23
| Project: ForgeEssentials-master File: SSLContextHelper.java View source code |
public void loadSSLCertificate(InputStream keystore, String storepass, String keypass) throws IOException, GeneralSecurityException {
if (keystore == null)
throw new IOException("Invalid keystore");
// Load KeyStore
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(keystore, storepass.toCharArray());
// Init KeyManager
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, keypass.toCharArray());
// Init TrustManager
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
// Init SSLContext
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
sslCtx = ctx;
}Example 24
| Project: geoserver-master File: SSLUtilities.java View source code |
public static void registerKeyStore(String keyStoreName) {
try {
ClassLoader classLoader = SSLUtilities.class.getClassLoader();
InputStream keyStoreInputStream = classLoader.getResourceAsStream(keyStoreName);
if (keyStoreInputStream == null) {
throw new FileNotFoundException("Could not find file named '" + keyStoreName + "' in the CLASSPATH");
}
// load the keystore
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(keyStoreInputStream, null);
// add to known keystore
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
// default SSL connections are initialized with the keystore above
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustManagers, null);
SSLContext.setDefault(sc);
} catch (IOExceptionGeneralSecurityException | e) {
throw new RuntimeException(e);
}
}Example 25
| Project: identity-sample-apps-master File: SSLValidationDisabler.java View source code |
public static void disableSSLValidation() {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
} catch (GeneralSecurityException e) {
}
}Example 26
| Project: JamVM-PH-master File: Jessie.java View source code |
public Object run() {
put("SSLContext.TLSv1.1", SSLContextImpl.class.getName());
put("Alg.Alias.SSLContext.SSLv3", "TLSv1.1");
put("Alg.Alias.SSLContext.TLSv1", "TLSv1.1");
put("Alg.Alias.SSLContext.TLSv1.0", "TLSv1.1");
put("Alg.Alias.SSLContext.TLS", "TLSv1.1");
put("Alg.Alias.SSLContext.SSL", "TLSv1.1");
put("KeyManagerFactory.JessieX509", X509KeyManagerFactory.class.getName());
put("TrustManagerFactory.JessieX509", X509TrustManagerFactory.class.getName());
put("KeyManagerFactory.JessiePSK", PreSharedKeyManagerFactoryImpl.class.getName());
//put("TrustManagerFactory.SRP", SRPTrustManagerFactory.class.getName());
put("Mac.SSLv3HMac-MD5", SSLv3HMacMD5Impl.class.getName());
put("Mac.SSLv3HMac-SHA", SSLv3HMacSHAImpl.class.getName());
put("Signature.TLSv1.1-RSA", SSLRSASignatureImpl.class.getName());
put("Alg.Alias.Signature.TLSv1-RSA", "TLSv1.1-RSA");
put("Alg.Alias.Signature.SSLv3-RSA", "TLSv1.1-RSA");
return null;
}Example 27
| Project: jgalaxy-master File: Ssl.java View source code |
public static void disableCertificateCheck() {
javax.net.ssl.TrustManager x509 = new javax.net.ssl.X509TrustManager() {
public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
return;
}
public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
return;
}
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("SSL");
ctx.init(null, new javax.net.ssl.TrustManager[] { x509 }, null);
} catch (java.security.GeneralSecurityException ex) {
}
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
}Example 28
| Project: karate-master File: HttpUtils.java View source code |
public static SSLContext getSslContext(String algorithm) { TrustManager[] certs = new TrustManager[] { new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } } }; SSLContext ctx = null; if (algorithm == null) { algorithm = "TLS"; } try { ctx = SSLContext.getInstance(algorithm); ctx.init(null, certs, new SecureRandom()); } catch (Exception e) { throw new RuntimeException(e); } return ctx; }
Example 29
| Project: keystone-master File: ConfigTest.java View source code |
@Test
public void testUnequalConfigSsl() {
Config firstConfig = Config.newConfig();
try {
SSLContext firstSslContext = SSLContext.getInstance("SSL");
firstSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
firstConfig.withSSLContext(firstSslContext);
} catch (Exception e) {
e.printStackTrace();
}
Config secondConfig = Config.newConfig();
try {
SSLContext secondSslContext = SSLContext.getInstance("SSL");
secondSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
secondConfig.withSSLContext(secondSslContext);
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertNotEquals(firstConfig, secondConfig);
}Example 30
| Project: LittleProxy-mitm-master File: TrustedClient.java View source code |
protected SSLContext initSslContext() throws GeneralSecurityException, IOException { FileInputStream is = new FileInputStream(new File("littleproxy-mitm.p12")); KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(is, "Be Your Own Lantern".toCharArray()); is.close(); X509TrustManager customTm = new MergeTrustManager(ks); SSLContext context = SSLContext.getInstance("TLSv1.2"); context.init(null, new TrustManager[] { customTm }, null); return context; }
Example 31
| Project: MVP-master File: TrustManager.java View source code |
public static SSLSocketFactory getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final X509TrustManager[] trustAllCerts = new X509TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
return sslSocketFactory;
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 32
| Project: mylyn-redmine-connector-master File: NaiveSSLFactory.java View source code |
/**
* @return Return naive SSL socket factory (authorize any SSL/TSL host)
*/
public static SSLSocketFactory createNaiveSSLSocketFactory() {
X509TrustManager manager = new NaiveX509TrustManager();
SSLContext sslcontext = null;
try {
TrustManager[] managers = new TrustManager[] { manager };
sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, managers, null);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}Example 33
| Project: neutron-master File: ConfigTest.java View source code |
@Test
public void testUnequalConfigSsl() {
Config firstConfig = Config.newConfig();
try {
SSLContext firstSslContext = SSLContext.getInstance("SSL");
firstSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
firstConfig.withSSLContext(firstSslContext);
} catch (Exception e) {
e.printStackTrace();
}
Config secondConfig = Config.newConfig();
try {
SSLContext secondSslContext = SSLContext.getInstance("SSL");
secondSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
secondConfig.withSSLContext(secondSslContext);
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertNotEquals(firstConfig, secondConfig);
}Example 34
| Project: OneSwarm-master File: PublicKeySSLClientTest.java View source code |
@Test
public void testHandShake() throws UnknownHostException, IOException, Exception {
File f = new File("/tmp/existingFriendsTest");
PublicKeySSLClient publicKeySSLClient = new PublicKeySSLClient(f, new LinkedList<byte[]>(), "localhost", 12345, Base64.decode(SERVER_KEY), new CryptoHandler() {
public PublicKey getPublicKey() {
return PublicKeyCreator.getInstance().getOwnPublicKey();
}
public SSLContext getSSLContext() throws Exception {
return PublicKeyCreator.getInstance().getSSLContext();
}
public byte[] sign(byte[] data) throws Exception {
return null;
}
});
publicKeySSLClient.connect();
publicKeySSLClient.updateFriends();
}Example 35
| Project: openstack4j-master File: ConfigTest.java View source code |
@Test
public void testUnequalConfigSsl() {
Config firstConfig = Config.newConfig();
try {
SSLContext firstSslContext = SSLContext.getInstance("SSL");
firstSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
firstConfig.withSSLContext(firstSslContext);
} catch (Exception e) {
e.printStackTrace();
}
Config secondConfig = Config.newConfig();
try {
SSLContext secondSslContext = SSLContext.getInstance("SSL");
secondSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
secondConfig.withSSLContext(secondSslContext);
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertNotEquals(firstConfig, secondConfig);
}Example 36
| Project: osgi-jax-rs-connector-master File: TLSUtil.java View source code |
public static void initializeUntrustedContext() {
X509TrustManager tm = new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException {
// no content
}
@Override
public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException {
// no content
}
};
SSLContext ctx;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] { tm }, null);
SSLContext.setDefault(ctx);
} catch (Exception shouldNotHappen) {
throw new IllegalStateException(shouldNotHappen);
}
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}Example 37
| Project: ovirt-engine-master File: EngineManagerProvider.java View source code |
@Override public SSLContext getSSLContext() throws GeneralSecurityException { final SSLContext context; try { context = SSLContext.getInstance(this.sslProtocol); context.init(getKeyManagers(), getTrustManagers(), null); } catch (KeyManagementExceptionNoSuchAlgorithmException | ex) { throw new RuntimeException(ex); } return context; }
Example 38
| Project: redmineReport-master File: NaiveSSLFactory.java View source code |
/**
* @return Return naive SSL socket factory (authorize any SSL/TSL host)
*/
public static SSLSocketFactory createNaiveSSLSocketFactory() {
X509TrustManager manager = new NaiveX509TrustManager();
SSLContext sslcontext = null;
try {
TrustManager[] managers = new TrustManager[] { manager };
sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, managers, null);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}Example 39
| Project: sitebricks-master File: MailClientPipelineFactory.java View source code |
public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = Channels.pipeline();
if (config.getAuthType() != Auth.PLAIN) {
SSLEngine sslEngine = SSLContext.getDefault().createSSLEngine();
sslEngine.setUseClientMode(true);
SslHandler sslHandler = new SslHandler(sslEngine);
sslHandler.setEnableRenegotiation(true);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
// and then business logic.
pipeline.addLast("handler", mailClientHandler);
return pipeline;
}Example 40
| Project: spritely-master File: SSLBypass.java View source code |
public static void bypassSSL(HttpClientBuilder builder) {
// Imports: javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
builder.setSslcontext(sslContext);
} catch (final Exception e) {
e.printStackTrace();
}
}Example 41
| Project: ssl_npn-master File: SSLContextCreator.java View source code |
public static SSLContext newContext() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException { KeyStore store = KeyStore.getInstance("PKCS12"); FileInputStream stream = new FileInputStream("server.pkcs12"); try { store.load(stream, "test123".toCharArray()); } finally { stream.close(); } KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(store, "test123".toCharArray()); SSLContext context = SSLContext.getInstance("TLSv1.2", new sslnpn.net.ssl.internal.ssl.Provider()); context.init(kmf.getKeyManagers(), new TrustManager[] { new NaiveTrustManager() }, new SecureRandom()); return context; }
Example 42
| Project: webpie-master File: SSLEngineFactoryWebServerTesting.java View source code |
@Override
public SSLEngine createSslEngine() {
// Create/startPing the SSLContext with key material
try (InputStream keySt = SSLEngineFactoryWebServerTesting.class.getResourceAsStream(serverKeystore)) {
char[] passphrase = password.toCharArray();
// First startPing the key and trust material.
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(keySt, passphrase);
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
//****************Server side specific*********************
// KeyManager's decide which key material to use.
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, passphrase);
sslContext.init(kmf.getKeyManagers(), null, null);
//****************Server side specific*********************
SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(false);
return engine;
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 43
| Project: zandy-master File: WebDavTrust.java View source code |
// Kudos and blame to http://stackoverflow.com/a/1201102/950790
public static void installAllTrustingCertificate() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception ignored) {
}
}Example 44
| Project: bugvm-master File: SSLContextUtils.java View source code |
static SSLContext getDefault() { SSLContext sslcontext; try { try { sslcontext = SSLContext.getInstance("Default"); } catch (NoSuchAlgorithmException ex) { sslcontext = SSLContext.getInstance("TLS"); } sslcontext.init(null, null, null); } catch (final Exception ex) { throw new IllegalStateException("Failure initializing default SSL context", ex); } return sslcontext; }
Example 45
| Project: http-client-master File: BogusSslContextFactory.java View source code |
// private static helpers ----------------------------------------------------------------------------------------- @SneakyThrows(Exception.class) private static SSLContext createServerContext() { String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm"); if (algorithm == null) algorithm = "X509"; // If you're on android, use BKS here instead of JKS KeyStore ks = KeyStore.getInstance("JKS"); ks.load(BogusKeyStore.asInputStream(), BogusKeyStore.getKeyStorePassword()); // Set up key manager factory to use our key store KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm); kmf.init(ks, BogusKeyStore.getCertificatePassword()); // Initialize the SSLContext to work with our key managers. SSLContext serverContext = SSLContext.getInstance(PROTOCOL); serverContext.init(kmf.getKeyManagers(), BogusTrustManagerFactory.getTrustManagers(), null); return serverContext; }
Example 46
| Project: JBossAS51-master File: Context.java View source code |
/*
* Returns an initialized JSSE SSLContext that uses the KeyManagerFactory
* and TrustManagerFactory objects encapsulated by a given JBossSX
* SecurityDomain.
*/
static SSLContext forDomain(SecurityDomain securityDomain) throws IOException {
SSLContext sslCtx = null;
try {
sslCtx = SSLContext.getInstance("TLS");
KeyManagerFactory keyMgr = securityDomain.getKeyManagerFactory();
if (keyMgr == null)
throw new IOException("KeyManagerFactory is null for security domain: " + securityDomain.getSecurityDomain());
TrustManagerFactory trustMgr = securityDomain.getTrustManagerFactory();
TrustManager[] trustMgrs = null;
if (trustMgr != null)
trustMgrs = trustMgr.getTrustManagers();
sslCtx.init(keyMgr.getKeyManagers(), trustMgrs, null);
return sslCtx;
} catch (NoSuchAlgorithmException e) {
log.error("Failed to get SSLContext for TLS algorithm", e);
throw new IOException("Failed to get SSLContext for TLS algorithm");
} catch (KeyManagementException e) {
log.error("Failed to init SSLContext", e);
throw new IOException("Failed to init SSLContext");
} catch (SecurityException e) {
log.error("Failed to init SSLContext", e);
throw new IOException("Failed to init SSLContext");
}
}Example 47
| Project: JBossAS_5_1_EDG-master File: Context.java View source code |
/*
* Returns an initialized JSSE SSLContext that uses the KeyManagerFactory
* and TrustManagerFactory objects encapsulated by a given JBossSX
* SecurityDomain.
*/
static SSLContext forDomain(SecurityDomain securityDomain) throws IOException {
SSLContext sslCtx = null;
try {
sslCtx = SSLContext.getInstance("TLS");
KeyManagerFactory keyMgr = securityDomain.getKeyManagerFactory();
if (keyMgr == null)
throw new IOException("KeyManagerFactory is null for security domain: " + securityDomain.getSecurityDomain());
TrustManagerFactory trustMgr = securityDomain.getTrustManagerFactory();
TrustManager[] trustMgrs = null;
if (trustMgr != null)
trustMgrs = trustMgr.getTrustManagers();
sslCtx.init(keyMgr.getKeyManagers(), trustMgrs, null);
return sslCtx;
} catch (NoSuchAlgorithmException e) {
log.error("Failed to get SSLContext for TLS algorithm", e);
throw new IOException("Failed to get SSLContext for TLS algorithm");
} catch (KeyManagementException e) {
log.error("Failed to init SSLContext", e);
throw new IOException("Failed to init SSLContext");
} catch (SecurityException e) {
log.error("Failed to init SSLContext", e);
throw new IOException("Failed to init SSLContext");
}
}Example 48
| Project: manifold-master File: KeystoreManagerFactory.java View source code |
/** Build a secure socket factory that pays no attention to certificates in trust store, and just trusts everything.
*/
public static javax.net.ssl.SSLSocketFactory getTrustingSecureSocketFactory() throws ManifoldCFException {
try {
java.security.SecureRandom secureRandom = java.security.SecureRandom.getInstance("SHA1PRNG");
// Create an SSL context
javax.net.ssl.SSLContext sslContext = javax.net.ssl.SSLContext.getInstance("SSL");
sslContext.init(null, openTrustManagerArray, secureRandom);
return sslContext.getSocketFactory();
} catch (java.security.NoSuchAlgorithmException e) {
throw new ManifoldCFException("No such algorithm: " + e.getMessage(), e);
} catch (java.security.KeyManagementException e) {
throw new ManifoldCFException("Key management exception: " + e.getMessage(), e);
}
}Example 49
| Project: QuickBuild-Tray-Monitor-master File: MainApp.java View source code |
private static void trustAll() {
TrustManager[] trustAllCerts = new TrustManager[1];
trustAllCerts[0] = new TrustAllManager();
SSLContext sc;
try {
sc = javax.net.ssl.SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, null);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
}Example 50
| Project: undertow-master File: DefaultWebSocketClientSslProvider.java View source code |
@Override
public XnioSsl getSsl(XnioWorker worker, Endpoint endpoint, ClientEndpointConfig cec, URI uri) {
XnioSsl ssl = getThreadLocalSsl(worker);
if (ssl != null) {
return ssl;
}
//look for some SSL config
SSLContext sslContext = (SSLContext) cec.getUserProperties().get(SSL_CONTEXT);
if (sslContext != null) {
return new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, sslContext);
}
return null;
}Example 51
| Project: wildfly-core-master File: TLSSyslogServer.java View source code |
/**
* Creates custom sslContext from keystore and truststore configured in
*
* @see org.productivity.java.syslog4j.server.impl.net.tcp.TCPNetSyslogServer#initialize()
*/
@Override
public void initialize() throws SyslogRuntimeException {
super.initialize();
final SSLTCPNetSyslogServerConfigIF config = (SSLTCPNetSyslogServerConfigIF) this.tcpNetSyslogServerConfig;
try {
final char[] keystorePwd = config.getKeyStorePassword().toCharArray();
final KeyStore keystore = loadKeyStore(config.getKeyStore(), keystorePwd);
final char[] truststorePassword = config.getTrustStorePassword().toCharArray();
final KeyStore truststore = loadKeyStore(config.getTrustStore(), truststorePassword);
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keystore, keystorePwd);
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(truststore);
sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
} catch (Exception e) {
LOGGER.error("Exception occurred during SSLContext for TLS syslog server initialization", e);
throw new SyslogRuntimeException(e);
}
}Example 52
| Project: advanced-networking-master File: CustomSSLSocketFactory.java View source code |
public static SSLSocketFactory getInstance() throws NoSuchAlgorithmException, KeyStoreException, CertificateException, KeyManagementException, IOException {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
try {
String trustStore = System.getProperty("javax.net.ssl.trustStore");
String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
if (trustStore == null || trustStorePassword == null) {
throw new IOException("javax.net.ssl.trustStore/javax.net.ssl.trustStorePassword property - not set");
}
FileInputStream keystoreStream = new FileInputStream(trustStore);
try {
keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(keystoreStream, trustStorePassword.toCharArray());
} finally {
keystoreStream.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
trustManagerFactory.init(keystore);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
SSLContext.setDefault(sslContext);
return new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}Example 53
| Project: AFBaseLibrary-master File: AFCertificateUtil.java View source code |
public static SSLSocketFactory setCertificates(Context context, String... certificateNames) {
InputStream[] certificates = getCertificatesByAssert(context, certificateNames);
if (certificates == null) {
return null;
}
try {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null);
int index = 0;
for (InputStream certificate : certificates) {
String certificateAlias = Integer.toString(index++);
keyStore.setCertificateEntry(certificateAlias, certificateFactory.generateCertificate(certificate));
try {
if (certificate != null)
certificate.close();
} catch (IOException e) {
e.printStackTrace();
}
}
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());
return sslContext.getSocketFactory();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}Example 54
| Project: AisenWeiBo-master File: HttpsUtility.java View source code |
public OkHttpClient getOkHttpClient() {
if (mOKHttpClient == null) {
try {
mOKHttpClient = new OkHttpClient();
mOKHttpClient.setConnectTimeout(GlobalContext.CONN_TIMEOUT, TimeUnit.MILLISECONDS);
mOKHttpClient.setReadTimeout(GlobalContext.READ_TIMEOUT, TimeUnit.MILLISECONDS);
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { tm }, null);
mOKHttpClient.setSslSocketFactory(sslContext.getSocketFactory());
} catch (Throwable e) {
e.printStackTrace();
}
}
return mOKHttpClient;
}Example 55
| Project: alchemy-os-master File: HttpsConnectionImpl.java View source code |
@Override
public SecurityInfo getSecurityInfo() throws IOException {
HttpsURLConnection https = (HttpsURLConnection) conn;
if (https.getServerCertificates().length == 0) {
throw new IOException("No certificates");
}
X509Certificate cert = (X509Certificate) https.getServerCertificates()[0];
try {
return new SecurityInfoImpl(SSLContext.getInstance("TLS").getProtocol(), https.getCipherSuite(), cert);
} catch (NoSuchAlgorithmException nsae) {
throw new IOException(nsae);
}
}Example 56
| Project: ambry-master File: SSLFactoryTest.java View source code |
@Test
public void testSSLFactory() throws Exception {
File trustStoreFile = File.createTempFile("truststore", ".jks");
SSLConfig sslConfig = new SSLConfig(TestSSLUtils.createSslProps("DC1,DC2,DC3", SSLFactory.Mode.SERVER, trustStoreFile, "server"));
SSLConfig clientSSLConfig = new SSLConfig(TestSSLUtils.createSslProps("DC1,DC2,DC3", SSLFactory.Mode.CLIENT, trustStoreFile, "client"));
SSLFactory sslFactory = new SSLFactory(sslConfig);
SSLContext sslContext = sslFactory.getSSLContext();
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
Assert.assertNotNull(socketFactory);
SSLServerSocketFactory serverSocketFactory = sslContext.getServerSocketFactory();
Assert.assertNotNull(serverSocketFactory);
SSLEngine serverSideSSLEngine = sslFactory.createSSLEngine("localhost", 9095, SSLFactory.Mode.SERVER);
TestSSLUtils.verifySSLConfig(sslContext, serverSideSSLEngine, false);
//client
sslFactory = new SSLFactory(clientSSLConfig);
sslContext = sslFactory.getSSLContext();
socketFactory = sslContext.getSocketFactory();
Assert.assertNotNull(socketFactory);
serverSocketFactory = sslContext.getServerSocketFactory();
Assert.assertNotNull(serverSocketFactory);
SSLEngine clientSideSSLEngine = sslFactory.createSSLEngine("localhost", 9095, SSLFactory.Mode.CLIENT);
TestSSLUtils.verifySSLConfig(sslContext, clientSideSSLEngine, true);
}Example 57
| Project: Android-Backup-master File: AllTrustedSocketFactory.java View source code |
@Override
public Socket createSocket(Socket socket, String host, int port, String clientCertificateAlias) throws NoSuchAlgorithmException, KeyManagementException, MessagingException, IOException {
TrustManager[] trustManagers = new TrustManager[] { new InsecureX509TrustManager() };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
Socket trustedSocket;
if (socket == null) {
trustedSocket = socketFactory.createSocket();
} else {
trustedSocket = socketFactory.createSocket(socket, host, port, true);
}
return trustedSocket;
}Example 58
| Project: android-libcore64-master File: SSLSessionContextTest.java View source code |
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* javax.net.ssl.SSLSessionContex#getSessionCacheSize()
* javax.net.ssl.SSLSessionContex#setSessionCacheSize(int size)
*/
public final void test_sessionCacheSize() throws NoSuchAlgorithmException, KeyManagementException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
SSLSessionContext sc = context.getClientSessionContext();
sc.setSessionCacheSize(10);
assertEquals("10 wasn't returned", 10, sc.getSessionCacheSize());
sc.setSessionCacheSize(5);
assertEquals("5 wasn't returned", 5, sc.getSessionCacheSize());
try {
sc.setSessionCacheSize(-1);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
}
}Example 59
| Project: android-signage-client-master File: TrustManager.java View source code |
/**
* Create a trust manager that does not validate certificate chains
* @return
*/
public static HostnameVerifier overrideCertificateChainValidation() {
try {
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// return the all-trusting host verifier
return allHostsValid;
} catch (KeyManagementException e) {
Log.e(TAG, e.toString());
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, e.toString());
}
return null;
}Example 60
| Project: android-tutorials-glide-master File: UnsafeOkHttpClient.java View source code |
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setSslSocketFactory(sslSocketFactory);
okHttpClient.setProtocols(Arrays.asList(Protocol.HTTP_1_1));
okHttpClient.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 61
| Project: AndroidAsync-master File: SSLTests.java View source code |
public void testKeys() throws Exception {
KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
kmf.init(ks, "storepass".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore ts = KeyStore.getInstance(KeyStore.getDefaultType());
ts.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
tmf.init(ts);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.listenSecure(8888, sslContext);
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("hello");
}
});
Thread.sleep(1000);
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(sslContext);
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setTrustManagers(tmf.getTrustManagers());
AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("https://localhost:8888/"), null).get();
}Example 62
| Project: AndroidSource-master File: SslSocketFactory.java View source code |
private static SSLContext createSSLContext(InputStream keyStore, String keyStorePassword) throws GeneralSecurityException { SSLContext sslcontext = null; try { sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { new SsX509TrustManager(keyStore, keyStorePassword) }, null); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("Failure initializing default SSL context", e); } catch (KeyManagementException e) { throw new IllegalStateException("Failure initializing default SSL context", e); } return sslcontext; }
Example 63
| Project: android_platform_libcore-master File: SSLSessionContextTest.java View source code |
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* javax.net.ssl.SSLSessionContex#getSessionCacheSize()
* javax.net.ssl.SSLSessionContex#setSessionCacheSize(int size)
*/
public final void test_sessionCacheSize() throws NoSuchAlgorithmException, KeyManagementException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
SSLSessionContext sc = context.getClientSessionContext();
sc.setSessionCacheSize(10);
assertEquals("10 wasn't returned", 10, sc.getSessionCacheSize());
sc.setSessionCacheSize(5);
assertEquals("5 wasn't returned", 5, sc.getSessionCacheSize());
try {
sc.setSessionCacheSize(-1);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
}
}Example 64
| Project: android_volley_examples-master File: SslSocketFactory.java View source code |
private static SSLContext createSSLContext(InputStream keyStore, String keyStorePassword) throws GeneralSecurityException { SSLContext sslcontext = null; try { sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { new SsX509TrustManager(keyStore, keyStorePassword) }, null); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("Failure initializing default SSL context", e); } catch (KeyManagementException e) { throw new IllegalStateException("Failure initializing default SSL context", e); } return sslcontext; }
Example 65
| Project: AppUpdate-master File: TrustAllCertificates.java View source code |
public static void install() {
try {
TrustAllCertificates trustAll = new TrustAllCertificates();
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { trustAll }, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(trustAll);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Failed setting up all thrusting certificate manager.", e);
} catch (KeyManagementException e) {
throw new RuntimeException("Failed setting up all thrusting certificate manager.", e);
}
}Example 66
| Project: AppWorkUtils-master File: TrustALLSSLFactory.java View source code |
public static SSLSocketFactory getSSLFactoryTrustALL() throws IOException {
try {
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, TrustALLSSLFactory.trustAllCerts, new java.security.SecureRandom());
return sc.getSocketFactory();
} catch (final NoSuchAlgorithmException e) {
throw new IOException(e);
} catch (final KeyManagementException e) {
throw new IOException(e);
}
}Example 67
| Project: apteryx-master File: SSLInitializer.java View source code |
public static void Initialize() {
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, _TrustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(_Verifier);
} catch (Exception e) {
e.printStackTrace();
}
}Example 68
| Project: ARTPart-master File: SSLSessionContextTest.java View source code |
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* javax.net.ssl.SSLSessionContex#getSessionCacheSize()
* javax.net.ssl.SSLSessionContex#setSessionCacheSize(int size)
*/
public final void test_sessionCacheSize() throws NoSuchAlgorithmException, KeyManagementException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
SSLSessionContext sc = context.getClientSessionContext();
sc.setSessionCacheSize(10);
assertEquals("10 wasn't returned", 10, sc.getSessionCacheSize());
sc.setSessionCacheSize(5);
assertEquals("5 wasn't returned", 5, sc.getSessionCacheSize());
try {
sc.setSessionCacheSize(-1);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
}
}Example 69
| Project: asielauncher-master File: Main.java View source code |
public static void main(String[] args) {
// SSL patch
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
AsieLauncherGUI al = new AsieLauncherGUI();
System.out.println("Connecting...");
if (!al.init()) {
System.out.println("Error connecting!");
System.exit(1);
}
boolean isRunning = true;
while (al.isRunning && isRunning) {
int sleepLength = 1000;
if (!al.getLaunchedMinecraft()) {
al.repaint();
sleepLength = 100;
} else // Launched Minecraft
{
al.setVisible(false);
if (!al.isActive()) {
isRunning = false;
}
}
try {
Thread.sleep(sleepLength);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Shutting down.");
System.exit(0);
}Example 70
| Project: audit-master File: MainActivity.java View source code |
private void GetHttps() {
String https = "https://mail.qq.com/cgi-bin/loginpage";
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager[] { new MyTrustManager() }, new SecureRandom());
HttpsURLConnection conn = (HttpsURLConnection) new URL(https).openConnection();
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) sb.append(line);
Log.e("testcaseLog", sb.toString());
} catch (Exception e) {
e.printStackTrace();
}
}Example 71
| Project: aws-java-sdk-master File: SdkSSLContext.java View source code |
/**
* @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);
}
}Example 72
| Project: aws-sdk-java-master File: SdkSSLContext.java View source code |
/**
* @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);
}
}Example 73
| Project: Bingo-master File: HttpsCoder.java View source code |
private static SSLSocketFactory getSSLSocketFactory(InputStream keyStoreInputStream, String password) throws Exception {
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = getKeyStore(keyStoreInputStream, password);
keyManagerFactory.init(keyStore, password.toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
SSLContext context = SSLContext.getInstance(PROTOCOL);
context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
keyStoreInputStream.close();
return context.getSocketFactory();
}Example 74
| Project: BitTorrentApp-master File: TrustALLSSLFactory.java View source code |
public static SSLSocketFactory getSSLFactoryTrustALL() throws IOException {
try {
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, TrustALLSSLFactory.trustAllCerts, new java.security.SecureRandom());
return sc.getSocketFactory();
} catch (final NoSuchAlgorithmException e) {
throw new IOException(e.toString());
} catch (final KeyManagementException e) {
throw new IOException(e.toString());
}
}Example 75
| Project: caelum-stella-master File: CertificateAndPrivateKey.java View source code |
public void enableSSLForServer(InputStream serverCertificateFile, String password) {
try {
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(serverCertificateFile, password.toCharArray());
String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(defaultAlgorithm);
trustManagerFactory.init(trustStore);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
KeyManager[] keyManagers = { new HSKeyManager(certificate, privateKey) };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 76
| Project: cas-master File: SimpleHttpClientTests.java View source code |
private static SSLConnectionSocketFactory getFriendlyToAllSSLSocketFactory() throws Exception {
final TrustManager trm = new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(final X509Certificate[] certs, final String authType) {
}
@Override
public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
}
};
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { trm }, null);
return new SSLConnectionSocketFactory(sc, new NoopHostnameVerifier());
}Example 77
| Project: cats-master File: SSLUtil.java View source code |
/**
* to disable the certificate validation.
*
*/
public static void disableCertificateValidation() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 78
| Project: channelmanager2-master File: MockSSLEngineFactory.java View source code |
public SSLEngine createEngineForServerSocket() throws GeneralSecurityException, IOException {
// Create/initialize the SSLContext with key material
char[] passphrase = password.toCharArray();
// First initialize the key and trust material.
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(serverKeystore), passphrase);
SSLContext sslContext = SSLContext.getInstance("TLS");
//****************Server side specific*********************
// KeyManager's decide which key material to use.
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, passphrase);
sslContext.init(kmf.getKeyManagers(), null, null);
//****************Server side specific*********************
SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(false);
return engine;
}Example 79
| Project: cirmlive-master File: AllowAnySSL.java View source code |
public void installPermissiveTrustmanager() {
// Imports: javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
} catch (final Exception e) {
e.printStackTrace();
}
}Example 80
| Project: Cliques-master File: FakeX509TrustManager.java View source code |
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new FakeX509TrustManager() };
}
try {
context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
}Example 81
| Project: cloudbees-api-client-master File: TrustAllSocketFactory.java View source code |
public static SSLSocketFactory create() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] x509Certificates, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] x509Certificates, String authType) throws CertificateException {
if (LOGGER.isLoggable(FINE)) {
LOGGER.fine("Got the certificate: " + Arrays.asList(x509Certificates));
}
// TODO: define a mechanism for users to accept a certificate from UI
// try {
// CertificateUtil.validatePath(Arrays.asList(x509Certificates));
// } catch (GeneralSecurityException e) {
// e.printStackTrace();
// }
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
return context.getSocketFactory();
} catch (NoSuchAlgorithmException e) {
throw new Error(e);
} catch (KeyManagementException e) {
throw new Error(e);
}
}Example 82
| Project: cloudbreak-master File: CertificateTrustManager.java View source code |
public static SSLContext sslContext() { // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { LOGGER.info("accept all issuer"); return null; } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { LOGGER.info("checkClientTrusted"); // Trust everything } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { LOGGER.info("checkServerTrusted"); // Trust everything } } }; try { // Install the all-trusting trust manager SSLContext sc = SslConfigurator.newInstance().createSSLContext(); sc.init(null, trustAllCerts, new SecureRandom()); LOGGER.warn("Trust all SSL cerificates has been installed"); return sc; } catch (KeyManagementException e) { LOGGER.error(e.getMessage(), e); throw new RuntimeException("F", e); } }
Example 83
| Project: commons-eid-master File: BeIDSocketFactory.java View source code |
public static SSLSocketFactory getSSLSocketFactory() throws NoSuchAlgorithmException, KeyManagementException {
if (BeIDSocketFactory.socketFactorSingleton == null) {
final SSLContext sslContext = SSLContext.getInstance("TLS");
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("BeID");
sslContext.init(keyManagerFactory.getKeyManagers(), null, SecureRandom.getInstance("BeID"));
socketFactorSingleton = sslContext.getSocketFactory();
}
return socketFactorSingleton;
}Example 84
| Project: Composer-Java-Bindings-master File: Downloader.java View source code |
private void registerSSLContext(HttpClient client) throws Exception {
X509TrustManager tm = new ComposerTrustManager();
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = client.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
}Example 85
| Project: cpush-apns-master File: SecureSslContextFactory.java View source code |
public static SSLContext getSSLContext(Credentials conf) { SSLContext clientContext = CLIENT_CONTEXT.get(conf); if (clientContext == null) { try { String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm"); if (algorithm == null) { algorithm = "SunX509"; } KeyStore keyStore = KeyStore.getInstance("PKCS12"); keyStore.load(new ByteArrayInputStream(conf.getCertification()), conf.getPassword().toCharArray()); KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm); kmf.init(keyStore, conf.getPassword().toCharArray()); clientContext = SSLContext.getInstance(PROTOCOL); clientContext.init(kmf.getKeyManagers(), new TrustManager[] { new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { throw new CertificateException("Client is not trusted."); } } }, null); CLIENT_CONTEXT.putIfAbsent(conf, clientContext); } catch (Exception e) { e.printStackTrace(); } } return clientContext; }
Example 86
| Project: DavidWebb-master File: TestWebb_Ssl.java View source code |
public void testHttpsInvalidCertificateAndHostnameIgnore() throws Exception {
webb.setBaseUri(null);
TrustManager[] trustAllCerts = new TrustManager[] { new AlwaysTrustManager() };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
webb.setSSLSocketFactory(sslContext.getSocketFactory());
webb.setHostnameVerifier(new TrustingHostnameVerifier());
Response<Void> response = webb.get("https://localhost:13003/").asVoid();
assertTrue(response.isSuccess() || response.getStatusCode() == 301);
}Example 87
| Project: deepnighttwo-master File: CategoryYank.java View source code |
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
;
}
// TODO Auto-generated method stub
getPV("");
}Example 88
| Project: dreamDroid-master File: MainActivity.java View source code |
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tv_main);
try {
// set location of the keystore
MemorizingTrustManager.setKeyStoreFile("private", "sslkeys.bks");
// register MemorizingTrustManager for HTTPS
SSLContext sc = SSLContext.getInstance("TLS");
mTrustManager = new MemorizingTrustManager(this);
sc.init(null, new X509TrustManager[] { mTrustManager }, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(mTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()));
Picasso.Builder builder = new Picasso.Builder(this);
builder.downloader(new UrlConnectionDownloader(this) {
@Override
protected HttpURLConnection openConnection(Uri path) throws IOException {
HttpURLConnection connection = super.openConnection(path);
String userinfo = path.getUserInfo();
if (!userinfo.isEmpty()) {
connection.setRequestProperty("Authorization", "Basic " + Base64.encodeToString(userinfo.getBytes(), Base64.NO_WRAP));
}
return connection;
}
});
Picasso.setSingletonInstance(builder.build());
} catch (Exception e) {
e.printStackTrace();
}
}Example 89
| Project: dse_driver_examples-master File: TestSSL.java View source code |
public static void main(String[] args) throws Exception {
SSLContext context = getSSLContext("/Users/mark/deploy/datastax.truststore", "datastax", "/Users/mark/deploy/datastax.keystore", // truststore first, keystore second
"datastax");
Session session = null;
// Default cipher suites supported by C*
String[] cipherSuites = { "TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_256_CBC_SHA" };
Cluster cluster = Cluster.builder().addContactPoints("54.183.130.240").withSSL(new SSLOptions(context, cipherSuites)).build();
try {
System.out.println("connecting...");
session = cluster.connect();
System.out.println(session.getState().toString());
ResultSet myResults;
myResults = session.execute("select * from system.peers");
for (Row myRow : myResults) {
System.out.println(myRow.toString());
}
/**
myResults = session.execute("select * from markc.testme");
for (Row myRow : myResults) {
System.out.println(myRow.toString());
}**/
} catch (Exception e) {
e.printStackTrace();
}
session.close();
cluster.close();
}Example 90
| Project: ecf-master File: HttpClientDefaultSSLSocketFactoryModifier.java View source code |
public synchronized SSLContext getSSLContext(String protocols) { SSLContext rtvContext = null; if (protocols != null) { //$NON-NLS-1$ String protocolNames[] = StringUtils.split(protocols, ","); for (int i = 0; i < protocolNames.length; i++) { try { rtvContext = SSLContext.getInstance(protocolNames[i]); sslContext.init(null, new TrustManager[] { new HttpClientSslTrustManager() }, null); break; } catch (Exception e) { } } } return rtvContext; }
Example 91
| Project: egdownloader-master File: HttpsUtils.java View source code |
private static HttpsURLConnection getHttpsConnection(String urlStr, Proxy proxy) throws IOException, NoSuchAlgorithmException, KeyManagementException {
URL url = new URL(urlStr);
HttpsURLConnection conn = null;
if (proxy != null) {
conn = (HttpsURLConnection) url.openConnection(proxy);
} else {
conn = (HttpsURLConnection) url.openConnection();
}
// ä¸?验è¯?æœ?务器主机å??å’Œè¯?书
conn.setHostnameVerifier(new IgnoreHostnameVerifier());
TrustManager[] tm = { new X509TrustManager4Portal() };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tm, null);
SSLSocketFactory ssf = sslContext.getSocketFactory();
conn.setSSLSocketFactory(ssf);
return conn;
}Example 92
| Project: flexmls_api4j-master File: ConnectionApacheHttps.java View source code |
@Override
protected final void resetChild() {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { new FullTrustManager() }, null);
SSLSocketFactory sf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme https = new Scheme("https", SSL_PORT, sf);
getClient().getConnectionManager().getSchemeRegistry().register(https);
setHost(new HttpHost(getConfig().getEndpoint(), SSL_PORT, "https"));
} catch (Exception e) {
logger.error("Failed to setup SSL authentication for the client (https disabled).", e);
}
}Example 93
| Project: frostwire-common-master File: TrustALLSSLFactory.java View source code |
public static SSLSocketFactory getSSLFactoryTrustALL() throws IOException {
try {
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, TrustALLSSLFactory.trustAllCerts, new java.security.SecureRandom());
return sc.getSocketFactory();
} catch (final NoSuchAlgorithmException e) {
throw new IOException(e.toString());
} catch (final KeyManagementException e) {
throw new IOException(e.toString());
}
}Example 94
| Project: Git.NB-master File: FakeX509TrustManager.java View source code |
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new FakeX509TrustManager() };
}
try {
context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
}Example 95
| Project: gngr-master File: TrustManager.java View source code |
public static SSLSocketFactory makeSSLSocketFactory(final InputStream extraCertsStream) {
final String sep = File.separator;
final String hardDefaultPath = System.getProperty("java.home") + sep + "lib" + sep + "security" + sep + "cacerts";
final String defaultStorePath = System.getProperty("javax.net.ssl.trustStore", hardDefaultPath);
try (final FileInputStream defaultIS = new FileInputStream(defaultStorePath)) {
final KeyStore defKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
defKeyStore.load(defaultIS, "changeit".toCharArray());
final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(extraCertsStream, null);
// final KeyStore keyStore = KeyStore.Builder.newInstance(defKeyStore, null).getKeyStore();
final Enumeration<String> aliases = defKeyStore.aliases();
while (aliases.hasMoreElements()) {
final String alias = aliases.nextElement();
if (defKeyStore.isCertificateEntry(alias)) {
final Entry entry = defKeyStore.getEntry(alias, null);
keyStore.setEntry(alias, entry, null);
}
}
final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
final SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, tmf.getTrustManagers(), null);
return sc.getSocketFactory();
} catch (KeyManagementExceptionKeyStoreException | NoSuchAlgorithmException | IOException | CertificateException | UnrecoverableEntryException | e) {
throw new RuntimeException(e);
}
}Example 96
| Project: hammock-master File: SSLBypass.java View source code |
static void disableSSLChecks() {
HttpsURLConnection.setDefaultHostnameVerifier(( s, sslSession) -> true);
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] c, String s) {
}
@Override
public void checkServerTrusted(X509Certificate[] c, String s) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, SECURE_RANDOM);
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
} catch (GeneralSecurityException gse) {
throw new RuntimeException(gse.getMessage());
}
}Example 97
| Project: hudson_plugins-master File: TrustAllSocketFactory.java View source code |
@Override
protected void initFactory() throws IOException {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
sslFactory = context.getSocketFactory();
} catch (NoSuchAlgorithmException e) {
throw new Error(e);
} catch (KeyManagementException e) {
throw new Error(e);
}
}Example 98
| Project: ijoomer-adv-sdk-master File: TrustManagerManipulator.java View source code |
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new TrustManagerManipulator() };
}
try {
context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
}Example 99
| Project: IliConnect-master File: HttpsClient.java View source code |
public static HttpClient createHttpsClient(HttpClient client) {
X509TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
// TODO Auto-generated method stub
return null;
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
// TODO Auto-generated method stub
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
// TODO Auto-generated method stub
}
};
SSLContext ctx;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new MySSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = client.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
return new DefaultHttpClient(ccm, client.getParams());
} catch (Exception e1) {
e1.printStackTrace();
}
return null;
}Example 100
| Project: imok_android-master File: DisableSSLCertificateCheckUtil.java View source code |
/**
* Disable trust checks for SSL connections.
*/
public static void disableChecks() throws NoSuchAlgorithmException, KeyManagementException {
try {
new URL("https://0.0.0.0/").getContent();
} catch (IOException e) {
}
try {
SSLContext sslc;
sslc = SSLContext.getInstance("TLS");
TrustManager[] trustManagerArray = { new NullX509TrustManager() };
sslc.init(null, trustManagerArray, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new NullHostnameVerifier());
} catch (Exception e) {
e.printStackTrace();
}
}Example 101
| Project: ion-master File: SelfSignedCertificateTests.java View source code |
public void testKeys() throws Exception {
KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
kmf.init(ks, "storepass".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore ts = KeyStore.getInstance(KeyStore.getDefaultType());
ts.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
tmf.init(ts);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.listenSecure(8888, sslContext);
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("hello");
}
});
Thread.sleep(1000);
Ion ion = Ion.getInstance(getContext(), "CustomSSL");
ion.getHttpClient().getSSLSocketMiddleware().setSSLContext(sslContext);
ion.getHttpClient().getSSLSocketMiddleware().setTrustManagers(tmf.getTrustManagers());
ion.build(getContext()).load("https://localhost:8888/").asString().get();
}