Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit ce199da

Browse files
committed
More options for configuring TLS client auth
1 parent f6d19f1 commit ce199da

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ attribute:
5454

5555
See property files in conf/
5656

57+
## TLS/SSL Transport
58+
59+
kafka-websocket can be configured to support TLS transport between client and server (not from kafka-websocket to kafka). Client certificates
60+
can also be used, if desired. Client auth can be set to none, optional, or required, each being, I hope, self-explanatory. See
61+
conf/server.properties for various configuration options.
62+
5763
## License
5864

5965
kafka-websocket is copyright 2014 Benjamin Black, and distributed under the Apache License 2.0.

conf/server.properties

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ ws.ssl=false
55
ws.ssl.port=7443
66
ws.ssl.keyStorePath=conf/keystore
77
ws.ssl.keyStorePassword=password
8+
ws.ssl.trustStorePath=conf/keystore
9+
ws.ssl.trustStorePassword=password
810
ws.ssl.protocols=TLSv1.2
911
ws.ssl.ciphers=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_RC4_128_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
10-
ws.ssl.clientAuth=false
12+
ws.ssl.clientAuth=none

src/main/java/us/b3k/kafka/ws/KafkaWebsocketServer.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ public KafkaWebsocketServer(Properties wsProps, Properties consumerProps, Proper
4646
}
4747

4848
private SslContextFactory newSslContextFactory() {
49+
LOG.info("Configuring TLS.");
4950
String keyStorePath = wsProps.getProperty("ws.ssl.keyStorePath");
5051
String keyStorePassword = wsProps.getProperty("ws.ssl.keyStorePassword");
5152
String trustStorePath = wsProps.getProperty("ws.ssl.trustStorePath", keyStorePath);
5253
String trustStorePassword = wsProps.getProperty("ws.ssl.trustStorePassword", keyStorePassword);
5354
String[] protocols = wsProps.getProperty("ws.ssl.protocols", DEFAULT_PROTOCOLS).split(",");
5455
String[] ciphers = wsProps.getProperty("ws.ssl.ciphers", DEFAULT_CIPHERS).split(",");
55-
Boolean clientAuth = Boolean.parseBoolean(wsProps.getProperty("ws.ssl.clientAuth", "false"));
56+
String clientAuth = wsProps.getProperty("ws.ssl.clientAuth", "none");
5657

5758
SslContextFactory sslContextFactory = new SslContextFactory();
5859
sslContextFactory.setKeyStorePath(keyStorePath);
@@ -62,8 +63,23 @@ private SslContextFactory newSslContextFactory() {
6263
sslContextFactory.setTrustStorePassword(trustStorePassword);
6364
sslContextFactory.setIncludeProtocols(protocols);
6465
sslContextFactory.setIncludeCipherSuites(ciphers);
65-
sslContextFactory.setNeedClientAuth(clientAuth);
66-
sslContextFactory.setValidatePeerCerts(clientAuth);
66+
switch(clientAuth) {
67+
case "required":
68+
LOG.info("Client auth required.");
69+
sslContextFactory.setNeedClientAuth(true);
70+
sslContextFactory.setValidatePeerCerts(true);
71+
break;
72+
case "optional":
73+
LOG.info("Client auth allowed.");
74+
sslContextFactory.setWantClientAuth(true);
75+
sslContextFactory.setValidatePeerCerts(true);
76+
break;
77+
default:
78+
LOG.info("Client auth disabled.");
79+
sslContextFactory.setNeedClientAuth(false);
80+
sslContextFactory.setWantClientAuth(false);
81+
sslContextFactory.setValidatePeerCerts(false);
82+
}
6783
return sslContextFactory;
6884
}
6985

0 commit comments

Comments
 (0)