77import org .apache .commons .io .FilenameUtils ;
88import org .apache .http .HttpHost ;
99import org .apache .http .HttpRequestInterceptor ;
10- import org .apache .jmeter .JMeter ;
10+ import org .apache .http .conn .ssl .NoopHostnameVerifier ;
11+ import org .apache .http .ssl .SSLContextBuilder ;
12+ import org .apache .http .ssl .TrustStrategy ;
1113import org .apache .jmeter .config .Arguments ;
1214import org .apache .jmeter .samplers .SampleResult ;
1315import org .apache .jmeter .util .JMeterUtils ;
2527import com .google .gson .Gson ;
2628
2729public class ElasticsearchBackendClient extends AbstractBackendListenerClient {
30+
2831 private static final String BUILD_NUMBER = "BuildNumber" ;
2932 private static final String ES_SCHEME = "es.scheme" ;
3033 private static final String ES_HOST = "es.host" ;
@@ -46,6 +49,7 @@ public class ElasticsearchBackendClient extends AbstractBackendListenerClient {
4649 private static final String ES_SSL_TRUSTSTORE_PW = "es.ssl.truststore.pw" ;
4750 private static final String ES_SSL_KEYSTORE_PATH = "es.ssl.keystore.path" ;
4851 private static final String ES_SSL_KEYSTORE_PW = "es.ssl.keystore.pw" ;
52+ private static final String ES_SSL_VERIFICATION_MODE = "es.ssl.verificationMode" ;
4953 private static final long DEFAULT_TIMEOUT_MS = 200L ;
5054 private static final String SERVICE_NAME = "es" ;
5155 private static RestClient client ;
@@ -73,6 +77,7 @@ public class ElasticsearchBackendClient extends AbstractBackendListenerClient {
7377 DEFAULT_ARGS .put (ES_SSL_TRUSTSTORE_PW , "" );
7478 DEFAULT_ARGS .put (ES_SSL_KEYSTORE_PATH , "" );
7579 DEFAULT_ARGS .put (ES_SSL_KEYSTORE_PW , "" );
80+ DEFAULT_ARGS .put (ES_SSL_VERIFICATION_MODE , "full" );
7681 }
7782 private ElasticSearchMetricSender sender ;
7883 private Set <String > modes ;
@@ -83,9 +88,7 @@ public class ElasticsearchBackendClient extends AbstractBackendListenerClient {
8388 private int esVersion ;
8489 private long timeoutMs ;
8590
86- public ElasticsearchBackendClient () {
87- super ();
88- }
91+ private static final TrustStrategy TRUST_ALL_STRATEGY = (chain , authType ) -> true ;
8992
9093 @ Override
9194 public Arguments getDefaultParameters () {
@@ -112,6 +115,22 @@ public void setupTest(BackendListenerContext context) throws Exception {
112115 client = RestClient
113116 .builder (new HttpHost (context .getParameter (ES_HOST ),
114117 Integer .parseInt (context .getParameter (ES_PORT )), context .getParameter (ES_SCHEME )))
118+ .setHttpClientConfigCallback (httpAsyncClientBuilder -> {
119+ if (context .getParameter (ES_SSL_VERIFICATION_MODE ).equalsIgnoreCase ("none" )) {
120+ logger .info ("Will trust all remote SSL certificates." );
121+ final SSLContextBuilder contextBuilder = new SSLContextBuilder ();
122+ try {
123+ contextBuilder .loadTrustMaterial (TRUST_ALL_STRATEGY );
124+ httpAsyncClientBuilder .setSSLContext (contextBuilder .build ());
125+ httpAsyncClientBuilder .setSSLHostnameVerifier (NoopHostnameVerifier .INSTANCE );
126+ }
127+ catch (Exception e ) {
128+ // NOTE: purposedly ignored as this strategy does not use any custom algorithm
129+ // or certificate
130+ }
131+ }
132+ return httpAsyncClientBuilder ;
133+ })
115134 .setRequestConfigCallback (requestConfigBuilder -> requestConfigBuilder .setConnectTimeout (5000 )
116135 .setSocketTimeout ((int ) timeoutMs ))
117136 .setFailureListener (new RestClient .FailureListener () {
0 commit comments