How to get a 'Connection' object during serialization?

44 views
Skip to first unread message

Jakub S

unread,
Oct 7, 2016, 4:40:52 AM10/7/16
to kryonet-users

I have a huge, huge problem. I'm using AES serialization for packets and here comes an issue.

Serializers in Kryo look like this:

public class AESSerializer extends Serializer {
    private final Serializer serializer;

    public AESSerializer (Serializer serializer) {
       this.serializer = serializer;
    }

    public void write (Kryo kryo, Output output, Object object) {
        // USE AES KEY TO ENCRYPT
        // WRITE OBJECT
    }

    public Object read (Kryo kryo, Input input, Class type) {
        // USE AES KEY TO DECRYPT
        // READ OBJECT
    }

}

The problem is here that each user has to have it's own SecretAESKey. I can't find any way to get to the connections lists from the serializer and as I read Kryonet's code - they don't pass it anywhere. I need to get the Connection that writes the object to get it's AES key.

Serializer constructor isn't an option cause serializer is one per application, not for each user.

Do you guys have any idea how to handle things like that?


Maybe I should 'encrypt' data before using 'sendTcp()' method?

Capt Kirk

unread,
Mar 1, 2018, 10:41:15 PM3/1/18
to kryonet-users
I had that issue once.  What I did was create a helper utility class that creates a Kryo Output instance and writes the unencrypted data to that then pass that buffer into a encryption method that returns a encryted byte array, finally, write that encrypted data to the KryoSerializable write method's output with the length of the byte array for deserialization.

Nate

unread,
Mar 2, 2018, 11:45:01 AM3/2/18
to kryone...@googlegroups.com, Jakub S
No need to create any classes, you can get the connection like this:
Connection connection = (Connection)kryo.getContext().get("connection");


--
You received this message because you are subscribed to the "kryonet-users" group.
http://groups.google.com/group/kryonet-users
---
You received this message because you are subscribed to the Google Groups "kryonet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kryonet-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages