2013-11-29 17:34:06 -05:00
|
|
|
package ch.spacebase.packetlib.test;
|
|
|
|
|
2013-12-14 19:41:25 -05:00
|
|
|
import java.security.GeneralSecurityException;
|
|
|
|
|
|
|
|
import javax.crypto.SecretKey;
|
|
|
|
|
2013-11-29 17:34:06 -05:00
|
|
|
import ch.spacebase.packetlib.Client;
|
|
|
|
import ch.spacebase.packetlib.Server;
|
|
|
|
import ch.spacebase.packetlib.Session;
|
2013-12-14 19:41:25 -05:00
|
|
|
import ch.spacebase.packetlib.crypt.AESEncryption;
|
|
|
|
import ch.spacebase.packetlib.crypt.PacketEncryption;
|
2013-11-29 17:34:06 -05:00
|
|
|
import ch.spacebase.packetlib.packet.PacketProtocol;
|
|
|
|
|
|
|
|
public class TestProtocol extends PacketProtocol {
|
|
|
|
|
2013-12-14 19:41:25 -05:00
|
|
|
private AESEncryption encrypt;
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private TestProtocol() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public TestProtocol(SecretKey key) {
|
|
|
|
this.setSecretKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSecretKey(SecretKey key) {
|
|
|
|
this.register(0, PingPacket.class);
|
|
|
|
try {
|
|
|
|
this.encrypt = new AESEncryption(key);
|
|
|
|
} catch(GeneralSecurityException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-11-29 17:34:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-14 19:41:25 -05:00
|
|
|
public PacketEncryption getEncryption() {
|
|
|
|
return this.encrypt;
|
2013-11-29 17:34:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-14 19:41:25 -05:00
|
|
|
public void newClientSession(Client client, Session session) {
|
|
|
|
session.addListener(new ClientSessionListener());
|
2013-11-29 17:34:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void newServerSession(Server server, Session session) {
|
|
|
|
session.addListener(new ServerSessionListener());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|