-
Notifications
You must be signed in to change notification settings - Fork 5
Protocol
| ofs | size | contents |
|---|---|---|
| +00 | 2byte | message id, see Protocol Messages |
| +02 | 3byte | payload length |
| +05 | 2byte | version (Doesn't appear to matter, you can use 0x00, 0x00) |
| +07 | encrypted message |
NOTE: The Cryptography methods shown here no longer work with Clash of Clans, Boom Beach, Clash Royale or Hay Day.
-
Server generates a key pair with
crypto_box_keypair, keeps the private key secret, and puts the public key (serverkey) inlibg.so. -
Client reads
serverkeyfromlibg.so. -
Client sends
10100packet to server unencrypted. -
Server sends
20100packet to client unencrypted.It contains only a 24 byte binary string that the client sends back to the server in packet
10101. -
Client generates a little-endian nonce (
snonce) usingrandombytes-1.It will be used to encrypt all client->server packets after
10101.Note: It appears that the output of
randombytesmay only be decremented some of the time. I experienced a few anomalies, but as the value actually sent to the server is the important one, I didn't investigate further. This is only applicable if you are intercepting the data fromrandombytesand comparing it tosnonce. -
Client generates a key pair (
pkandsk) withcrypto_box_keypair. -
Client generates
noncewithblake2busingpkandserverkey. -
Client generates a shared key (
s) withcrypto_box_beforenmusingskandserverkey. -
Client sends
10101packet encrypted withcrypto_box_afternmusingsandnonceto server.It is prefixed with the 24 byte binary string from packet
20100andsnoncebefore encryption.It is prefixed with
pkafter encryption. -
Server reads
pkfrom packet10101. -
Server generates
noncewithblake2busingpkandserverkey. -
Server generates a shared key (
s) withcrypto_box_beforenmusing its private key andpk. -
Server decrypts packet
10101withcrypto_box_afternm_openusingsandnonce. -
Server reads
snoncefrom packet10101. -
Server generates a little-endian nonce (
rnonce) usingrandombytes.It will be used to encrypt all server->client packets after
20104. -
Server generates a key pair with
crypto_box_keypair. -
Server generates a shared key (
k) using the keypair from the previous step. -
Server generates
noncewithblake2busingsnonce,pk, andserverkey. -
Server sends
20104packet encrypted withcrypto_box_afternmusingsandnonceto client.It is prefixed with
rnonceandkbefore encryption. -
Client generates
noncewithblake2busingsnonce,pk, andserverkey. -
Client generates a shared key (
s) withcrypto_box_beforenmusingskandserverkey. -
Client decrypts packet
20104withcrypto_box_afternm_openusingsandnonce. -
Client reads
rnonceandkfrom packet20104. -
For all subsequent client->server packets:
-
Both the client and server increment
snonceby 2.Reminder:
snonceis little-endian. -
Client encrypts packet with
crypto_box_afternmusingkandsnonce. -
Server decrypts packet with
crypto_box_afternm_openusingkandsnonce.
For all subsequent server->client packets:
-
Both the client and server increment
rnonceby 2.Reminder:
rnonceis little-endian. -
Server encrypts packet with
crypto_box_afternmusingkandrnonce. -
Client decrypts packet with
crypto_box_afternm_openusingkandrnonce.
-