-
Notifications
You must be signed in to change notification settings - Fork 54
WhatsApp Handshake Noise Protocol
This page explains the handshake of WhatsApp using Noise Protocol.
If you have a edge_routing_info
, first send ED
0x00 0x01
and then 4 bytes containing the edge_routing_info
.
WhatsApp needs to know what version of the protocol you are using. For example, when using protocol version 4.1, send WA
0x04 0x01
.
This 4 bytes (WA
0x04 0x01
) should also set as prologue when using Noise Protocol.
After the WhatsApp version is sent, the client and servers communicates with segments, so every data fragment is prefixed with a int24 length. This isn't only for the handshake, but also after it, when sending (encrypted) FunXMPP.
During the handshake, the client and server send Protobuf messages to each other to initiate a encrypted communication. The used Protobuf structure can be found here. The handshake uses Noise Pipes.
What do you need:
-
client_static_keypair
(generated before the registration), consisting of:-
client_static_public
(Used during registration asauthkey
) client_static_private
-
-
server_static_public
(If you don't have it, it will be send by the server) -
client_ephemeral_keypair
(generate before handshake), consisting of:client_ephemeral_public
client_ephemeral_private
-
server_ephemeral_public
(Will be send by the server)
If you don't know what the server_static_public
of the server is, go to XX. If you already know the server_static_public
, then go to IK.
XX means:
- Static key for initiator Xmitted ("transmitted") to responder
- Static key for responder Xmitted ("transmitted") to initiator
Direction: Client -> Server
-
e
: Client sends it'sclient_ephemeral_public
(unencrypted) to the server.
Direction: Server -> Client
-
e
: Server sends it'sserver_ephemeral_public
(unencrypted) to the client. -
ee
: Both client and server calculate the shared secret with the received public ephemeral and their stored private ephemeral. -
s
: Server sends it'sserver_static_public
(encrypted withee
) to the client (in same packet). -
es
: Server calculates the shared secret with the received public ephemeral and their stored private static. - Server sends it's Certificate payload (encrypted with
es
) to the client (in same packet).
Direction: Client -> Server
-
s
: Client sends it'sclient_static_public
(encrypted with es`) to the server. -
se
: Client calculates the shared secret with the received public ephemeral and their stored private static. - Client sends it's User-Agent payload (encrypted with
se
) to the server (in same packet).
IK means:
- Static key for initiator Immediately transmitted to responder, despite reduced or absent identity hiding
- Static key for responder Known to initiator
Direction: Client -> Server
-
e
: Client sends it'sclient_ephemeral_public
(unencrypted) to the server. -
es
: Server calculates the shared secret with the received public ephemeral and their stored private static. -
s
: Client sends it'sclient_static_public
(encrypted with es`) to the server (in same packet). -
ss
: Both client and server calculate the shared secret with the received/stored public static and their stored private static.
Direction: Server -> Client
NOTE: If this packet does have a server_static_public
, than you should look at Server Hello (XXfallback).
- TODO
XXfallback means:
- Fallback to
XX
, whenIK
fails.
Direction: Server -> Client
- TODO
Direction: Client -> Server
- TODO
WAPI!!!
WAPI!!!