Custom encryption
As an optional feature, the TeamSpeak 3 SDK allows users to implement custom encryption and decryption for all network traffic. Custom encryption replaces the default AES encryption implemented by the TeamSpeak 3 SDK. A possible reason to apply custom encryption might be to make ones TeamSpeak 3 client and server incompatible to other SDK implementations.
Important
Custom encryption must be implemented the same way in both the client and server.
Note
If you do not want to use this feature, just don’t implement the two encryption callbacks.
Enryption
To encrypt outgoing data, implement the callback
-
struct ClientUIFunctions
Defines available callbacks that you can receive.
Set the members of this struct to a function to call when the specific event happens.
Public Members
-
void (*onCustomPacketEncryptEvent)(char **dataToSend, unsigned int *sizeOfData)
called for every packet to be sent to the server. Used to implement custom cryptography.
Only implement if you need custom encryption of network traffic. Replaces default encryption. If implemented Encryption and Decryption must be implemented the same way on both server and client.
- Param dataToSend:
pointer to a byte array of data to be encrypted. Must not be freed. Write encrypted data to array. Replace array pointer with pointer to own buffer if you need more space. Need to take care of freeing your own memory yourself.
- Param sizeOfData:
pointer to the size of the data array.
-
void (*onCustomPacketEncryptEvent)(char **dataToSend, unsigned int *sizeOfData)
dataToSend
Pointer to an array with the outgoing data to be encrypted.
Apply your custom encryption to the data array. If the encrypted data is smaller than sizeOfData, write your encrypted data into the existing memory of dataToSend. If your encrypted data is larger, you need to allocate memory and redirect the pointer dataToSend. You need to take care of freeing your own allocated memory yourself. The memory allocated by the SDK, to which dataToSend is originally pointing to, must not be freed.
sizeOfData
Pointer to an integer value containing the size of the data array.
Decryption
To decrypt incoming data, implement the callback
-
struct ClientUIFunctions
Defines available callbacks that you can receive.
Set the members of this struct to a function to call when the specific event happens.
Public Members
-
void (*onCustomPacketDecryptEvent)(char **dataReceived, unsigned int *dataReceivedSize)
called for every packet received from the server. Used to implement custom cryptography.
Only implement if you need custom encryption of network traffic. Replaces default encryption. If implemented Encryption and Decryption must be implemented the same way on both server and client.
- Param dataReceived:
pointer to byte array of data to decrypt. Must not be freed. Write decrypted data to the array if large enough. Replace array pointer with pointer to own buffer if decrypted data exceeds the array size. Must take care to free own memory.
- Param sizeOfData:
pointer to the size of the data array.
-
void (*onCustomPacketDecryptEvent)(char **dataReceived, unsigned int *dataReceivedSize)
dataReceived
Pointer to an array with the received data to be decrypted.
Apply your custom decryption to the data array. If the decrypted data is smaller than dataReceivedSize, write your decrypted data into the existing memory of dataReceived. If your decrypted data is larger, you need to allocate memory and redirect the pointer dataReceived. You need to take care of freeing your own allocated memory yourself. The memory allocated by the SDK, to which dataReceived is originally pointing to, must not be freed.
dataReceivedSize
Pointer to an integer value containing the size of the data array.
Example
Example code implementing a very simple XOR custom encryption and decryption (also see the SDK examples):
1void onCustomPacketEncryptEvent(char** dataToSend, unsigned int* sizeOfData) {
2 unsigned int i;
3 for (i = 0; i < *sizeOfData; i++) {
4 (*dataToSend)[i] ^= CUSTOM_CRYPT_KEY;
5 }
6}
7
8void onCustomPacketDecryptEvent(char** dataReceived, unsigned int* dataReceivedSize) {
9 unsigned int i;
10 for (i = 0; i < *dataReceivedSize; i++) {
11 (*dataReceived)[i] ^= CUSTOM_CRYPT_KEY;
12 }
13}