diff --git a/Extasys for Java Examples/Extasys.Examples.UDPClient/src/Extasys/Examples/UDPClient/UDPClient.java b/Extasys for Java Examples/Extasys.Examples.UDPClient/src/Extasys/Examples/UDPClient/UDPClient.java index 2a57f4c..3e66aac 100644 --- a/Extasys for Java Examples/Extasys.Examples.UDPClient/src/Extasys/Examples/UDPClient/UDPClient.java +++ b/Extasys for Java Examples/Extasys.Examples.UDPClient/src/Extasys/Examples/UDPClient/UDPClient.java @@ -19,11 +19,11 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE.*/ package Extasys.Examples.UDPClient; +import Extasys.Encryption.Base64Encryptor; import Extasys.Network.UDP.Client.Connectors.UDPConnector; import java.net.DatagramPacket; import java.net.InetAddress; - /** * * @author Nikos Siatras @@ -39,7 +39,8 @@ public UDPClient(String name, String description, int readTimeOut, int corePoolS // Add a UDP connector to this UDP client. // You can add more than one connectors if you need to. - super.AddConnector("My connector", 10240, 10000, remoteHostIP, remoteHostPort); + UDPConnector conn = super.AddConnector("My connector", 10240, 10000, remoteHostIP, remoteHostPort); + //conn.setConnectionEncryptor(new Base64Encryptor()); } @Override diff --git a/Extasys for Java Examples/Extasys.Examples.UDPServer/src/Extasys/Examples/UDPServer/UDPServer.java b/Extasys for Java Examples/Extasys.Examples.UDPServer/src/Extasys/Examples/UDPServer/UDPServer.java index c13ca58..43183ff 100644 --- a/Extasys for Java Examples/Extasys.Examples.UDPServer/src/Extasys/Examples/UDPServer/UDPServer.java +++ b/Extasys for Java Examples/Extasys.Examples.UDPServer/src/Extasys/Examples/UDPServer/UDPServer.java @@ -19,6 +19,7 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE.*/ package Extasys.Examples.UDPServer; +import Extasys.Encryption.Base64Encryptor; import Extasys.Network.UDP.Server.Listener.UDPListener; import java.net.DatagramPacket; import java.net.InetAddress; @@ -33,7 +34,8 @@ public class UDPServer extends Extasys.Network.UDP.Server.ExtasysUDPServer public UDPServer(String name, String description, InetAddress listenerIP, int port, int connectionsTimeOut, int corePoolSize, int maximumPoolSize) { super(name, description, corePoolSize, maximumPoolSize); - this.AddListener("My UDP Listener", listenerIP, port, 10240, connectionsTimeOut); + UDPListener listener = this.AddListener("My UDP Listener", listenerIP, port, 10240, connectionsTimeOut); + //listener.setConnectionEncryptor(new Base64Encryptor()); } @Override diff --git a/Extasys for Java/src/Extasys/Network/TCP/Client/Connectors/TCPConnector.java b/Extasys for Java/src/Extasys/Network/TCP/Client/Connectors/TCPConnector.java index a957069..7c60212 100644 --- a/Extasys for Java/src/Extasys/Network/TCP/Client/Connectors/TCPConnector.java +++ b/Extasys for Java/src/Extasys/Network/TCP/Client/Connectors/TCPConnector.java @@ -19,7 +19,6 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE.*/ package Extasys.Network.TCP.Client.Connectors; -import Extasys.DataFrame; import Extasys.Encryption.ConnectionEncryptor; import Extasys.Encryption.NullEncryptor; import Extasys.MessageCollector.MessageETX; diff --git a/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/Packets/IncomingUDPClientPacket.java b/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/Packets/IncomingUDPClientPacket.java index a27ba59..1cd778f 100644 --- a/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/Packets/IncomingUDPClientPacket.java +++ b/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/Packets/IncomingUDPClientPacket.java @@ -69,6 +69,11 @@ public void run() { // Trim the incoming packet byte[] cleanData = Arrays.copyOfRange(fDataGram.getData(), 0, fDataGram.getLength()); + + // Decrypt incoming data + cleanData = fConnector.getConnectionEncyptor().Decrypt(cleanData); + + // Set trimmed and decrypted data to fDataGram fDataGram.setData(cleanData, 0, cleanData.length); fConnector.getMyExtasysUDPClient().OnDataReceive(fConnector, fDataGram); diff --git a/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/Packets/OutgoingUDPClientPacket.java b/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/Packets/OutgoingUDPClientPacket.java index 97d9da1..c104b5f 100644 --- a/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/Packets/OutgoingUDPClientPacket.java +++ b/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/Packets/OutgoingUDPClientPacket.java @@ -62,7 +62,11 @@ public void run() // Wait for previous Packet to be processed // by the thread pool. this.WaitForPreviousPacketToBeProcessedAndCheckIfItWasCanceled(); - + + // Encrypt outgoing data + byte[] encryptedData = fConnector.getConnectionEncyptor().Encrypt(fDataGram.getData()); + fDataGram.setData(encryptedData, 0, encryptedData.length); + if (!fCancel) { fConnector.fSocket.send(fDataGram); diff --git a/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/UDPConnector.java b/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/UDPConnector.java index 21449a4..4352804 100644 --- a/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/UDPConnector.java +++ b/Extasys for Java/src/Extasys/Network/UDP/Client/Connectors/UDPConnector.java @@ -19,6 +19,8 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE.*/ package Extasys.Network.UDP.Client.Connectors; +import Extasys.Encryption.ConnectionEncryptor; +import Extasys.Encryption.NullEncryptor; import Extasys.Network.UDP.Client.Connectors.Packets.*; import Extasys.Network.UDP.Client.ExtasysUDPClient; import java.io.IOException; @@ -26,7 +28,6 @@ of this software and associated documentation files (the "Software"), to deal import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; -import java.util.Arrays; /** * @@ -36,19 +37,22 @@ public class UDPConnector { private boolean fActive = false; - private ExtasysUDPClient fMyUDPClient; //Extasys UDP Client reference. + private final ExtasysUDPClient fMyUDPClient; //Extasys UDP Client reference. public DatagramSocket fSocket; - private InetAddress fServerIP; - private int fServerPort; + private final InetAddress fServerIP; + private final int fServerPort; private Thread fReadDataThread; - private String fName; - private int fReadBufferSize; - private int fReadTimeOut; + private final String fName; + private final int fReadBufferSize; + private final int fReadTimeOut; public long fBytesIn = 0, fBytesOut = 0; public IncomingUDPClientPacket fLastIncomingPacket = null; public OutgoingUDPClientPacket fLastOutgoingPacket = null; + // Connection Encryption + private ConnectionEncryptor fConnectionEncryptor = new NullEncryptor(); + /** * Constructs a new UDP Connector. * @@ -219,11 +223,11 @@ public int getReadBufferSize() } /** - * Returns the maximum time in milliseconds in which a datagram packet can be - * received. + * Returns the maximum time in milliseconds in which a datagram packet can + * be received. * - * @return the maximum time in milliseconds in which a datagram packet can be - * received. + * @return the maximum time in milliseconds in which a datagram packet can + * be received. */ public int getReadTimeOut() { @@ -250,6 +254,26 @@ public long getBytesOut() return fBytesOut; } + /** + * Returns the connection encryptor + * + * @return + */ + public ConnectionEncryptor getConnectionEncyptor() + { + return fConnectionEncryptor; + } + + /** + * Sets the connection encryptor of this UDPConnector + * + * @param encryptor + */ + public void setConnectionEncryptor(ConnectionEncryptor encryptor) + { + fConnectionEncryptor = (encryptor == null) ? new NullEncryptor() : encryptor; + } + } class ReadIncomingData extends Thread diff --git a/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/Packets/IncomingUDPServerPacket.java b/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/Packets/IncomingUDPServerPacket.java index e6c29f2..225cbf4 100644 --- a/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/Packets/IncomingUDPServerPacket.java +++ b/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/Packets/IncomingUDPServerPacket.java @@ -70,6 +70,10 @@ public void run() { // Trim the incoming packet byte[] cleanData = Arrays.copyOfRange(fDataGram.getData(), 0, fDataGram.getLength()); + + // Decrypt incoming data + cleanData = fMyListener.getConnectionEncyptor().Decrypt(cleanData); + fDataGram.setData(cleanData, 0, cleanData.length); fMyListener.getMyExtasysUDPServer().OnDataReceive(fMyListener, fDataGram); diff --git a/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/Packets/OutgoingUDPServerPacket.java b/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/Packets/OutgoingUDPServerPacket.java index d904111..04595b9 100644 --- a/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/Packets/OutgoingUDPServerPacket.java +++ b/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/Packets/OutgoingUDPServerPacket.java @@ -52,6 +52,10 @@ public void run() // by the thread pool. this.WaitForPreviousPacketToBeProcessedAndCheckIfItWasCanceled(); + // Encrypt outgoing data + byte[] encryptedData = fMyListener.getConnectionEncyptor().Encrypt(fDataGram.getData()); + fDataGram.setData(encryptedData, 0, encryptedData.length); + if (!fCancel) { fMyListener.fSocket.send(fDataGram); diff --git a/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/UDPListener.java b/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/UDPListener.java index 1b9e333..232e9f2 100644 --- a/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/UDPListener.java +++ b/Extasys for Java/src/Extasys/Network/UDP/Server/Listener/UDPListener.java @@ -19,6 +19,8 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE.*/ package Extasys.Network.UDP.Server.Listener; +import Extasys.Encryption.ConnectionEncryptor; +import Extasys.Encryption.NullEncryptor; import Extasys.Network.UDP.Server.ExtasysUDPServer; import Extasys.Network.UDP.Server.Listener.Packets.IncomingUDPServerPacket; import Extasys.Network.UDP.Server.Listener.Packets.OutgoingUDPServerPacket; @@ -49,6 +51,9 @@ public class UDPListener public IncomingUDPServerPacket fLastIncomingPacket = null; public OutgoingUDPServerPacket fLastOutgoingPacket = null; + // Connection Encryption + private ConnectionEncryptor fConnectionEncryptor = new NullEncryptor(); + /** * Constructs a new UDP Listener. * @@ -231,6 +236,26 @@ public boolean isActive() return fActive; } + /** + * Returns the connection encryptor + * + * @return + */ + public ConnectionEncryptor getConnectionEncyptor() + { + return fConnectionEncryptor; + } + + /** + * Sets the connection encryptor of this UDPListener + * + * @param encryptor + */ + public void setConnectionEncryptor(ConnectionEncryptor encryptor) + { + fConnectionEncryptor = (encryptor == null) ? new NullEncryptor() : encryptor; + } + } class ReadIncomingDataThread extends Thread