diff --git a/.travis.yml b/.travis.yml index 7957a82..b179f30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ language: java jdk: - - oraclejdk8 - - openjdk7 + - openjdk8 diff --git a/client/src/main/java/org/smpp/client/SMPPSender.java b/client/src/main/java/org/smpp/client/SMPPSender.java index 3581220..2595242 100644 --- a/client/src/main/java/org/smpp/client/SMPPSender.java +++ b/client/src/main/java/org/smpp/client/SMPPSender.java @@ -8,7 +8,9 @@ import java.util.Properties; import java.util.StringTokenizer; +import org.smpp.Connection; import org.smpp.Data; +import org.smpp.SSLConnection; import org.smpp.Session; import org.smpp.TCPIPConnection; import org.smpp.pdu.Address; @@ -56,6 +58,11 @@ public class SMPPSender { */ boolean bound = false; + /** + * If application should use TLS. + */ + private static boolean useTLS = false; + /** * Address of the SMSC. */ @@ -155,6 +162,8 @@ public static void main(String args[]) { message = args[++i]; } else if(opt.compareToIgnoreCase("file") == 0) { propsFilePath = args[++i]; + } else if(opt.compareToIgnoreCase("tls") == 0) { + useTLS = true; } } } @@ -224,7 +233,12 @@ private void bind() { request = new BindTransmitter(); - TCPIPConnection connection = new TCPIPConnection(ipAddress, port); + Connection connection; + if(useTLS) { + connection = new SSLConnection(ipAddress, port); + } else { + connection = new TCPIPConnection(ipAddress, port); + } connection.setReceiveTimeout(20 * 1000); session = new Session(connection); diff --git a/core/src/main/java/org/smpp/Connection.java b/core/src/main/java/org/smpp/Connection.java index 150cfd9..5ee8341 100644 --- a/core/src/main/java/org/smpp/Connection.java +++ b/core/src/main/java/org/smpp/Connection.java @@ -15,6 +15,8 @@ import org.smpp.Data; import org.smpp.util.ByteBuffer; +import javax.net.SocketFactory; + /** * Abstract class defining necessary abstract methods for communication * over socket based network communication interface. It defines methods @@ -176,6 +178,12 @@ public synchronized int getConnectionTimeout() { public String getAddress() { return address; } + + /** + * Create method to get SocketFactory to override the variable hiding + * in SSLConnection. Use to get SSLSocketFactory instead of defaultSocketFactory + */ + public abstract SocketFactory getSocketFactory(); } /* diff --git a/core/src/main/java/org/smpp/SSLConnection.java b/core/src/main/java/org/smpp/SSLConnection.java index 808d182..f1828d7 100644 --- a/core/src/main/java/org/smpp/SSLConnection.java +++ b/core/src/main/java/org/smpp/SSLConnection.java @@ -67,4 +67,20 @@ public SSLConnection(String address, int port) { public SSLConnection(SSLSocket sslsocket) throws IOException { super(sslsocket); } + + /** + * Create method to get SocketFactory to override the variable hiding + * in SSLConnection. Use to get SSLSocketFactory instead of defaultSocketFactory + */ + public SocketFactory getSocketFactory() { + return this.socketFactory; + } + + /** + * Create method to get SocketFactory to override the variable hiding + * in SSLConnection. Use to get SSLSocketFactory instead of defaultServerSocketFactory + */ + public ServerSocketFactory getServerSocketFactory() { + return this.serverSocketFactory; + } } diff --git a/core/src/main/java/org/smpp/TCPIPConnection.java b/core/src/main/java/org/smpp/TCPIPConnection.java index c6063b6..301532d 100644 --- a/core/src/main/java/org/smpp/TCPIPConnection.java +++ b/core/src/main/java/org/smpp/TCPIPConnection.java @@ -24,6 +24,8 @@ import javax.net.ServerSocketFactory; import javax.net.SocketFactory; +import javax.net.ssl.SSLSocket; +import sun.security.ssl.SSLSocketImpl; /** * Implementation of TCP/IP type of communication. @@ -243,7 +245,7 @@ public void open() throws IOException { if (!opened) { if (connType == CONN_CLIENT) { try { - socket = socketFactory.createSocket(); + socket = this.getSocketFactory().createSocket(); if( System.getProperty("bind.address") != null ) { socket.bind( new java.net.InetSocketAddress( java.net.InetAddress.getByName(System.getProperty("bind.address")), 0) ); } @@ -259,9 +261,9 @@ public void open() throws IOException { } else if (connType == CONN_SERVER) { try { if( System.getProperty("bind.address") == null ) { - receiverSocket = serverSocketFactory.createServerSocket(requestedPort); + receiverSocket = this.getServerSocketFactory().createServerSocket(requestedPort); } else { - receiverSocket = serverSocketFactory.createServerSocket(requestedPort, 0, java.net.InetAddress.getByName(System.getProperty("bind.address"))); + receiverSocket = this.getServerSocketFactory().createServerSocket(requestedPort, 0, java.net.InetAddress.getByName(System.getProperty("bind.address"))); } opened = true; this.port = receiverSocket.getLocalPort(); @@ -497,7 +499,12 @@ public Connection accept() throws IOException { } if (acceptedSocket != null) { try { - newConn = new TCPIPConnection(acceptedSocket); + if(acceptedSocket instanceof SSLSocket) { + newConn = new SSLConnection((SSLSocket)acceptedSocket); + } + else { + newConn = new TCPIPConnection(acceptedSocket); + } } catch (IOException e) { debug.write("IOException creating new client connection " + e); event.write(e, "IOException creating new client connection"); @@ -580,6 +587,23 @@ public boolean isOpened() { public int getPort() { return this.port; } + + /** + * Create method to get SocketFactory to override the variable hiding + * in SSLConnection. Use to get SSLSocketFactory instead of defaultSocketFactory + */ + public SocketFactory getSocketFactory() { + return this.socketFactory; + } + + /** + * Create method to get SocketFactory to override the variable hiding + * in SSLConnection. Use to get SSLSocketFactory instead of defaultSocketFactory + */ + public ServerSocketFactory getServerSocketFactory() { + return this.serverSocketFactory; + } + } /* * $Log: not supported by cvs2svn $ diff --git a/sim/src/main/java/org/smpp/smscsim/SMSCListenerImpl.java b/sim/src/main/java/org/smpp/smscsim/SMSCListenerImpl.java index fee84c7..65c71f1 100644 --- a/sim/src/main/java/org/smpp/smscsim/SMSCListenerImpl.java +++ b/sim/src/main/java/org/smpp/smscsim/SMSCListenerImpl.java @@ -14,6 +14,7 @@ import java.io.IOException; import org.smpp.Connection; +import org.smpp.SSLConnection; import org.smpp.SmppObject; /** @@ -72,7 +73,12 @@ public SMSCListenerImpl(int port, boolean asynchronous) { public synchronized void start() throws IOException { debug.write("going to start SMSCListener on port " + port); if (!isReceiving) { - serverConn = new org.smpp.TCPIPConnection(port); + if(System.getProperty("javax.net.ssl.keyStore") == null || System.getProperty("javax.net.ssl.keyStorePassword") == null || + System.getProperty("javax.net.ssl.keyStore").equals("") || System.getProperty("javax.net.ssl.keyStorePassword").equals("") ) { + serverConn = new org.smpp.TCPIPConnection(port); + } else { + serverConn = new org.smpp.SSLConnection(port); + } serverConn.setReceiveTimeout(getAcceptTimeout()); serverConn.open(); keepReceiving = true;