use of javax.net.ssl.SSLHandshakeException in project wildfly by wildfly.
the class HTTPSWebConnectorTestCase method testNonVerifyingConnector.
/**
* @test.tsfi tsfi.keystore.file
* @test.tsfi tsfi.truststore.file
* @test.objective Testing default HTTPs connector with verify-client attribute set to "false". The CLIENT-CERT
* authentication (BaseCertLoginModule) is configured for this test. Trusted client is allowed to access
* both secured/unsecured resource. Untrusted client can only access unprotected resources.
* @test.expectedResult Trusted client has access to protected and unprotected resources. Untrusted client has only access
* to unprotected resources.
* @throws Exception
*/
@Test
@InSequence(1)
public void testNonVerifyingConnector() throws Exception {
Assume.assumeFalse(SystemUtils.IS_JAVA_1_6 && SystemUtils.JAVA_VENDOR.toUpperCase(Locale.ENGLISH).contains("IBM"));
final URL printPrincipalUrl = getServletUrl(HTTPS_PORT_VERIFY_FALSE, PrincipalPrintingServlet.SERVLET_PATH);
final URL securedUrl = getServletUrl(HTTPS_PORT_VERIFY_FALSE, SECURED_SERVLET_WITH_SESSION);
final URL unsecuredUrl = getServletUrl(HTTPS_PORT_VERIFY_FALSE, SimpleServlet.SERVLET_PATH);
final HttpClient httpClient = getHttpClient(CLIENT_KEYSTORE_FILE);
final HttpClient httpClientUntrusted = getHttpClient(UNTRUSTED_KEYSTORE_FILE);
try {
makeCallWithHttpClient(printPrincipalUrl, httpClient, HttpServletResponse.SC_FORBIDDEN);
String responseBody = makeCallWithHttpClient(securedUrl, httpClient, HttpServletResponse.SC_OK);
assertEquals("Secured page was not reached", SimpleSecuredServlet.RESPONSE_BODY, responseBody);
String principal = makeCallWithHttpClient(printPrincipalUrl, httpClient, HttpServletResponse.SC_OK);
assertEquals("Unexpected principal", "cn=client", principal.toLowerCase());
responseBody = makeCallWithHttpClient(unsecuredUrl, httpClientUntrusted, HttpServletResponse.SC_OK);
assertEquals("Secured page was not reached", SimpleServlet.RESPONSE_BODY, responseBody);
try {
makeCallWithHttpClient(securedUrl, httpClientUntrusted, HttpServletResponse.SC_FORBIDDEN);
} catch (SSLHandshakeException e) {
// OK
} catch (java.net.SocketException se) {
// OK - on windows usually fails with this one
}
} finally {
httpClient.getConnectionManager().shutdown();
httpClientUntrusted.getConnectionManager().shutdown();
}
}
use of javax.net.ssl.SSLHandshakeException in project intellij-community by JetBrains.
the class GithubConnection method doRequest.
@NotNull
private ResponsePage doRequest(@NotNull String uri, @Nullable String requestBody, @NotNull Collection<Header> headers, @NotNull HttpVerb verb) throws IOException {
if (myAborted)
throw new GithubOperationCanceledException();
if (EventQueue.isDispatchThread() && !ApplicationManager.getApplication().isUnitTestMode()) {
// TODO: fix
LOG.warn("Network operation in EDT");
}
CloseableHttpResponse response = null;
try {
response = doREST(uri, requestBody, headers, verb);
if (myAborted)
throw new GithubOperationCanceledException();
checkStatusCode(response, requestBody);
HttpEntity entity = response.getEntity();
if (entity == null) {
return createResponse(response);
}
JsonElement ret = parseResponse(entity.getContent());
if (ret.isJsonNull()) {
return createResponse(response);
}
String nextPage = null;
Header pageHeader = response.getFirstHeader("Link");
if (pageHeader != null) {
for (HeaderElement element : pageHeader.getElements()) {
NameValuePair rel = element.getParameterByName("rel");
if (rel != null && "next".equals(rel.getValue())) {
String urlString = element.toString();
int begin = urlString.indexOf('<');
int end = urlString.lastIndexOf('>');
if (begin == -1 || end == -1) {
LOG.error("Invalid 'Link' header", "{" + pageHeader.toString() + "}");
break;
}
nextPage = urlString.substring(begin + 1, end);
break;
}
}
}
return createResponse(ret, nextPage, response);
} catch (SSLHandshakeException e) {
// User canceled operation from CertificateManager
if (e.getCause() instanceof CertificateException) {
LOG.info("Host SSL certificate is not trusted", e);
throw new GithubOperationCanceledException("Host SSL certificate is not trusted", e);
}
throw e;
} catch (IOException e) {
if (myAborted)
throw new GithubOperationCanceledException("Operation canceled", e);
throw e;
} finally {
myRequest = null;
if (response != null) {
response.close();
}
if (!myReusable) {
myClient.close();
}
}
}
use of javax.net.ssl.SSLHandshakeException in project geode by apache.
the class LauncherLifecycleCommands method doAutoConnect.
private boolean doAutoConnect(final String locatorHostname, final int locatorPort, final String gemfirePropertiesPathname, final String gemfireSecurityPropertiesPathname, final InfoResultData infoResultData) {
boolean connectSuccess = false;
boolean jmxManagerAuthEnabled = false;
boolean jmxManagerSslEnabled = false;
Map<String, String> configurationProperties = loadConfigurationProperties(gemfireSecurityPropertiesPathname, loadConfigurationProperties(gemfirePropertiesPathname));
Map<String, String> locatorConfigurationProperties = new HashMap<>(configurationProperties);
String responseFailureMessage = null;
for (int attempts = 0; (attempts < 10 && !connectSuccess); attempts++) {
try {
ConnectToLocatorResult connectToLocatorResult = ShellCommands.connectToLocator(locatorHostname, locatorPort, ShellCommands.getConnectLocatorTimeoutInMS() / 4, locatorConfigurationProperties);
ConnectionEndpoint memberEndpoint = connectToLocatorResult.getMemberEndpoint();
jmxManagerSslEnabled = connectToLocatorResult.isJmxManagerSslEnabled();
if (!jmxManagerSslEnabled) {
configurationProperties.clear();
}
getGfsh().setOperationInvoker(new JmxOperationInvoker(memberEndpoint.getHost(), memberEndpoint.getPort(), null, null, configurationProperties, null));
String shellAndLogMessage = CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, "JMX Manager " + memberEndpoint.toString(false));
infoResultData.addLine("\n");
infoResultData.addLine(shellAndLogMessage);
getGfsh().logToFile(shellAndLogMessage, null);
connectSuccess = true;
responseFailureMessage = null;
} catch (IllegalStateException unexpected) {
if (CauseFinder.indexOfCause(unexpected, ClassCastException.class, false) != -1) {
responseFailureMessage = "The Locator might require SSL Configuration.";
}
} catch (SecurityException ignore) {
getGfsh().logToFile(ignore.getMessage(), ignore);
jmxManagerAuthEnabled = true;
// no need to continue after SecurityException
break;
} catch (AuthenticationFailedException ignore) {
getGfsh().logToFile(ignore.getMessage(), ignore);
jmxManagerAuthEnabled = true;
// no need to continue after AuthenticationFailedException
break;
} catch (SSLException ignore) {
if (ignore instanceof SSLHandshakeException) {
// try to connect again without SSL since the SSL handshake failed implying a plain text
// connection...
locatorConfigurationProperties.clear();
} else {
// another type of SSL error occurred (possibly a configuration issue); pass the buck...
getGfsh().logToFile(ignore.getMessage(), ignore);
responseFailureMessage = "Check your SSL configuration and try again.";
break;
}
} catch (Exception ignore) {
getGfsh().logToFile(ignore.getMessage(), ignore);
responseFailureMessage = "Failed to connect; unknown cause: " + ignore.getMessage();
}
}
if (!connectSuccess) {
doOnConnectionFailure(locatorHostname, locatorPort, jmxManagerAuthEnabled, jmxManagerSslEnabled, infoResultData);
}
if (StringUtils.isNotBlank(responseFailureMessage)) {
infoResultData.addLine("\n");
infoResultData.addLine(responseFailureMessage);
}
return connectSuccess;
}
use of javax.net.ssl.SSLHandshakeException in project cloudstack by apache.
the class ElastistorUtil method getElastistorRestClient.
/**
* This intializes a new jersey restclient for http call with elasticenter
*/
public static ElastiCenterClient getElastistorRestClient() {
ElastiCenterClient restclient = null;
try {
String ip = getConfigurationDao().getValue("cloudbyte.management.ip");
String apikey = getConfigurationDao().getValue("cloudbyte.management.apikey");
if (ip == null) {
throw new CloudRuntimeException("set the value of cloudbyte.management.ip in global settings");
}
if (apikey == null) {
throw new CloudRuntimeException("set the value of cloudbyte.management.apikey in global settings");
}
restclient = new ElastiCenterClient(ip, apikey);
} catch (InvalidCredentialsException e) {
throw new CloudRuntimeException("InvalidCredentialsException:" + e.getMessage(), e);
} catch (InvalidParameterException e) {
throw new CloudRuntimeException("InvalidParameterException:" + e.getMessage(), e);
} catch (SSLHandshakeException e) {
throw new CloudRuntimeException("SSLHandshakeException:" + e.getMessage(), e);
} catch (ServiceUnavailableException e) {
throw new CloudRuntimeException("ServiceUnavailableException:" + e.getMessage(), e);
}
return restclient;
}
use of javax.net.ssl.SSLHandshakeException in project platform_external_apache-http by android.
the class CertificateChainValidator method closeSocketThrowException.
private void closeSocketThrowException(SSLSocket socket, String errorMessage) throws IOException {
if (HttpLog.LOGV) {
HttpLog.v("validation error: " + errorMessage);
}
if (socket != null) {
SSLSession session = socket.getSession();
if (session != null) {
session.invalidate();
}
socket.close();
}
throw new SSLHandshakeException(errorMessage);
}
Aggregations