Example #1
0
class HandshakesTest(unittest.TestCase):
    USERNAME = 123456789
    KEYPAIR = KeyPair.generate()
    PHONE_ID = uuid.uuid4().__str__()
    CONFIG = ClientConfig(username=USERNAME,
                          passive=True,
                          useragent=VBoxUserAgentConfig(
                              app_version="2.19.51",
                              phone_id=PHONE_ID,
                              mcc="000",
                              mnc="000",
                          ),
                          pushname="consonance",
                          short_connect=True)
    ENDPOINT = ("e1.whatsapp.net", 443)
    HEADER = b"WA\x02\x01"

    def test_xx_handshake(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(self.ENDPOINT)
        # send WA header indicating protocol version
        s.send(self.HEADER)
        # use WASegmentedStream for sending/receiving in frames
        stream = WASegmentedStream(SocketArbitraryStream(s))
        # initialize WANoiseProtocol 2.1
        wa_noiseprotocol = WANoiseProtocol(2, 1)
        # start the protocol, this should a XX handshake since
        # we are not passing the remote static public key
        self.assertTrue(
            wa_noiseprotocol.start(stream, self.CONFIG, self.KEYPAIR))
        # we are now in transport phase, first incoming data
        # will indicate whether we are authenticated
        first_transport_data = wa_noiseprotocol.receive()
        # fourth byte is status, 172 is success, 52 is failure
        self.assertEqual(52, first_transport_data[3])
import logging
import sys
import base64

consonance.logger.setLevel(logging.DEBUG)
dissononce.logger.setLevel(logging.DEBUG)

# username is phone number
USERNAME = 123456789
# on Android fetch client_static_keypair from /data/data/com.whatsapp/shared_prefs/keystore.xml
KEYPAIR = KeyPair.from_bytes(
    base64.b64decode(
        b"YJa8Vd9pG0KV2tDYi5V+DMOtSvCEFzRGCzOlGZkvBHzJvBE5C3oC2Fruniw0GBGo7HHgR4TjvjI3C9AihStsVg=="
    ))
# using a random remote public key
WA_PUBLIC = KeyPair.generate().public
# same phone_id/fdid used at registration.
# on Android it's phoneid_id under /data/data/com.whatsapp/shared_prefs/com.whatsapp_preferences.xml
PHONE_ID = uuid.uuid4().__str__()
# create full configuration which will translate later into a protobuf payload
CONFIG = ClientConfig(username=USERNAME,
                      passive=True,
                      useragent=SamsungS9PUserAgentConfig(
                          app_version="2.21.21.18", phone_id=PHONE_ID),
                      pushname="consonance",
                      short_connect=True)
PROTOCOL_VERSION = (4, 0)
ENDPOINT = ("e1.whatsapp.net", 443)
HEADER = b"WA" + bytes(PROTOCOL_VERSION)

if __name__ == "__main__":
Example #3
0
 def generateKeyPair(cls):
     """
     :return:
     :rtype: KeyPair
     """
     return KeyPair.generate()