コード例 #1
0
 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
     wa_noiseprotocol = WANoiseProtocol(*PROTOCOL_VERSION)
     # start the protocol, this should a XX handshake since
     # we are not passing the remote static public key
     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 + fifth byte are status, [237, 38] is failure
     self.assertEqual(b'\xed\x26', first_transport_data[3:5])
コード例 #2
0
                      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__":
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(ENDPOINT)
    # send WA header indicating protocol version
    s.send(HEADER)
    # use WASegmentedStream for sending/receiving in frames
    stream = WASegmentedStream(SocketArbitraryStream(s))
    # initialize WANoiseProtocol
    wa_noiseprotocol = WANoiseProtocol(*PROTOCOL_VERSION)
    # start the protocol, this should a XX handshake since
    # we are not passing the remote static public key
    try:
        wa_noiseprotocol.start(stream, CONFIG, KEYPAIR)
        print("Handshake completed, checking authentication...")
        # we are now in transport phase, first incoming data
        # will indicate whether we are authenticated
        first_transport_data = wa_noiseprotocol.receive()
        # fourth + fifth byte are status, [237, 38] is failure
        if first_transport_data[3] == 51:
            print("Authentication succeeded")
        elif list(first_transport_data[3:5]) == [237, 38]:
            print("Authentication failed")