Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding TLS capabilities to client and server, modifications to Connec… #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
language: java
jdk:
- oraclejdk8
- openjdk7
- openjdk8
16 changes: 15 additions & 1 deletion client/src/main/java/org/smpp/client/SMPPSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +58,11 @@ public class SMPPSender {
*/
boolean bound = false;

/**
* If application should use TLS.
*/
private static boolean useTLS = false;

/**
* Address of the SMSC.
*/
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/smpp/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

/*
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/org/smpp/SSLConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
32 changes: 28 additions & 4 deletions core/src/main/java/org/smpp/TCPIPConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) );
}
Expand All @@ -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();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 $
Expand Down
8 changes: 7 additions & 1 deletion sim/src/main/java/org/smpp/smscsim/SMSCListenerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;

import org.smpp.Connection;
import org.smpp.SSLConnection;
import org.smpp.SmppObject;

/**
Expand Down Expand Up @@ -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;
Expand Down