This is the major revamp of my old version. Additionally this new library also include the interface of cryptography which is defined in the "connection" class and which is having the signature function of Decrypt and Encrypt. This cryptography interface can be implemented outside the parent class therefore making this proxy library a very flexible tools for creating a proxy with different type of encryption.
Cryptography Interface signature:
We know that we have an interface installed inside the connection class which can implemented on the parent class but we don't know how and when is the right time to initialize it. Well this can be done perfectly during when the proxy established the connection between remote-proxy-client such as the example below.
When the cryptography will be incorporated correctly, a decrypted packet shall be available on the Data arrival events and you can do whatever you want on that packet.
Please take note that I have added the sessionid on each events which also corresponds to the connection id for each remote-proxy-client session. This sessionid is just an incremental value of integer. The purpose of this sessionid is if you want to control the specific connection and if you want to access its public method from the parent class such as the example below.
General Implementation of the library:
Importing the library
Initializing the library.
Starting the proxy and defining the events
Events Callback
See also the attached test proxy example. If you find any bugs please let me know. :D
Cryptography Interface signature:
Code:
public interface Icrypto
{
void Decrypt(ref byte[] data, bool IsRemServer);
void Encrypt(ref byte[] data, bool IsRemServer);
}
Code:
private void myProxy_NewConnectionEvent(object sender, int sessionid)
{
//Initialized the encryptor here
CrypImplementer cryptImp = new CrypImplementer();
myProxy.SetCryptImp((object)cryptImp, sessionid);
}
private class CrypImplementer : connection.Icrypto
{
public CrypImplementer() { }
public void Decrypt(ref byte[] data, bool IsRemServer)
{
/*Define your Decryption here
* IrRemServer is true when the data is coming from server
* otherwise it is false
*/
}
public void Encrypt(ref byte[] data, bool IsRemServer)
{
/*Define your Encryption here
* IrRemServer is true when the data is coming from server
* otherwise it is false
*/
}
}
Code:
private void myProxy_DataArrivalEvent(
object sender,
object data,
int sessionid,
Boolean IsRemServer)
{
connection conn = (connection)sender;
if (IsRemServer)
{
// You can add packet handler here
conn.SendPC(data);
}
else
{
// You can add packet handler here
conn.SendPS(data);
}
}
Code:
connection tmpcon=myProxy.GetConn(sessionid); tmpcon.SendPC((object) byte); // send data from proxy to client for connection id= sessionid tmpcon.SendPS((object) byte); // send data from proxy to remote host for connection id= sessionid
General Implementation of the library:
Importing the library
Code:
using xmenproxy;
Code:
/* * If you have more proxy listening at different port then you can defined different instance for it */ ProxyServer myProxy = new ProxyServer(); //ProxyServer myProxy2 = new ProxyServer(); //ProxyServer myProxy3 = new ProxyServer(); //etc
Code:
myProxy.RemoteIP = "remotehostip";
myProxy.RemotePort = 9960;
myProxy.LocalPort = 9960;
myProxy.LocalIP = "localhost";
myProxy.DataArrivalEvent += new ProxyServer.DataArrival(myProxy_DataArrivalEvent);
myProxy.NewConnectionEvent += new ProxyServer.NewConnection(myProxy_NewConnectionEvent);
myProxy.StartServer();
Code:
private void myProxy_NewConnectionEvent(object sender, int sessionid)
{
//Initialized the encryptor here
CrypImplementer cryptImp = new CrypImplementer();
myProxy.SetCryptImp((object)cryptImp, sessionid);
}
private void myProxy_DataArrivalEvent(
object sender,
object data,
int sessionid,
Boolean IsRemServer)
{
connection conn = (connection)sender;
if (IsRemServer)
{
conn.SendPC(data);
}
else
{
conn.SendPS(data);
}
}