Java Examples for javax.net.ssl.HostnameVerifier
The following java examples will help you to understand the usage of javax.net.ssl.HostnameVerifier. These source code samples are taken from different open source projects.
Example 1
| Project: MobilePlayer1020-master File: MyApplication.java View source code |
@Override
public void onCreate() {
super.onCreate();
x.Ext.init(this);
// 开�debug会影�性能
x.Ext.setDebug(BuildConfig.DEBUG);
// 信任所有https域å??
/*HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});*/
}Example 2
| Project: xUtils3-master File: MyApplication.java View source code |
@Override
public void onCreate() {
super.onCreate();
x.Ext.init(this);
// 开�debug会影�性能
x.Ext.setDebug(BuildConfig.DEBUG);
// 全局默认信任所有https域å?? 或 ä»…æ·»åŠ ä¿¡ä»»çš„https域å??
// 使用RequestParams#setHostnameVerifier(...)方法å?¯è®¾ç½®å?•次请求的域å??æ ¡éªŒ
x.Ext.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}Example 3
| Project: Android-Templates-And-Utilities-master File: SelfSignedSSLUtility.java View source code |
public static HostnameVerifier createSSLHostnameVerifier(final String apiHostname) { HostnameVerifier hostnameVerifier = new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { //Logcat.d(hostname + " / " + apiHostname); return hostname.equals(apiHostname); } }; return hostnameVerifier; }
Example 4
| 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 5
| 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 6
| 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 7
| 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 8
| 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 9
| Project: keystone-master File: ConfigTest.java View source code |
@Test
public void testUnequalConfigHostnameVerifier() {
Config firstConfig = Config.newConfig();
firstConfig.withHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// TODO Auto-generated method stub
return false;
}
});
Config secondConfig = Config.newConfig();
Assert.assertNotEquals(firstConfig, secondConfig);
}Example 10
| Project: maven-confluence-plugin-master File: Issue130IntegrationTest.java View source code |
@Before
@Override
public void initService() throws Exception {
super.initService();
try {
// SSL Implementation
final SSLSocketFactory sslSocketFactory = SSLFactories.newInstance(new YesTrustManager());
Assert.assertThat(sslSocketFactory, IsNull.notNullValue());
final X509TrustManager trustManager = new YesTrustManager();
final HostnameVerifier hostnameVerifier = new YesHostnameVerifier();
service.client.hostnameVerifier(hostnameVerifier).sslSocketFactory(sslSocketFactory, trustManager);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}Example 11
| Project: neutron-master File: ConfigTest.java View source code |
@Test
public void testUnequalConfigHostnameVerifier() {
Config firstConfig = Config.newConfig();
firstConfig.withHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// TODO Auto-generated method stub
return false;
}
});
Config secondConfig = Config.newConfig();
Assert.assertNotEquals(firstConfig, secondConfig);
}Example 12
| Project: openstack4j-master File: ConfigTest.java View source code |
@Test
public void testUnequalConfigHostnameVerifier() {
Config firstConfig = Config.newConfig();
firstConfig.withHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// TODO Auto-generated method stub
return false;
}
});
Config secondConfig = Config.newConfig();
Assert.assertNotEquals(firstConfig, secondConfig);
}Example 13
| 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 14
| 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 15
| 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 16
| 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 17
| Project: bugvm-master File: HttpsHandler.java View source code |
@Override
protected OkHttpClient newOkHttpClient(Proxy proxy) {
OkHttpClient client = super.newOkHttpClient(proxy);
client.setTransports(ENABLED_TRANSPORTS);
HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
// default verifier.
if (!(verifier instanceof DefaultHostnameVerifier)) {
client.setHostnameVerifier(verifier);
}
return client;
}Example 18
| 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 19
| 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 20
| Project: helios-master File: HostnameVerifierProviderTest.java View source code |
@Test
public void testHostnameVerificationEnabled() {
final String hostname = "example.com";
final HostnameVerifierProvider provider = new HostnameVerifierProvider(true, delegate);
final HostnameVerifier verifier = provider.verifierFor(hostname);
// verify that the returned provider just delegates to the delgate
when(delegate.verify(hostname, sslSession)).thenReturn(true);
assertTrue(verifier.verify(hostname, sslSession));
when(delegate.verify(hostname, sslSession)).thenReturn(false);
assertFalse(verifier.verify("foo.example.com", sslSession));
}Example 21
| 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 22
| Project: jayhorn-master File: SSLSocketExampleA.java View source code |
public void startSession() throws SSLHandshakeException, SSLPeerUnverifiedException {
HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
SSLSession s = socket.getSession();
// for verification purposes.
if (!hv.verify("mail.google.com", s)) {
throw new SSLHandshakeException("Expected mail.google.com, found " + s.getPeerPrincipal());
}
}Example 23
| Project: jira-rest-client-master File: HttpConnectionUtil.java View source code |
public static void disableSslVerification() {
try {
// 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(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;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
}Example 24
| Project: lightfish-master File: GlassfishAuthenticator.java View source code |
public void addAuthenticator(Client client, String username, String password) {
//TODO migration
// client.addFilter(new HTTPBasicAuthFilter(username, password));
/*
* Bypass certificates
*/
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String string, SSLSession ssls) {
return true;
}
});
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (KeyManagementExceptionNoSuchAlgorithmException | ex) {
Logger.getLogger(SnapshotProvider.class.getName()).log(Level.SEVERE, null, ex);
}
}Example 25
| Project: LuckyMonkey-master File: AllCertificatesAndHostsTruster.java View source code |
public static void apply() {
final TrustManager[] trustAllCerts = new TrustManager[] { new AllCertificatesAndHostsTruster() };
try {
final SSLContext context = SSLContext.getInstance("SSL");
context.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
} catch (Exception e) {
LOGGER.log(Level.INFO, SSL_FAILED);
}
}Example 26
| Project: mobilecloud-15-master File: UnsafeHttpsClient.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.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 27
| Project: neembuu-uploader-master File: SSLUtils.java View source code |
/**
* This static method disable the Validation Certificate. Use it for
* <b>HttpURLConnection</b>.
*/
public static void disableCertificateValidation() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
// Ignore differences between given hostname and certificate hostname
HostnameVerifier hv = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(hv);
} catch (Exception e) {
}
}Example 28
| Project: OpenETSMobile2-master File: AppletsApiCalendarRequest.java View source code |
@Override
public EventList loadDataFromNetwork() throws Exception {
String url = context.getString(R.string.applets_api_calendar, "ets", startDate, endDate);
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
return getRestTemplate().getForObject(url, EventList.class);
}Example 29
| Project: ORCID-Source-master File: OrcidJerseyT2ClientConfig.java View source code |
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
* <p>
* This method allows the bean instance to perform initialization only
* possible when all bean properties have been set and to throw an exception
* in the event of misconfiguration.
*
* @throws Exception
* in the event of misconfiguration (such as failure to set an
* essential property) or if initialization fails.
*/
@Override
public void afterPropertiesSet() throws Exception {
SSLContext ctx = createSslContext();
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
}, ctx));
}Example 30
| Project: POCenter-master File: UnsafeOkHttpUtils.java View source code |
/**
* don't verify certificate
* @return
*/
public static OkHttpClient getClient() {
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) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
} };
// 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 javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 31
| Project: Posterize-Android-master File: AllCertificatesAndHostsTruster.java View source code |
public static void apply() {
final TrustManager[] trustAllCerts = new TrustManager[] { new AllCertificatesAndHostsTruster() };
try {
final SSLContext context = SSLContext.getInstance("SSL");
context.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
} catch (Exception e) {
LOGGER.log(Level.INFO, SSL_FAILED);
}
}Example 32
| Project: programming-cloud-services-for-android-master File: UnsafeHttpsClient.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.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 33
| Project: Qmusic-master File: QMusicHTTPSTrustManager.java View source code |
public static HostnameVerifier getHostnameVerifier() { HostnameVerifier verifier = new HostnameVerifier() { @Override public boolean verify(String urlHostName, SSLSession session) { BLog.d("RequestImageManager", "" + urlHostName + " vs. " + session.getPeerHost()); return true; } }; return verifier; }
Example 34
| Project: QTPaySDK-Android-master File: HttpsTrustManager.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 HttpsTrustManager() };
}
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 35
| Project: robovm-master File: HttpsHandler.java View source code |
@Override
protected OkHttpClient newOkHttpClient(Proxy proxy) {
OkHttpClient client = super.newOkHttpClient(proxy);
client.setTransports(ENABLED_TRANSPORTS);
HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
// default verifier.
if (!(verifier instanceof DefaultHostnameVerifier)) {
client.setHostnameVerifier(verifier);
}
return client;
}Example 36
| Project: rsimulator-master File: SecurityHandler.java View source code |
public void initialize() {
// 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());
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
} catch (Exception e) {
log.error("Can not initialize.", e);
}
}Example 37
| Project: s1tbx-master File: SSLUtil.java View source code |
public void disableSSLCertificateCheck() {
hostnameVerifier = javax.net.ssl.HttpsURLConnection.getDefaultHostnameVerifier();
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
if (hostname.equals("qc.sentinel1.eo.esa.int")) {
return true;
}
return false;
}
});
final TrustManager[] trustManager = new 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) {
}
} };
try {
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustManager, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (NoSuchAlgorithmExceptionKeyManagementException | e) {
SystemUtils.LOG.warning("disableSSLCertificateCheck failed: " + e);
}
}Example 38
| Project: screensaver-master File: ImageLocatorUtil.java View source code |
/**
* @return the same URL iff the content of the URL is accessible, otherwise null
* @motivation allow UI code to gracefully handle non-extant images that are identified by URL
*/
public static URL toExtantContentUrl(URL url) {
if (url != null) {
try {
// Override the HostNameChecker so that any ole SSL (including our lowly dev box) will pass, and we can move on to verify this URL
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
// Image locator utility times out when displaying well images #173
//Object content = url.getContent();
//if (content != null) {
// return url;
//}
int timeout_seconds = 50 * 1000;
HttpsURLConnection huc = (HttpsURLConnection) url.openConnection();
huc.setConnectTimeout(timeout_seconds);
huc.setReadTimeout(timeout_seconds);
Object content = huc.getContent();
if (content != null) {
return url;
}
} catch (IOException e) {
log.error("image location error: " + e.toString());
}
}
log.info("image not available: " + url);
return null;
}Example 39
| Project: SmartCommunity-master File: VolleyX509TrustManager.java View source code |
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
// TODO Auto-generated method stub
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new VolleyX509TrustManager() };
}
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 40
| Project: Spark_Pixels-master File: WebHelpers.java View source code |
private static OkHttpClient disableTLSforStaging() {
log.e("WARNING: TLS DISABLED FOR STAGING!");
OkHttpClient client = new OkHttpClient();
client.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, 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];
}
} }, new SecureRandom());
client.setSslSocketFactory(context.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
return client;
}Example 41
| Project: spring-ldap-master File: TlsContextSourceEc2InstanceLaunchingFactoryBean.java View source code |
protected void setAdditionalContextSourceProperties(LdapContextSource ctx, final String dnsName) {
DefaultTlsDirContextAuthenticationStrategy authenticationStrategy = new DefaultTlsDirContextAuthenticationStrategy();
authenticationStrategy.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return hostname.equals(dnsName);
}
});
ctx.setAuthenticationStrategy(authenticationStrategy);
ctx.setPooled(false);
}Example 42
| Project: stubby4j-master File: FakeX509TrustManager.java View source code |
public void allowAllSSL() throws KeyManagementException, NoSuchAlgorithmException {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
});
final SSLContext defaultSslContext = SSLContext.getInstance("SSL");
defaultSslContext.init(new KeyManager[] {}, new TrustManager[] { this }, null);
SSLContext.setDefault(defaultSslContext);
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSslContext.getSocketFactory());
}Example 43
| Project: study-master File: HTTPSTrustManager.java View source code |
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
// TODO Auto-generated method stub
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new HTTPSTrustManager() };
}
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 44
| Project: tesb-rt-se-master File: HttpsConnectionHelper.java View source code |
public static void trustAllForUrlConnection() throws NoSuchAlgorithmException, KeyManagementException {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new FakeX509TrustManager() }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}Example 45
| Project: winstone-master File: HttpsConnectorFactoryTest.java View source code |
private void request(X509TrustManager tm) throws Exception {
HttpsURLConnection con = (HttpsURLConnection) new URL("https://localhost:59009/CountRequestsServlet").openConnection();
con.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
SSLContext ssl = SSLContext.getInstance("SSL");
ssl.init(null, new X509TrustManager[] { tm }, null);
con.setSSLSocketFactory(ssl.getSocketFactory());
IOUtils.toString(con.getInputStream());
}Example 46
| Project: youtui-core-master File: HTTPSTrustManager.java View source code |
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
// TODO Auto-generated method stub
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new HTTPSTrustManager() };
}
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 47
| Project: yyl-master File: MySSLTrust.java View source code |
@SuppressWarnings("null")
public static OkHttpClient configureClient(final OkHttpClient client) {
final TrustManager[] certs = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
}
} };
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, certs, new SecureRandom());
} catch (final java.security.GeneralSecurityException ex) {
}
try {
final HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
};
client.setHostnameVerifier(hostnameVerifier);
client.setSslSocketFactory(new SSLv3SocketFactory(ctx.getSocketFactory()));
} catch (final Exception e) {
}
return client;
}Example 48
| Project: zstack-master File: LdapUtil.java View source code |
void setTls(LdapContextSource ldapContextSource) {
// set tls
logger.debug("Ldap TLS enabled.");
DefaultTlsDirContextAuthenticationStrategy tls = new DefaultTlsDirContextAuthenticationStrategy();
tls.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
tls.setSslSocketFactory(new DummySSLSocketFactory());
ldapContextSource.setAuthenticationStrategy(tls);
}Example 49
| Project: -KJFrameForAndroid-master File: HTTPSTrustManager.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 HTTPSTrustManager() };
}
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 50
| Project: aliyun-odps-java-sdk-master File: AuthorizationUtil.java View source code |
public static void ignoreHttpsCerts(HttpURLConnection conn) throws IOException {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
}
};
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
return true;
}
};
ctx.init(null, new TrustManager[] { tm }, null);
if (conn instanceof HttpsURLConnection) {
((HttpsURLConnection) conn).setSSLSocketFactory(ctx.getSocketFactory());
((HttpsURLConnection) conn).setHostnameVerifier(hv);
}
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
}
}Example 51
| Project: bard-master File: ClientHelper.java View source code |
private static Configuration configureClient() {
TrustManager[] certs = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, certs, new SecureRandom());
} catch (java.security.GeneralSecurityException ex) {
}
assert ctx != null;
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// 'New' jersey...
ClientBuilder builder = ClientBuilder.newBuilder().sslContext(ctx);
Client client = builder.hostnameVerifier(hostnameVerifier).build();
Configuration config = client.getConfiguration();
// Old Jersey...
//ClientConfig config = new ClientConfig();
// try {
// config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(
// new HostnameVerifier() {
// public boolean verify(String hostname, SSLSession session) {
// return true;
// }
// },
// ctx
// ));
// } catch (Exception e) {
// }
// should be getting a better SAX parser, but there's only going to be
// a single source of XML documents
// 'New' jersey :)
config.getProperties().put(MessageProperties.XML_SECURITY_DISABLE, Boolean.TRUE);
return config;
}Example 52
| Project: BeijingNews_1020-master File: MyApplication.java View source code |
@Override
public void onCreate() {
super.onCreate();
ClearableCookieJar cookieJar1 = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getApplicationContext()));
HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);
// CookieJarImpl cookieJar1 = new CookieJarImpl(new MemoryCookieStore());
OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(10000L, TimeUnit.MILLISECONDS).readTimeout(10000L, TimeUnit.MILLISECONDS).addInterceptor(new LoggerInterceptor("TAG")).cookieJar(cookieJar1).hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}).sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager).build();
OkHttpUtils.initClient(okHttpClient);
}Example 53
| Project: conversation-master File: HttpConnectionManager.java View source code |
public void setupTrustManager(final HttpsURLConnection connection, final boolean interactive) {
final X509TrustManager trustManager;
final HostnameVerifier hostnameVerifier;
if (interactive) {
trustManager = mXmppConnectionService.getMemorizingTrustManager().getInteractive();
hostnameVerifier = mXmppConnectionService.getMemorizingTrustManager().wrapHostnameVerifier(new StrictHostnameVerifier());
} else {
trustManager = mXmppConnectionService.getMemorizingTrustManager().getNonInteractive();
hostnameVerifier = mXmppConnectionService.getMemorizingTrustManager().wrapHostnameVerifierNonInteractive(new StrictHostnameVerifier());
}
try {
final SSLSocketFactory sf = new TLSSocketFactory(new X509TrustManager[] { trustManager }, mXmppConnectionService.getRNG());
connection.setSSLSocketFactory(sf);
connection.setHostnameVerifier(hostnameVerifier);
} catch (final KeyManagementExceptionNoSuchAlgorithmException | ignored) {
}
}Example 54
| Project: Conversations-master File: HttpConnectionManager.java View source code |
public void setupTrustManager(final HttpsURLConnection connection, final boolean interactive) {
final X509TrustManager trustManager;
final HostnameVerifier hostnameVerifier;
if (interactive) {
trustManager = mXmppConnectionService.getMemorizingTrustManager().getInteractive();
hostnameVerifier = mXmppConnectionService.getMemorizingTrustManager().wrapHostnameVerifier(new StrictHostnameVerifier());
} else {
trustManager = mXmppConnectionService.getMemorizingTrustManager().getNonInteractive();
hostnameVerifier = mXmppConnectionService.getMemorizingTrustManager().wrapHostnameVerifierNonInteractive(new StrictHostnameVerifier());
}
try {
final SSLSocketFactory sf = new TLSSocketFactory(new X509TrustManager[] { trustManager }, mXmppConnectionService.getRNG());
connection.setSSLSocketFactory(sf);
connection.setHostnameVerifier(hostnameVerifier);
} catch (final KeyManagementExceptionNoSuchAlgorithmException | ignored) {
}
}Example 55
| Project: domodroid-master File: httpsUrl.java View source code |
//todo add tracerengine here too handle log.
public static HttpsURLConnection setUpHttpsConnection(String urlString, String login, String password) {
try {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@SuppressLint("TrustAllX509TrustManager")
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@SuppressLint("TrustAllX509TrustManager")
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
@SuppressLint("BadHostnameVerifier")
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Tell the URLConnection to use a SocketFactory from our SSLContext
URL url = new URL(urlString);
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
urlConnection.setHostnameVerifier(allHostsValid);
urlConnection.setSSLSocketFactory(sslContext.getSocketFactory());
final String basicAuth = "Basic " + Base64.encodeToString((login + ":" + password).getBytes(), Base64.NO_WRAP);
urlConnection.setRequestProperty("Authorization", basicAuth);
return urlConnection;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}Example 56
| Project: emobc-android-master File: HttpUtils.java View source code |
/**
* Take a client address is https by default if
* @param https
* @return
*/
public static DefaultHttpClient getHttpClient(boolean https) {
if (https) {
HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
DefaultHttpClient client = new DefaultHttpClient();
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
registry.register(new Scheme("https", socketFactory, 443));
SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());
// Set verifier
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
return httpClient;
}
return new DefaultHttpClient();
}Example 57
| Project: fiware-sdc-master File: ConnectionSetup.java View source code |
public HttpURLConnection createConnection(URL url) throws NoSuchAlgorithmException, KeyManagementException, IOException {
// Install the all-trusting trust manager
SSLContext sslctx = SSLContext.getInstance("SSL");
javax.net.ssl.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) {
}
} };
sslctx.init(null, trustAllCerts, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslctx.getSocketFactory());
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
return con;
}Example 58
| Project: geoserver-master File: LDAPUtils.java View source code |
/**
* Creates an LdapContext from a configuration object.
*
* @param ldapConfig
*
*/
public static LdapContextSource createLdapContext(LDAPBaseSecurityServiceConfig ldapConfig) {
LdapContextSource ldapContext = new DefaultSpringSecurityContextSource(ldapConfig.getServerURL());
ldapContext.setCacheEnvironmentProperties(false);
ldapContext.setAuthenticationSource(new SpringSecurityAuthenticationSource());
if (ldapConfig.isUseTLS()) {
// TLS does not play nicely with pooled connections
ldapContext.setPooled(false);
DefaultTlsDirContextAuthenticationStrategy tls = new DefaultTlsDirContextAuthenticationStrategy();
tls.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
ldapContext.setAuthenticationStrategy(tls);
}
return ldapContext;
}Example 59
| Project: glassfish-master File: JSSE.java View source code |
/* public String getHostFromCertificate() throws Exception {
HttpsURLConnection https = getHttpsURLConnection();
https.connect();
//We don't have to do the following, may be we can getaway with just
//accepting any server certificate.
Certificate[] cert = https.getServerCertificates();
generateTrustStore(cert[0]);
String dn = getDistinguishedName(cert[0]);
String hostName = getHostNameFromDN(dn);
return hostName;
}
private void generateTrustStore(Certificate cert) throws Exception {
File f = new File("certdb.jks");
FileOutputStream fout = new FileOutputStream(f);
KeyStore key = KeyStore.getInstance("JKS");//default is JKS
key.load(null, null); //initialize keystore
key.setCertificateEntry("s1as", cert);
key.store(fout, new char[]{'c', 'h', 'a', 'n', 'g', 'e', 'i', 't'});
System.setProperty("javax.net.ssl.trustStore", "out.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
}
private String getDistinguishedName(Certificate cert) {
String dn = ((X509Certificate)cert).getSubjectX500Principal().getName();
return dn;
}
private String getHostNameFromDN(String dn) {
StringTokenizer str = new StringTokenizer(dn, ",");
String s = str.nextToken();
return s.substring(s.indexOf("=")+1);
}*/
public void trustAnyServerCertificate() throws Exception {
//URL url = new URL("https", "cchidamb-pc.sfbay.sun.com", 4849, "/asadmin/admingui/homePage");
SSLContext sslc = SSLContext.getInstance("SSLv3");
final X509TrustManager[] tms = TrustAnyTrustManager.getInstanceArray();
sslc.init(null, tms, null);
if (sslc != null) {
HttpsURLConnection.setDefaultSSLSocketFactory(sslc.getSocketFactory());
}
HostnameVerifier hv = new AcceptAnyHostName();
HttpsURLConnection.setDefaultHostnameVerifier(hv);
URLConnection conn = url.openConnection();
HttpsURLConnection https = (HttpsURLConnection) conn;
https.connect();
//return https;
}Example 60
| Project: gocd-master File: GoAgentServerHttpClientBuilder.java View source code |
public CloseableHttpClient build() throws Exception {
HttpClientBuilder builder = HttpClients.custom();
builder.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build()).setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE);
HostnameVerifier hostnameVerifier = sslVerificationMode.verifier();
TrustStrategy trustStrategy = sslVerificationMode.trustStrategy();
KeyStore trustStore = agentTruststore();
SSLContextBuilder sslContextBuilder = SSLContextBuilder.create().useProtocol(systemEnvironment.get(SystemEnvironment.GO_SSL_TRANSPORT_PROTOCOL_TO_BE_USED_BY_AGENT));
if (trustStore != null || trustStrategy != null) {
sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
}
sslContextBuilder.loadKeyMaterial(agentKeystore(), keystorePassword().toCharArray());
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContextBuilder.build(), hostnameVerifier);
builder.setSSLSocketFactory(sslConnectionSocketFactory);
return builder.build();
}Example 61
| Project: KJFrameForAndroid-master File: HTTPSTrustManager.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 HTTPSTrustManager() };
}
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 62
| Project: MIFOSX-master File: ProcessorHelper.java View source code |
@SuppressWarnings("null")
public static OkHttpClient configureClient(final OkHttpClient client) {
final TrustManager[] certs = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
}
} };
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, certs, new SecureRandom());
} catch (final java.security.GeneralSecurityException ex) {
}
try {
final HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
};
client.setHostnameVerifier(hostnameVerifier);
client.setSslSocketFactory(ctx.getSocketFactory());
} catch (final Exception e) {
}
return client;
}Example 63
| Project: muikku-master File: ClientPool.java View source code |
private Client buildClient() {
// TODO: trust all only on development environment
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
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) {
}
} };
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
} catch (NoSuchAlgorithmExceptionKeyManagementException | e) {
logger.log(Level.SEVERE, "Failed to initialize trust all certificate manager", e);
}
HostnameVerifier fakeHostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
ClientBuilder builder = clientBuilder.sslContext(sslContext).hostnameVerifier(fakeHostnameVerifier).register(new JacksonConfigurator()).register(new BrowserCacheFeature());
return builder.build();
}Example 64
| Project: NoHttp-master File: OkHttpNetworkExecutor.java View source code |
@Override
public Network execute(IBasicRequest request) throws Exception {
URL url = new URL(request.url());
HttpURLConnection connection = URLConnectionFactory.getInstance().open(url, request.getProxy());
connection.setConnectTimeout(request.getConnectTimeout());
connection.setReadTimeout(request.getReadTimeout());
connection.setInstanceFollowRedirects(false);
if (connection instanceof HttpsURLConnection) {
SSLSocketFactory sslSocketFactory = request.getSSLSocketFactory();
if (sslSocketFactory != null)
((HttpsURLConnection) connection).setSSLSocketFactory(sslSocketFactory);
HostnameVerifier hostnameVerifier = request.getHostnameVerifier();
if (hostnameVerifier != null)
((HttpsURLConnection) connection).setHostnameVerifier(hostnameVerifier);
}
// Base attribute
connection.setRequestMethod(request.getRequestMethod().toString());
connection.setDoInput(true);
boolean isAllowBody = request.getRequestMethod().allowRequestBody();
connection.setDoOutput(isAllowBody);
// Adds all request header to connection.
Headers headers = request.headers();
// To fix bug: accidental EOFException before API 19.
List<String> values = headers.getValues(Headers.HEAD_KEY_CONNECTION);
if (values == null || values.size() == 0)
headers.add(Headers.HEAD_KEY_CONNECTION, Headers.HEAD_VALUE_CONNECTION_KEEP_ALIVE);
if (isAllowBody)
headers.set(Headers.HEAD_KEY_CONTENT_LENGTH, Long.toString(request.getContentLength()));
Map<String, String> requestHeaders = headers.toRequestHeaders();
for (Map.Entry<String, String> headerEntry : requestHeaders.entrySet()) {
String headKey = headerEntry.getKey();
String headValue = headerEntry.getValue();
Logger.i(headKey + ": " + headValue);
connection.setRequestProperty(headKey, headValue);
}
// 5. Connect
connection.connect();
return new OkHttpNetwork(connection);
}Example 65
| Project: okhttp-master File: OkHttpAsync.java View source code |
@Override
public void prepare(final Benchmark benchmark) {
concurrencyLevel = benchmark.concurrencyLevel;
targetBacklog = benchmark.targetBacklog;
client = new OkHttpClient.Builder().protocols(benchmark.protocols).dispatcher(new Dispatcher(new ThreadPoolExecutor(benchmark.concurrencyLevel, benchmark.concurrencyLevel, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()))).build();
if (benchmark.tls) {
SslClient sslClient = SslClient.localhost();
SSLSocketFactory socketFactory = sslClient.socketFactory;
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession session) {
return true;
}
};
client = client.newBuilder().sslSocketFactory(socketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build();
}
callback = new Callback() {
@Override
public void onFailure(Call call, IOException e) {
System.out.println("Failed: " + e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
ResponseBody body = response.body();
long total = SynchronousHttpClient.readAllAndClose(body.byteStream());
long finish = System.nanoTime();
if (VERBOSE) {
long start = (Long) response.request().tag();
System.out.printf("Transferred % 8d bytes in %4d ms%n", total, TimeUnit.NANOSECONDS.toMillis(finish - start));
}
requestsInFlight.decrementAndGet();
}
};
}Example 66
| Project: okhttputils-master File: MyApplication.java View source code |
@Override
public void onCreate() {
super.onCreate();
ClearableCookieJar cookieJar1 = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getApplicationContext()));
HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);
// CookieJarImpl cookieJar1 = new CookieJarImpl(new MemoryCookieStore());
OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(10000L, TimeUnit.MILLISECONDS).readTimeout(10000L, TimeUnit.MILLISECONDS).addInterceptor(new LoggerInterceptor("TAG")).cookieJar(cookieJar1).hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}).sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager).build();
OkHttpUtils.initClient(okHttpClient);
}Example 67
| Project: openemm-master File: TrustedHttpsHandler.java View source code |
@Override
protected URLConnection openConnection(URL url) throws IOException {
URLConnection connection = super.openConnection(url);
if (connection instanceof HttpsURLConnection) {
HttpsURLConnection urlConnection = (HttpsURLConnection) connection;
HostnameVerifier hostnameVerifier = urlConnection.getHostnameVerifier();
if (hostnameVerifier != kindHostnameVerifier) {
urlConnection.setHostnameVerifier(kindHostnameVerifier);
}
if (urlConnection.getSSLSocketFactory() != trustedSslSocketFactory && trustedSslSocketFactory != null) {
urlConnection.setSSLSocketFactory(trustedSslSocketFactory);
}
}
return connection;
}Example 68
| Project: oreva-master File: AllowSelfSignedCertsBehavior.java View source code |
@Override
public void modify(ClientConfig clientConfig) {
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
// Write a warning, as there is certainly a potential security implication here.
System.out.println(String.format("Warning: URL Host: '%s' does not equal '%s'", urlHostName, session.getPeerHost()));
return true;
}
};
TrustManager[] trustAll = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[] {};
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustAll, new SecureRandom());
HTTPSProperties props = new HTTPSProperties(hv, context);
clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, props);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}Example 69
| Project: org.ops4j.pax.url-master File: Util.java View source code |
static void setupClientSSL() throws Exception {
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream storeInput = new FileInputStream(getTestKeystore());
char[] storePass = getTestKeystorePassword().toCharArray();
store.load(storeInput, storePass);
TrustManagerFactory manager = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
manager.init(store);
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, manager.getTrustManagers(), null);
SSLSocketFactory factory = context.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(factory);
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public //
boolean verify(String hostname, SSLSession session) {
return true;
}
});
}Example 70
| Project: phresco-master File: ClientHelper.java View source code |
public static ClientConfig configureClient() {
TrustManager[] certs = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, certs, new SecureRandom());
} catch (java.security.GeneralSecurityException ex) {
}
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
ClientConfig config = new DefaultClientConfig();
try {
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
System.out.println(hostname);
System.out.println(session);
return true;
}
}, ctx));
} catch (Exception e) {
}
config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
return config;
}Example 71
| Project: quercus-gae-master File: HttpsConnection.java View source code |
@Override
protected void init(CurlResource curl) throws IOException {
Proxy proxy = getProxy();
HttpsURLConnection conn;
conn = (HttpsURLConnection) getURL().openConnection(proxy);
HostnameVerifier hostnameVerifier = CurlHostnameVerifier.create(curl.getIsVerifySSLPeer(), curl.getIsVerifySSLCommonName(), curl.getIsVerifySSLHostname());
conn.setHostnameVerifier(hostnameVerifier);
setConnection(conn);
}Example 72
| Project: quercus-master File: HttpsConnection.java View source code |
@Override
protected void init(CurlResource curl) throws IOException {
Proxy proxy = getProxy();
HttpsURLConnection conn;
if (proxy != null) {
conn = (HttpsURLConnection) getURL().openConnection(proxy);
} else {
conn = (HttpsURLConnection) getURL().openConnection();
}
HostnameVerifier hostnameVerifier = CurlHostnameVerifier.create(curl.getIsVerifySSLPeer(), curl.getIsVerifySSLCommonName(), curl.getIsVerifySSLHostname());
conn.setHostnameVerifier(hostnameVerifier);
setConnection(conn);
}Example 73
| Project: resin-master File: HttpsConnection.java View source code |
@Override
protected void init(CurlResource curl) throws IOException {
Proxy proxy = getProxy();
HttpsURLConnection conn;
if (proxy != null)
conn = (HttpsURLConnection) getURL().openConnection(proxy);
else
conn = (HttpsURLConnection) getURL().openConnection();
HostnameVerifier hostnameVerifier = CurlHostnameVerifier.create(curl.getIsVerifySSLPeer(), curl.getIsVerifySSLCommonName(), curl.getIsVerifySSLHostname());
conn.setHostnameVerifier(hostnameVerifier);
setConnection(conn);
}Example 74
| Project: RxVolley-master File: HTTPSTrustManager.java View source code |
@Deprecated
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
SSLContext sslContext = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new HTTPSTrustManager() };
}
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmExceptionKeyManagementException | e) {
e.printStackTrace();
}
if (sslContext != null) {
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
}
}Example 75
| Project: SmartReceiptsLibrary-master File: BetaSmartReceiptsHostConfiguration.java View source code |
/**
* Only meant for beta testing, so we don't have to buy another cert
*
* @return an UNSAFE {@link OkHttpClient}
*/
private static OkHttpClient.Builder getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
} };
// 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();
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(interceptor);
return builder;
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 76
| Project: TLSDemo-master File: UrlConnectionRequst.java View source code |
@Override
protected String doInBackground(String... params) {
try {
char[] buffer = new char[2048];
URL url = new URL(mUrl);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
//httpsConn.setSSLSocketFactory(TLSApplicaton.getInstance().getDefaultSSLSocketFactory());
httpConn.setReadTimeout(10000);
httpConn.setConnectTimeout(15000);
httpConn.setRequestMethod("GET");
httpConn.setDoInput(true);
if ("https".equalsIgnoreCase(url.getProtocol()) && mSSLSocketFactory != null) {
Log.e(TAG, "Set sslSocketFactory.");
((HttpsURLConnection) httpConn).setSSLSocketFactory(mSSLSocketFactory);
((HttpsURLConnection) httpConn).setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}
httpConn.connect();
int response = httpConn.getResponseCode();
Log.e(TAG, "https response code: " + response);
InputStream in = httpConn.getInputStream();
Reader reader = null;
reader = new InputStreamReader(in, "UTF-8");
int length = reader.read(buffer);
char[] tmpBuf = new char[length];
System.arraycopy(buffer, 0, tmpBuf, 0, length);
return new String(tmpBuf);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}Example 77
| Project: vld-master File: RetrofitModule.java View source code |
@Provides
public OkHttpClient provideOkhttpClient(Cache cache, CacheInterceptor cacheInterceptor, CookiesManager cookiesManager) {
X509TrustManager xtm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
X509Certificate[] x509Certificates = new X509Certificate[0];
return x509Certificates;
}
};
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new TrustManager[] { xtm }, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HostnameVerifier DO_NOT_VERIFY = ( hostname, session) -> true;
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return new OkHttpClient.Builder().cache(//æ·»åŠ ç¼“å˜
cache).addInterceptor(loggingInterceptor).addInterceptor(cacheInterceptor).sslSocketFactory(sslContext.getSocketFactory()).hostnameVerifier(DO_NOT_VERIFY).build();
}Example 78
| Project: voms-api-java-master File: RESTProtocol.java View source code |
public VOMSResponse doRequest(VOMSServerInfo endpoint, X509Credential credential, VOMSACRequest request) {
RESTServiceURLBuilder restQueryBuilder = new RESTServiceURLBuilder();
URL serviceUrl = restQueryBuilder.build(endpoint, request);
RESTVOMSResponseParsingStrategy responseParsingStrategy = new RESTVOMSResponseParsingStrategy();
HttpsURLConnection connection = null;
try {
connection = (HttpsURLConnection) serviceUrl.openConnection();
if (isSkipHostnameChecks()) {
connection.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
}
connection.setConnectTimeout(connectTimeout);
connection.setReadTimeout(readTimeout);
} catch (IOException e) {
throw new VOMSProtocolError(e.getMessage(), endpoint, request, credential, e);
}
connection.setSSLSocketFactory(getSSLSocketFactory(credential));
listener.notifyHTTPRequest(serviceUrl.toExternalForm());
try {
connection.connect();
} catch (IOException e) {
throw new VOMSProtocolError(e.getMessage(), endpoint, request, credential, e);
}
InputStream is = null;
try {
if (connection.getResponseCode() != 200) {
is = connection.getErrorStream();
} else
is = connection.getInputStream();
} catch (IOException e) {
throw new VOMSProtocolError(e.getMessage(), endpoint, request, credential, e);
}
VOMSResponse response = responseParsingStrategy.parse(is);
listener.notifyReceivedResponse(response);
connection.disconnect();
return response;
}Example 79
| Project: android_libcore-master File: HttpsURLConnectionTest.java View source code |
/**
* @tests javax.net.ssl.HttpsURLConnection#getHostnameVerifier()
*/
@TestTargetNew(level = TestLevel.COMPLETE, notes = "", method = "getHostnameVerifier", args = {})
public final void test_getHostnameVerifier() throws Exception {
HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"));
HostnameVerifier verifyer = con.getHostnameVerifier();
assertNotNull("Hostname verifyer is null", verifyer);
assertEquals("Incorrect value of hostname verirfyer", HttpsURLConnection.getDefaultHostnameVerifier(), verifyer);
}Example 80
| Project: aipo-master File: ALURLConnectionUtils.java View source code |
/**
* HttpURLConnection���HttpsURLConnectionを返�
*
* @param url
* @return HttpURLConnection���HttpsURLConnection
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws IOException
*/
public static HttpURLConnection openUrlConnection(URL connectURL) throws NoSuchAlgorithmException, KeyManagementException, IOException {
HttpURLConnection urlconnection = null;
// SSLHandshakeException�発生����調�る
urlconnection = (HttpURLConnection) connectURL.openConnection();
try {
urlconnection.getResponseMessage();
} catch (SSLHandshakeException ex) {
if ("https".equals(connectURL.getProtocol())) {
TrustManager[] tm = { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
SSLContext sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, tm, null);
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
urlconnection = (HttpsURLConnection) connectURL.openConnection();
((HttpsURLConnection) urlconnection).setSSLSocketFactory(sslcontext.getSocketFactory());
return urlconnection;
}
}
// http接続ã?®å ´å?ˆ
urlconnection = (HttpURLConnection) connectURL.openConnection();
return urlconnection;
}Example 81
| Project: Canoo-WebTest-master File: SunJsseBaseConnectionInitializer.java View source code |
/**
* Doing the initialization for https heavily relies on side effects in shared data, i.e. System properties and static
* fields in java.security.* and java.net.* .
*/
public void initializeConnection(final Configuration config) throws ConnectionInitializationException {
LOG.debug("Using Custom ConnectionInitializer: " + getClass().getName());
if (isProtocolHttps(config)) {
if (LOG.isDebugEnabled()) {
System.setProperty("javax.net.debug", "all");
}
logProtocolConfiguration(config);
installJsseProviderIfRequired(SUN_JSSE_PROVIDER_CLASS);
setSystemProperty(PROTOCOL_HANDLER_KEY, SUN_SSL_PROTOCOL_HANDLER_PACKAGE);
if (!config.getUseInsecureSSL()) {
attemptSetSystemProperty(config, TRUST_STORE_KEY, PROPERTY_TRUSTSTORE_FILE);
attemptSetSystemProperty(config, TRUST_STORE_PASSWORD_KEY, PROPERTY_TRUSTSTORE_PASSPHRASE);
}
// Ordering is important! The trust store is read upon connectionHandler
// initialization which occurs implicitly when the HostnameVerifier is
// installed.
installTrustAndKeyManager(config);
installHostnameVerifier(config);
}
}Example 82
| Project: cxf-dosgi-master File: SslIntent.java View source code |
@Override
public List<Object> call() throws Exception {
HttpConduitFeature conduitFeature = new HttpConduitFeature();
HttpConduitConfig conduitConfig = new HttpConduitConfig();
TLSClientParameters tls = new TLSClientParameters();
String karafHome = System.getProperty("karaf.home");
tls.setKeyManagers(keyManager(keystore(karafHome + "/etc/keystores/client.jks", CLIENT_PASSWORD), CLIENT_PASSWORD));
tls.setTrustManagers(trustManager(keystore(karafHome + "/etc/keystores/client.jks", CLIENT_PASSWORD)));
//tls.setTrustManagers(new TrustManager[]{new DefaultTrustManager()});
HostnameVerifier verifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
tls.setHostnameVerifier(verifier);
tls.setCertAlias("clientkey");
tls.setDisableCNCheck(true);
conduitConfig.setTlsClientParameters(tls);
conduitFeature.setConduitConfig(conduitConfig);
return Arrays.asList((Object) conduitFeature);
}Example 83
| Project: cxf-master File: SSLUtils.java View source code |
public static HostnameVerifier getHostnameVerifier(TLSClientParameters tlsClientParameters) { HostnameVerifier verifier; if (tlsClientParameters.getHostnameVerifier() != null) { verifier = tlsClientParameters.getHostnameVerifier(); } else if (tlsClientParameters.isUseHttpsURLConnectionDefaultHostnameVerifier()) { verifier = HttpsURLConnection.getDefaultHostnameVerifier(); } else if (tlsClientParameters.isDisableCNCheck()) { verifier = new AllowAllHostnameVerifier(); } else { verifier = new DefaultHostnameVerifier(PublicSuffixMatcherLoader.getDefault()); } return verifier; }
Example 84
| Project: jkdbx-master File: UrlStreamHelper.java View source code |
protected void setSSLSocketFactory(URLConnection conn) throws GeneralSecurityException, IOException {
if (conn instanceof HttpsURLConnection) {
SSLContext context = createSSLContext();
SSLSocketFactory sf = context.getSocketFactory();
((HttpsURLConnection) conn).setSSLSocketFactory(sf);
((HttpsURLConnection) conn).setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}
}Example 85
| Project: keycloak-master File: JSSETruststoreConfigurator.java View source code |
public HostnameVerifier getHostnameVerifier() { if (provider == null) { return null; } HostnameVerificationPolicy policy = provider.getPolicy(); switch(policy) { case ANY: return new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; } }; case WILDCARD: return new BrowserCompatHostnameVerifier(); case STRICT: return new StrictHostnameVerifier(); default: throw new IllegalStateException("Unknown policy: " + policy.name()); } }
Example 86
| Project: liferay-portal-master File: TunnelUtil.java View source code |
private static HttpURLConnection _getConnection(HttpPrincipal httpPrincipal) throws IOException {
if ((httpPrincipal == null) || (httpPrincipal.getUrl() == null)) {
return null;
}
URL url = new URL(httpPrincipal.getUrl() + "/api/liferay/do");
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
if (!_VERIFY_SSL_HOSTNAME && (httpURLConnection instanceof HttpsURLConnection)) {
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) httpURLConnection;
httpsURLConnection.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}
httpURLConnection.setRequestProperty(HttpHeaders.CONTENT_TYPE, ContentTypes.APPLICATION_X_JAVA_SERIALIZED_OBJECT);
httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestMethod(HttpMethods.POST);
return httpURLConnection;
}Example 87
| Project: Loboevolution-master File: SSLCertificate.java View source code |
/**
* Sets the certificate fix for Exception in thread "main"
* javax.net.ssl.SSLHandshakeException:
* sun.security.validator.ValidatorException: PKIX path building failed:
* sun.security.provider.certpath.SunCertPathBuilderException: unable to
* find valid certification path to requested target
*/
public static void setCertificate() {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
/*
* end of the fix
*/
} catch (KeyManagementException e) {
logger.error(e.getMessage());
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage());
}
}Example 88
| Project: mongo-rest-master File: ResourceClientFactory.java View source code |
public static Client getClientHandle(String username, String password, int connectTimeoutMillis, int readTimeoutMillis) {
if (clientHandle == null) {
// Take a small hit on first invocation
synchronized (mutex) {
X509TrustManager trustManager = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] certs, String string) throws CertificateException {
return;
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String string) throws CertificateException {
return;
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("SSL");
} catch (NoSuchAlgorithmException nsae) {
String message = String.format("Unable to setup SSL: (%s) %s", nsae.getClass().getSimpleName(), nsae.getMessage());
logger.error(message);
throw new RuntimeException(message, nsae);
}
try {
sslContext.init(null, new TrustManager[] { trustManager }, null);
} catch (KeyManagementException kme) {
String message = String.format("Unable to configure SSL: (%s) %s", kme.getClass().getSimpleName(), kme.getMessage());
logger.error(message);
throw new RuntimeException(message, kme);
}
ClientConfig config = new DefaultClientConfig();
config.getClasses().add(JacksonJsonProvider.class);
config.getSingletons().add(new JacksonJsonProvider(new ObjectMapper()));
config.getSingletons().add(new BaseExceptionMapper());
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
}, sslContext));
clientHandle = new Client(new URLConnectionClientHandler(), config);
clientHandle.addFilter(new HTTPBasicAuthFilter(username, password));
clientHandle.addFilter(new LoggingFilter());
if (connectTimeoutMillis > 0) {
clientHandle.setConnectTimeout(connectTimeoutMillis);
}
if (readTimeoutMillis > 0) {
clientHandle.setReadTimeout(readTimeoutMillis);
}
if (logger.isDebugEnabled()) {
logger.debug("Initialized client handle: " + clientHandle.getProperties());
}
}
}
return clientHandle;
}Example 89
| Project: mysql-binlog-connector-java-master File: PacketChannel.java View source code |
public void upgradeToSSL(SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier) throws IOException {
SSLSocket sslSocket = sslSocketFactory.createSocket(this.socket);
sslSocket.startHandshake();
socket = sslSocket;
inputStream = new ByteArrayInputStream(sslSocket.getInputStream());
outputStream = new ByteArrayOutputStream(sslSocket.getOutputStream());
if (hostnameVerifier != null && !hostnameVerifier.verify(sslSocket.getInetAddress().getHostName(), sslSocket.getSession())) {
throw new IdentityVerificationException("\"" + sslSocket.getInetAddress().getHostName() + "\" identity was not confirmed");
}
}Example 90
| Project: pact-jvm-master File: InsecureHttpsRequest.java View source code |
private void setupInsecureSSL() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
HttpClientBuilder b = HttpClientBuilder.create();
// setup a Trust Strategy that allows all certificates.
//
TrustStrategy trustStrategy = ( chain, authType) -> true;
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
b.setSSLContext(sslContext);
// don't check Hostnames, either.
// -- use SSLConnectionSocketFactory.getDefaultHostnameVerifier(), if you don't want to weaken
HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
// here's the special part:
// -- need to create an SSL Socket Factory, to use our weakened "trust strategy";
// -- and create a Registry, to register it.
//
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
// now, we create connection-manager using our Registry.
// -- allows multi-threaded use
PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
b.setConnectionManager(connMgr);
// finally, build the HttpClient;
// -- done!
this.httpclient = b.build();
}Example 91
| Project: pact-master File: InsecureHttpsRequest.java View source code |
private void setupInsecureSSL() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
HttpClientBuilder b = HttpClientBuilder.create();
// setup a Trust Strategy that allows all certificates.
//
TrustStrategy trustStrategy = ( chain, authType) -> true;
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
b.setSSLContext(sslContext);
// don't check Hostnames, either.
// -- use SSLConnectionSocketFactory.getDefaultHostnameVerifier(), if you don't want to weaken
HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
// here's the special part:
// -- need to create an SSL Socket Factory, to use our weakened "trust strategy";
// -- and create a Registry, to register it.
//
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
// now, we create connection-manager using our Registry.
// -- allows multi-threaded use
PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
b.setConnectionManager(connMgr);
// finally, build the HttpClient;
// -- done!
this.httpclient = b.build();
}Example 92
| Project: pax-web-undertow-master File: SslTest.java View source code |
@Test
public void runStaticResourceServlet() throws Exception {
URL url = new URL("https://localhost:8443/sample1/hello");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
SSLContext ssl = SSLContext.getInstance("TLS");
ssl.init(null, TRUST_ALL_CERTS, null);
con.setSSLSocketFactory(ssl.getSocketFactory());
con.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
assertThat(servletContext.getContextPath(), is("/sample1"));
InputStream is = con.getInputStream();
OutputStream os = new ByteArrayOutputStream();
StreamUtils.copyStream(is, os, true);
assertThat(os.toString(), containsString("Hello from Pax Web!"));
}Example 93
| Project: pgjdbc-master File: MakeSSL.java View source code |
public static void convert(PGStream stream, Properties info) throws PSQLException, IOException {
LOGGER.log(Level.FINE, "converting regular socket connection to ssl");
SSLSocketFactory factory;
String sslmode = PGProperty.SSL_MODE.get(info);
// Use the default factory if no specific factory is requested
// unless sslmode is set
String classname = PGProperty.SSL_FACTORY.get(info);
if (classname == null) {
// If sslmode is set, use the libp compatible factory
if (sslmode != null) {
factory = new LibPQFactory(info);
} else {
factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
} else {
try {
factory = (SSLSocketFactory) instantiate(classname, info, true, PGProperty.SSL_FACTORY_ARG.get(info));
} catch (Exception e) {
throw new PSQLException(GT.tr("The SSLSocketFactory class provided {0} could not be instantiated.", classname), PSQLState.CONNECTION_FAILURE, e);
}
}
SSLSocket newConnection;
try {
newConnection = (SSLSocket) factory.createSocket(stream.getSocket(), stream.getHostSpec().getHost(), stream.getHostSpec().getPort(), true);
// We must invoke manually, otherwise the exceptions are hidden
newConnection.startHandshake();
} catch (IOException ex) {
if (factory instanceof LibPQFactory) {
((LibPQFactory) factory).throwKeyManagerException();
}
throw new PSQLException(GT.tr("SSL error: {0}", ex.getMessage()), PSQLState.CONNECTION_FAILURE, ex);
}
String sslhostnameverifier = PGProperty.SSL_HOSTNAME_VERIFIER.get(info);
if (sslhostnameverifier != null) {
HostnameVerifier hvn;
try {
hvn = (HostnameVerifier) instantiate(sslhostnameverifier, info, false, null);
} catch (Exception e) {
throw new PSQLException(GT.tr("The HostnameVerifier class provided {0} could not be instantiated.", sslhostnameverifier), PSQLState.CONNECTION_FAILURE, e);
}
if (!hvn.verify(stream.getHostSpec().getHost(), newConnection.getSession())) {
throw new PSQLException(GT.tr("The hostname {0} could not be verified by hostnameverifier {1}.", stream.getHostSpec().getHost(), sslhostnameverifier), PSQLState.CONNECTION_FAILURE);
}
} else {
if ("verify-full".equals(sslmode) && factory instanceof LibPQFactory) {
if (!(((LibPQFactory) factory).verify(stream.getHostSpec().getHost(), newConnection.getSession()))) {
throw new PSQLException(GT.tr("The hostname {0} could not be verified.", stream.getHostSpec().getHost()), PSQLState.CONNECTION_FAILURE);
}
}
}
stream.changeSocket(newConnection);
}Example 94
| 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 95
| Project: RestComm-master File: NingClientFactory.java View source code |
private void disableCertificateVerification() throws KeyManagementException, NoSuchAlgorithmException {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new CustomTrustManager() };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
final HostnameVerifier verifier = new HostnameVerifier() {
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(verifier);
}Example 96
| Project: restcommander-master File: NingClientFactory.java View source code |
private void disableCertificateVerification() throws KeyManagementException, NoSuchAlgorithmException {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new CustomTrustManager() };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
final HostnameVerifier verifier = new HostnameVerifier() {
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(verifier);
}Example 97
| Project: SpiderJackson-master File: HttpClientCreater.java View source code |
/**
* 创建SSL安全连接,�验�安全性(爬虫下安全性�求�高)
* @return
*/
public static SSLConnectionSocketFactory getSSLSocketFactory() {
SSLConnectionSocketFactory sslsf = null;
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
sslsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
return sslsf;
}Example 98
| Project: symmetric-ds-master File: TransportManagerFactory.java View source code |
public static void initHttps(final String httpSslVerifiedServerNames, boolean allowSelfSignedCerts) {
try {
if (!StringUtils.isBlank(httpSslVerifiedServerNames)) {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String s, SSLSession sslsession) {
boolean verified = false;
if (!StringUtils.isBlank(httpSslVerifiedServerNames)) {
if (httpSslVerifiedServerNames.equalsIgnoreCase(Constants.TRANSPORT_HTTPS_VERIFIED_SERVERS_ALL)) {
verified = true;
} else {
String[] names = httpSslVerifiedServerNames.split(",");
for (String string : names) {
if (s != null && s.equals(string.trim())) {
verified = true;
break;
}
}
}
}
return verified;
}
});
}
if (allowSelfSignedCerts) {
HttpsURLConnection.setDefaultSSLSocketFactory(createSelfSignedSocketFactory());
}
} catch (GeneralSecurityException ex) {
throw new SecurityException(ex);
}
}Example 99
| Project: webtest-master File: SunJsseBaseConnectionInitializer.java View source code |
/**
* Doing the initialization for https heavily relies on side effects in shared data, i.e. System properties and static
* fields in java.security.* and java.net.* .
*/
public void initializeConnection(final Configuration config) throws ConnectionInitializationException {
LOG.debug("Using Custom ConnectionInitializer: " + getClass().getName());
if (isProtocolHttps(config)) {
if (LOG.isDebugEnabled()) {
System.setProperty("javax.net.debug", "all");
}
logProtocolConfiguration(config);
installJsseProviderIfRequired(SUN_JSSE_PROVIDER_CLASS);
setSystemProperty(PROTOCOL_HANDLER_KEY, SUN_SSL_PROTOCOL_HANDLER_PACKAGE);
if (!config.getUseInsecureSSL()) {
attemptSetSystemProperty(config, TRUST_STORE_KEY, PROPERTY_TRUSTSTORE_FILE);
attemptSetSystemProperty(config, TRUST_STORE_PASSWORD_KEY, PROPERTY_TRUSTSTORE_PASSPHRASE);
}
// Ordering is important! The trust store is read upon connectionHandler
// initialization which occurs implicitly when the HostnameVerifier is
// installed.
installTrustAndKeyManager(config);
installHostnameVerifier(config);
}
}Example 100
| Project: weixin4j-master File: SimpleHttpClient.java View source code |
protected HttpURLConnection createHttpConnection(HttpRequest request) throws IOException {
URI uri = request.getURI();
Proxy proxy = params != null ? params.getProxy() : null;
URLConnection urlConnection = proxy != null ? uri.toURL().openConnection(proxy) : uri.toURL().openConnection();
if (uri.getScheme().equals("https")) {
SSLContext sslContext = null;
HostnameVerifier hostnameVerifier = null;
if (params != null) {
sslContext = params.getSSLContext();
hostnameVerifier = params.getHostnameVerifier();
}
if (sslContext == null) {
sslContext = HttpClientFactory.allowSSLContext();
}
if (hostnameVerifier == null) {
hostnameVerifier = HttpClientFactory.AllowHostnameVerifier.GLOBAL;
}
HttpsURLConnection connection = (HttpsURLConnection) urlConnection;
connection.setSSLSocketFactory(sslContext.getSocketFactory());
connection.setHostnameVerifier(hostnameVerifier);
return connection;
} else {
return (HttpURLConnection) urlConnection;
}
}Example 101
| Project: XBDD-master File: JerseyClientFactory.java View source code |
/**
* Create a {@link Client} with the given options.
*
* @param options The options to customize the construction of the client
* @return The constructed client
*/
public Client createClient(final JerseyClientOptions options) {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { 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) {
}
} };
// Install the all-trusting trust manager
try {
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
final HostnameVerifier allHostsValid = new HostnameVerifier() {
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
};
final Client client = ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier(allHostsValid).build();
client.register(new HttpBasicAuthFilter(options.getUsername(), options.getPassword()));
client.register(BasicDBReader.class);
return client;
} catch (final Exception e) {
}
return null;
}