Skip to content

Commit

Permalink
Use user-provided SSLContext to create secure socket
Browse files Browse the repository at this point in the history
  • Loading branch information
BARCO\FIRDU authored and Cyrille Le Clerc committed Jan 15, 2019
1 parent 18f5923 commit 4527935
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class TcpSyslogMessageSender extends AbstractSyslogMessageSender implemen
private Writer writer;
private int socketConnectTimeoutInMillis = SETTING_SOCKET_CONNECT_TIMEOUT_IN_MILLIS_DEFAULT_VALUE;
private boolean ssl;
private SSLContext sslContext;
/**
* Number of retries to send a message before throwing an exception.
*/
Expand Down Expand Up @@ -144,7 +146,11 @@ private synchronized void ensureSyslogServerConnection() throws IOException {
writer = null;
try {
if (ssl) {
socket = SSLSocketFactory.getDefault().createSocket();
if(sslContext == null) {
socket = SSLSocketFactory.getDefault().createSocket();
} else {
socket = sslContext.getSocketFactory().createSocket();
}
} else {
socket = SocketFactory.getDefault().createSocket();
}
Expand Down Expand Up @@ -226,6 +232,14 @@ public boolean isSsl() {
public void setSsl(boolean ssl) {
this.ssl = ssl;
}

public synchronized void setSSLContext(SSLContext sslContext) {
this.sslContext = sslContext;
}

public synchronized SSLContext getSSLContext() {
return this.sslContext;
}

public int getSocketConnectTimeoutInMillis() {
return socketConnectTimeoutInMillis;
Expand Down

0 comments on commit 4527935

Please sign in to comment.