Skip to content

Commit 0457a66

Browse files
committed
ssl verification skip
1 parent 49894b8 commit 0457a66

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

api/src/main/java/io/kafbat/ui/KafkaUiApplication.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.kafbat.ui;
22

3+
import io.kafbat.ui.service.ssl.SkipSecurityProvider;
34
import io.kafbat.ui.util.DynamicConfigOperations;
5+
import java.security.Security;
46
import org.springframework.boot.autoconfigure.SpringBootApplication;
57
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
68
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -18,6 +20,7 @@ public static void main(String[] args) {
1820
}
1921

2022
public static ConfigurableApplicationContext startApplication(String[] args) {
23+
Security.addProvider(new SkipSecurityProvider());
2124
return new SpringApplicationBuilder(KafkaUiApplication.class)
2225
.initializers(DynamicConfigOperations.dynamicConfigPropertiesInitializer())
2326
.build()

api/src/main/java/io/kafbat/ui/serdes/builtin/sr/SchemaRegistrySerde.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.kafbat.ui.serde.api.PropertyResolver;
2525
import io.kafbat.ui.serde.api.SchemaDescription;
2626
import io.kafbat.ui.serdes.BuiltInSerde;
27+
import io.kafbat.ui.service.ssl.SkipSecurityProvider;
2728
import io.kafbat.ui.util.jsonschema.AvroJsonSchemaConverter;
2829
import io.kafbat.ui.util.jsonschema.ProtobufSchemaConverter;
2930
import java.net.URI;
@@ -34,6 +35,7 @@
3435
import java.util.Optional;
3536
import java.util.concurrent.Callable;
3637
import javax.annotation.Nullable;
38+
import javax.net.ssl.TrustManagerFactory;
3739
import lombok.SneakyThrows;
3840
import org.apache.kafka.common.config.SslConfigs;
3941

@@ -80,7 +82,8 @@ public void autoConfigure(PropertyResolver kafkaClusterProperties,
8082
kafkaClusterProperties.getProperty("schemaRegistrySsl.keystoreLocation", String.class).orElse(null),
8183
kafkaClusterProperties.getProperty("schemaRegistrySsl.keystorePassword", String.class).orElse(null),
8284
kafkaClusterProperties.getProperty("ssl.truststoreLocation", String.class).orElse(null),
83-
kafkaClusterProperties.getProperty("ssl.truststorePassword", String.class).orElse(null)
85+
kafkaClusterProperties.getProperty("ssl.truststorePassword", String.class).orElse(null),
86+
kafkaClusterProperties.getProperty("ssl.verifySsl", Boolean.class).orElse(true)
8487
),
8588
kafkaClusterProperties.getProperty("schemaRegistryKeySchemaNameTemplate", String.class).orElse("%s-key"),
8689
kafkaClusterProperties.getProperty("schemaRegistrySchemaNameTemplate", String.class).orElse("%s-value"),
@@ -106,7 +109,8 @@ public void configure(PropertyResolver serdeProperties,
106109
serdeProperties.getProperty("keystoreLocation", String.class).orElse(null),
107110
serdeProperties.getProperty("keystorePassword", String.class).orElse(null),
108111
kafkaClusterProperties.getProperty("ssl.truststoreLocation", String.class).orElse(null),
109-
kafkaClusterProperties.getProperty("ssl.truststorePassword", String.class).orElse(null)
112+
kafkaClusterProperties.getProperty("ssl.truststorePassword", String.class).orElse(null),
113+
kafkaClusterProperties.getProperty("ssl.verifySsl", Boolean.class).orElse(true)
110114
),
111115
serdeProperties.getProperty("keySchemaNameTemplate", String.class).orElse("%s-key"),
112116
serdeProperties.getProperty("schemaNameTemplate", String.class).orElse("%s-value"),
@@ -136,7 +140,9 @@ private static SchemaRegistryClient createSchemaRegistryClient(List<String> urls
136140
@Nullable String keyStoreLocation,
137141
@Nullable String keyStorePassword,
138142
@Nullable String trustStoreLocation,
139-
@Nullable String trustStorePassword) {
143+
@Nullable String trustStorePassword,
144+
boolean verifySsl
145+
) {
140146
Map<String, String> configs = new HashMap<>();
141147
if (username != null && password != null) {
142148
configs.put(BASIC_AUTH_CREDENTIALS_SOURCE, "USER_INFO");
@@ -166,6 +172,13 @@ private static SchemaRegistryClient createSchemaRegistryClient(List<String> urls
166172
keyStorePassword);
167173
}
168174

175+
if (!verifySsl) {
176+
configs.put(
177+
SchemaRegistryClientConfig.CLIENT_NAMESPACE + SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG,
178+
SkipSecurityProvider.NAME
179+
);
180+
}
181+
169182
return new CachedSchemaRegistryClient(
170183
urls,
171184
1_000,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.kafbat.ui.service.ssl;
2+
3+
import java.security.Provider;
4+
5+
public class SkipSecurityProvider extends Provider {
6+
public static final String NAME = "Skip";
7+
8+
public SkipSecurityProvider() {
9+
super("SkipProvider", 1.0, "Skip TrustManagerFactory Provider");
10+
put("TrustManagerFactory."+NAME, "SkipTrustManagerFactorySpi");
11+
}
12+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.kafbat.ui.service.ssl;
2+
3+
import java.security.InvalidAlgorithmParameterException;
4+
import java.security.KeyStore;
5+
import java.security.KeyStoreException;
6+
import java.security.cert.X509Certificate;
7+
import javax.net.ssl.ManagerFactoryParameters;
8+
import javax.net.ssl.TrustManager;
9+
import javax.net.ssl.X509TrustManager;
10+
11+
public class SkipTrustManagerFactorySpi extends javax.net.ssl.TrustManagerFactorySpi {
12+
13+
private final TrustManager[] trustAllCertificates;
14+
15+
public SkipTrustManagerFactorySpi() {
16+
this.trustAllCertificates = new TrustManager[]{
17+
new X509TrustManager() {
18+
public X509Certificate[] getAcceptedIssuers() { return null; }
19+
public void checkClientTrusted(X509Certificate[] certs, String authType) { }
20+
public void checkServerTrusted(X509Certificate[] certs, String authType) { }
21+
}
22+
};
23+
}
24+
25+
@Override
26+
protected void engineInit(KeyStore ks) throws KeyStoreException {
27+
28+
}
29+
30+
@Override
31+
protected void engineInit(ManagerFactoryParameters spec)
32+
throws InvalidAlgorithmParameterException {
33+
34+
}
35+
36+
@Override
37+
protected TrustManager[] engineGetTrustManagers() {
38+
return trustAllCertificates;
39+
}
40+
}

0 commit comments

Comments
 (0)