Skip to content

Commit

Permalink
Fix for issue with --noVerify not working. (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
nemonster authored Oct 16, 2019
1 parent 60865ff commit d7612f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.elasticsearch</groupId>
<artifactId>support-diagnostics</artifactId>
<version>7.1.0</version>
<version>7.1.1</version>
<packaging>jar</packaging>
<name>Support Diagnostics Utilities</name>
<properties>
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/com/elastic/support/ElasticClientService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,14 @@ protected RestClient createEsRestClient(BaseConfig config, ElasticClientInputs i
builder.setBypassVerify(inputs.isSkipVerification())
.setHost(inputs.getHost())
.setPort(inputs.getPort())
.setScheme(inputs.getScheme());



builder
.setScheme(inputs.getScheme())
.setConnectTimeout(config.getRestConfig().get("connectTimeout") * 1000)
.setRequestTimeout(config.getRestConfig().get("requestTimeout") * 1000)
.setSocketTimeout(config.getRestConfig().get("socketTimeout") * 1000)
.setProxyHost(inputs.getProxyUser())
.setProxPort(inputs.getProxyPort())
.setProxyUser(inputs.getUser())
.setProxyPass(inputs.getProxyPassword())
.setBypassVerify(inputs.isSkipVerification());

.setProxyPass(inputs.getProxyPassword());

if (inputs.isSecured()) {
builder.setUser(inputs.getUser())
Expand All @@ -60,11 +54,7 @@ RestClientBuilder setupBuilder(BaseConfig config, ElasticClientInputs inputs){
return builder
.setConnectTimeout(config.getRestConfig().get("connectTimeout") * 1000)
.setRequestTimeout(config.getRestConfig().get("requestTimeout") * 1000)
.setSocketTimeout(config.getRestConfig().get("socketTimeout") * 1000)
.setProxyHost(inputs.getProxyUser())
.setProxPort(inputs.getProxyPort())
.setProxyUser(inputs.getUser())
.setProxyPass(inputs.getProxyPassword());
.setSocketTimeout(config.getRestConfig().get("socketTimeout") * 1000);
}


Expand Down
34 changes: 27 additions & 7 deletions src/main/java/com/elastic/support/rest/RestClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
Expand Down Expand Up @@ -186,9 +188,19 @@ public RestClient build() {
}

SSLContext sslCtx = sslContextBuilder.build();
SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslCtx);
//SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslCtx);
clientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslCtx));

SSLConnectionSocketFactory factory = null;
if (bypassVerify) {
factory = new SSLConnectionSocketFactory(sslCtx, NoopHostnameVerifier.INSTANCE);
clientBuilder.setSSLSocketFactory(factory);
}
else{
factory = new SSLConnectionSocketFactory(sslCtx);
clientBuilder.setSSLSocketFactory(factory);
}

// If and when we start making connections to multinple nodes this will
// need to be turned on. Note that we need to create a registry for socket factories
// for both http and https or pooling will not work.
Expand All @@ -202,12 +214,7 @@ public RestClient build() {
clientBuilder.setConnectionManager(mgr);
}

if (bypassVerify) {
clientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslCtx, new NoopHostnameVerifier()));
}
else{
clientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslCtx));
}

}
catch (Exception e){
logger.log(SystemProperties.DIAG, "Connection setup failed", e);
Expand Down Expand Up @@ -259,5 +266,18 @@ public RestClient build() {

}

/**
* This overrides any hostname mismatch in the certificate
*/
private class BypassHostnameVerifier implements HostnameVerifier {

public boolean verify(String hostname, SSLSession session) {
return true;
}

}

}



0 comments on commit d7612f0

Please sign in to comment.