Skip to content

Commit

Permalink
Also disable hostname verification when connection wants to ignore SSL
Browse files Browse the repository at this point in the history
Signed-off-by: Yannic Klem <yannic.klem@bosch.io>
  • Loading branch information
Yannic92 committed Nov 26, 2021
1 parent cb9ed21 commit 6861754
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import java.util.Optional;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;

import javax.annotation.Nullable;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;

import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.connectivity.model.Connection;
Expand Down Expand Up @@ -103,7 +103,16 @@ static HttpPushFactory of(final Connection connection, final HttpPushConfig http
final SSLContext sslContext = connection.getCredentials()
.map(credentials -> credentials.accept(sslContextCreator))
.orElse(sslContextCreator.withoutClientCertificate());
httpsConnectionContext = ConnectionContext.httpsClient(sslContext);
if (connection.isValidateCertificates()) {
httpsConnectionContext = ConnectionContext.httpsClient(sslContext);
} else {
httpsConnectionContext = ConnectionContext.httpsClient((host, port) -> {
// This creates an SSL Engine without hostname verification.
final SSLEngine engine = sslContext.createSSLEngine(host, port);
engine.setUseClientMode(true);
return engine;
});
}
} else {
httpsConnectionContext = null;
}
Expand Down

0 comments on commit 6861754

Please sign in to comment.