use of javax.net.ssl.HostnameVerifier in project OpenAM by OpenRock.
the class AMSetupUtils method openConnection.
private static HttpURLConnection openConnection(String urlString) throws IOException {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if (url.getProtocol().equals(HTTPS)) {
HttpsURLConnection sslConnection = (HttpsURLConnection) connection;
sslConnection.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}
return connection;
}
use of javax.net.ssl.HostnameVerifier in project CloudStack-archive by CloudStack-extras.
the class VmwareContext method getHTTPConnection.
public HttpURLConnection getHTTPConnection(String urlString, String httpMethod) throws Exception {
String cookieString = getServiceCookie();
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setAllowUserInteraction(true);
conn.setRequestProperty(org.apache.axis.transport.http.HTTPConstants.HEADER_COOKIE, cookieString);
conn.setRequestMethod(httpMethod);
connectWithRetry(conn);
return conn;
}
use of javax.net.ssl.HostnameVerifier in project cubrid-manager by CUBRID.
the class ClientHttp method setUpConnection.
/**
* Set up a http client
*
* @throws UnknownHostException a possible exception
* @throws IOException a possible exception
*/
private void setUpConnection() {
tearDownConnection();
this.requestUrl = "https://" + hostAddress + ":" + port + METHOD;
// support https
try {
// KeyStore trustStore =
// KeyStore.getInstance(KeyStore.getDefaultType());
// instream = new FileInputStream(new File("cm.keystore"));
// trustStore.load(instream, "admin1".toCharArray());
// SSLSocketFactory socketFactory = new
// SSLSocketFactory(trustStore);
// Scheme sch = new Scheme("https", 443, socketFactory);
// this.httpClient.getConnectionManager().getSchemeRegistry().register(sch);
X509TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
};
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] { tm }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
URL url = new URL(requestUrl);
conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setConnectTimeout(timeout);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/json");
} catch (Exception e) {
LOGGER.error("Make to support HTTPS failed.", e);
}
}
use of javax.net.ssl.HostnameVerifier in project geode by apache.
the class ConnectCommandWithHttpAndSSLDUnitTest method connect.
@Override
protected void connect(final String host, final int jmxPort, final int httpPort, final HeadlessGfsh shell) {
assertNotNull(host);
assertNotNull(shell);
final CommandStringBuilder command = new CommandStringBuilder(CONNECT);
String endpoint;
// This is for testing purpose only. If we remove this piece of code we will
// get a java.security.cert.CertificateException
// as matching hostname can not be obtained in all test environment.
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String string, SSLSession ssls) {
return true;
}
});
endpoint = "https://" + host + ":" + httpPort + urlContext + "/v1";
command.addOption(CONNECT__USE_HTTP, Boolean.TRUE.toString());
command.addOption(CONNECT__URL, endpoint);
command.addOption(CONNECT__USE_SSL, Boolean.TRUE.toString());
if (sslInfoHolder.get().getProperty(CONNECT__KEY_STORE) != null) {
command.addOption(CONNECT__KEY_STORE, sslInfoHolder.get().getProperty(CONNECT__KEY_STORE));
}
if (sslInfoHolder.get().getProperty(CONNECT__KEY_STORE_PASSWORD) != null) {
command.addOption(CONNECT__KEY_STORE_PASSWORD, sslInfoHolder.get().getProperty(CONNECT__KEY_STORE_PASSWORD));
}
if (sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE) != null) {
command.addOption(CONNECT__TRUST_STORE, sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE));
}
if (sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE_PASSWORD) != null) {
command.addOption(CONNECT__TRUST_STORE_PASSWORD, sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE_PASSWORD));
}
if (sslInfoHolder.get().getProperty(CONNECT__SSL_PROTOCOLS) != null) {
command.addOption(CONNECT__SSL_PROTOCOLS, sslInfoHolder.get().getProperty(CONNECT__SSL_PROTOCOLS));
}
if (sslInfoHolder.get().getProperty(CONNECT__SSL_CIPHERS) != null) {
command.addOption(CONNECT__SSL_CIPHERS, sslInfoHolder.get().getProperty(CONNECT__SSL_CIPHERS));
}
CommandResult result = executeCommand(shell, command.toString());
if (!shell.isConnectedAndReady()) {
fail("Connect command failed to connect to manager " + endpoint + " result=" + commandResultToString(result));
}
info("Successfully connected to managing node using HTTPS");
assertEquals(true, shell.isConnectedAndReady());
}
use of javax.net.ssl.HostnameVerifier in project maven-plugins by apache.
the class ProjectInfoReportUtils method getURLConnection.
/**
* @param url not null
* @param project not null
* @param settings not null
* @return the url connection with auth if required. Don't check the certificate if SSL scheme.
* @throws IOException if any
*/
private static URLConnection getURLConnection(URL url, MavenProject project, Settings settings) throws IOException {
URLConnection conn = url.openConnection();
conn.setConnectTimeout(TIMEOUT);
conn.setReadTimeout(TIMEOUT);
//@formatter:off
if (settings.getServers() != null && !settings.getServers().isEmpty() && project != null && project.getDistributionManagement() != null && (project.getDistributionManagement().getRepository() != null || project.getDistributionManagement().getSnapshotRepository() != null) && (StringUtils.isNotEmpty(project.getDistributionManagement().getRepository().getUrl()) || StringUtils.isNotEmpty(project.getDistributionManagement().getSnapshotRepository().getUrl()))) //@formatter:on
{
Server server = null;
if (url.toString().contains(project.getDistributionManagement().getRepository().getUrl())) {
server = settings.getServer(project.getDistributionManagement().getRepository().getId());
}
if (server == null && url.toString().contains(project.getDistributionManagement().getSnapshotRepository().getUrl())) {
server = settings.getServer(project.getDistributionManagement().getSnapshotRepository().getId());
}
if (server != null && StringUtils.isNotEmpty(server.getUsername()) && StringUtils.isNotEmpty(server.getPassword())) {
String up = server.getUsername().trim() + ":" + server.getPassword().trim();
String upEncoded = new String(Base64.encodeBase64Chunked(up.getBytes())).trim();
conn.setRequestProperty("Authorization", "Basic " + upEncoded);
}
}
if (conn instanceof HttpsURLConnection) {
HostnameVerifier hostnameverifier = new HostnameVerifier() {
/** {@inheritDoc} */
public boolean verify(String urlHostName, SSLSession session) {
return true;
}
};
((HttpsURLConnection) conn).setHostnameVerifier(hostnameverifier);
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
/** {@inheritDoc} */
public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
}
/** {@inheritDoc} */
public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
}
/** {@inheritDoc} */
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
try {
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
((HttpsURLConnection) conn).setSSLSocketFactory(sslSocketFactory);
} catch (NoSuchAlgorithmException e1) {
// ignore
} catch (KeyManagementException e) {
// ignore
}
}
return conn;
}
Aggregations