Skip to content

Commit

Permalink
Enable TLS Client Authentication on WebSocketProxy and DiscoveryServi…
Browse files Browse the repository at this point in the history
…ce (apache#535)
  • Loading branch information
nkurihar authored and merlimat committed Jun 30, 2017
1 parent 1994f4f commit b86f7bb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,17 @@ protected void initChannel(SocketChannel ch) throws Exception {
File tlsCert = new File(serviceConfig.getTlsCertificateFilePath());
File tlsKey = new File(serviceConfig.getTlsKeyFilePath());
SslContextBuilder builder = SslContextBuilder.forServer(tlsCert, tlsKey);
// allows insecure connection
builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
if (serviceConfig.isTlsAllowInsecureConnection()) {
builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
} else {
if (serviceConfig.getTlsTrustCertsFilePath().isEmpty()) {
// Use system default
builder.trustManager((File) null);
} else {
File trustCertCollection = new File(serviceConfig.getTlsTrustCertsFilePath());
builder.trustManager(trustCertCollection);
}
}
SslContext sslCtx = builder.clientAuth(ClientAuth.OPTIONAL).build();
ch.pipeline().addLast(TLS_HANDLER, sslCtx.newHandler(ch.alloc()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ public ServerManager(ServiceConfig config) {
if (config.isTlsEnabled()) {
SslContextFactory sslCtxFactory = new SslContextFactory();
try {
SSLContext sslCtx = SecurityUtility.createSslContext(false, null, config.getTlsCertificateFilePath(),
SSLContext sslCtx = SecurityUtility.createSslContext(config.isTlsAllowInsecureConnection(), config.getTlsTrustCertsFilePath(), config.getTlsCertificateFilePath(),
config.getTlsKeyFilePath());
sslCtxFactory.setSslContext(sslCtx);
} catch (GeneralSecurityException e) {
throw new RestException(e);
}

sslCtxFactory.setWantClientAuth(false);
sslCtxFactory.setWantClientAuth(true);
ServerConnector tlsConnector = new ServerConnector(server, 1, 1, sslCtxFactory);
tlsConnector.setPort(config.getWebServicePortTls());
connectors.add(tlsConnector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public class ServiceConfig implements PulsarConfiguration {
private String tlsCertificateFilePath;
// Path for the TLS private key file
private String tlsKeyFilePath;
// Path for the trusted TLS certificate file
private String tlsTrustCertsFilePath = "";
// Accept untrusted TLS certificate from client
private boolean tlsAllowInsecureConnection = false;

private Properties properties = new Properties();

Expand Down Expand Up @@ -153,6 +157,22 @@ public void setTlsKeyFilePath(String tlsKeyFilePath) {
this.tlsKeyFilePath = tlsKeyFilePath;
}

public String getTlsTrustCertsFilePath() {
return tlsTrustCertsFilePath;
}

public void setTlsTrustCertsFilePath(String tlsTrustCertsFilePath) {
this.tlsTrustCertsFilePath = tlsTrustCertsFilePath;
}

public boolean isTlsAllowInsecureConnection() {
return tlsAllowInsecureConnection;
}

public void setTlsAllowInsecureConnection(boolean tlsAllowInsecureConnection) {
this.tlsAllowInsecureConnection = tlsAllowInsecureConnection;
}

public boolean isBindOnLocalhost() {
return bindOnLocalhost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ProxyServer(WebSocketProxyConfiguration config)
if (config.isTlsEnabled()) {
SslContextFactory sslCtxFactory = new SslContextFactory(true);
try {
SSLContext sslCtx = SecurityUtility.createSslContext(false, null, config.getTlsCertificateFilePath(),
SSLContext sslCtx = SecurityUtility.createSslContext(false, config.getTlsTrustCertsFilePath(), config.getTlsCertificateFilePath(),
config.getTlsKeyFilePath());
sslCtxFactory.setSslContext(sslCtx);

Expand Down

0 comments on commit b86f7bb

Please sign in to comment.