-
Notifications
You must be signed in to change notification settings - Fork 6
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
serverkey
fromlibg.so
. -
Client sends
10100
packet to server unencrypted. -
Server sends
20100
packet 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
randombytes
may 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 fromrandombytes
and comparing it tosnonce
. -
Client generates a key pair (
pk
andsk
) withcrypto_box_keypair
. -
Client generates
nonce
withblake2b
usingpk
andserverkey
. -
Client generates a shared key (
s
) withcrypto_box_beforenm
usingsk
andserverkey
. -
Client sends
10101
packet encrypted withcrypto_box_afternm
usings
andnonce
to server.It is prefixed with the 24 byte binary string from packet
20100
andsnonce
before encryption.It is prefixed with
pk
after encryption. -
Server reads
pk
from packet10101
. -
Server generates
nonce
withblake2b
usingpk
andserverkey
. -
Server generates a shared key (
s
) withcrypto_box_beforenm
using its private key andpk
. -
Server decrypts packet
10101
withcrypto_box_afternm_open
usings
andnonce
. -
Server reads
snonce
from 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
nonce
withblake2b
usingsnonce
,pk
, andserverkey
. -
Server sends
20104
packet encrypted withcrypto_box_afternm
usings
andnonce
to client.It is prefixed with
rnonce
andk
before encryption. -
Client generates
nonce
withblake2b
usingsnonce
,pk
, andserverkey
. -
Client generates a shared key (
s
) withcrypto_box_beforenm
usingsk
andserverkey
. -
Client decrypts packet
20104
withcrypto_box_afternm_open
usings
andnonce
. -
Client reads
rnonce
andk
from packet20104
. -
For all subsequent client->server packets:
-
Both the client and server increment
snonce
by 2.Reminder:
snonce
is little-endian. -
Client encrypts packet with
crypto_box_afternm
usingk
andsnonce
. -
Server decrypts packet with
crypto_box_afternm_open
usingk
andsnonce
.
For all subsequent server->client packets:
-
Both the client and server increment
rnonce
by 2.Reminder:
rnonce
is little-endian. -
Server encrypts packet with
crypto_box_afternm
usingk
andrnonce
. -
Client decrypts packet with
crypto_box_afternm_open
usingk
andrnonce
.
-