I finished the secure login / serverlist library. The first idea was to encrypt the whole connection. But because of the way kryonet is built, that would mean rewriting most of kryonet. The second idea was to do it similar to what minecraft does / did. The client connects over HTTPS to the central login server to log in. Then the game server connects to the login server and asks it to confirm the authentication of the client. Of course this can be disabled on the server side (and you should add a config option to do that). The biggest advantage compared to the first idea is the better performace. A MITM attack is possible but the attacker can not get the password from the kryonet connection. A replay attack is not possible which means that a "hacker" can only take over existing connections made via his malicious server.
Another feature of the library is the serverlist. You can announce a server on the internet and get a list of all servers (please add a config option to enable internet announcement and disable it by default to prevent lan servers from flooding the list).
If you use maven you can add the library like that:
Code: Select all
<dependencies>
<dependency>
<groupId>de._692b8c32</groupId>
<artifactId>kryonet-extras</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>692b8c32.de</id>
<name>692b8c32.de</name>
<url>https://jenkins.692b8c32.de/plugin/repository/everything/</url>
</repository>
</repositories>
If you use gradle, use the instructions from here:
https://docs.gradle.org/current/usergui ... orial.html
Before you use any other function you have to call
Code: Select all
ServerList.setUri(SERVERLIST_URI); // For example "https://serverlist.692b8c32.de/"
On the server side you can announce the server using something like
Code: Select all
announceTimer = new Timer(true);
announceTimer.schedule(new TimerTask() {
@Override
public void run() {
ServerList.announce("chat", "Chat-Server " + serverName, "1.0", ""); // gameName, serverName, gameVersion, payload
}
}, 0, 30 * 1000);
To enable the authentication replace the line where you add your listener with
Code: Select all
AuthenticationPacketRegisterer.registerClasses(server.getKryo());
server.addListener(new AuthenticationFilterServerListener(listener, true, "chat")); // listener, enableAuthentication, gameName
On the client side you can create a new account like this
Code: Select all
ServerList.register("chat", name, password); // gameName, userName, userPassword
and check the login using
Code: Select all
ServerList.login("chat", name, password, null); // gameName, userName, userPassword, challenge (does not matter if you only want to check whether the credentials are valid)
To enable the authentication replace the line where you add your listener with
Code: Select all
AuthenticationPacketRegisterer.registerClasses(client.getKryo());
client.addListener(new AuthenticationFilterClientListener(listener, name, password, "chat")); // listener, userName, userPassword, gameName
The source code of a small demo application is available here:
https://bitbucket.org/jrb0001/chat/
If you want to set up your own serverlist, you need a Java EE application server. You can download the newest release of the serverlist from here:
https://jenkins.692b8c32.de/job/serverlist.692b8c32.de/