def __init__(self): super(YowNoiseLayer, self).__init__() self._wa_noiseprotocol = WANoiseProtocol( 2, 1, protocol_state_callbacks=self._on_protocol_state_changed ) # type: WANoiseProtocol self._handshake_worker = None self._stream = BlockingQueueSegmentedStream() # type: BlockingQueueSegmentedStream self._read_buffer = bytearray() self._flush_lock = threading.Lock() self._incoming_segments_queue = Queue.Queue() self._profile = None self._rs = None
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])
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") sys.exit(1) else:
useragent=SamsungS9PUserAgentConfig( app_version="2.19.51", phone_id=PHONE_ID), pushname="consonance", short_connect=True) ENDPOINT = ("e1.whatsapp.net", 443) HEADER = b"WA\x02\x01" 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 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 if 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 byte is status, 172 is success, 52 is failure if first_transport_data[3] == 172: print("Authentication succeeded") elif first_transport_data[3] == 52: print("Authentication failed") sys.exit(1) else: print("Unrecognized authentication response: %s" %