whad-team / whad-client

Wireless Hacking Devices Protocol client
MIT License
131 stars 8 forks source link

SMP Broken Public Key Generation #60

Open sacca97 opened 2 months ago

sacca97 commented 2 months ago
Traceback (most recent call last):
  File "/usr/lib64/python3.12/threading.py", line 1075, in _bootstrap_inner
    self.run()
  File "/home/sacca/Projects/whad-client/whad/device/__init__.py", line 777, in run
    self.__device.process_messages()
  File "/home/sacca/Projects/whad-client/whad/device/__init__.py", line 1432, in process_messages
    self.dispatch_message(message)
  File "/home/sacca/Projects/whad-client/whad/device/__init__.py", line 1395, in dispatch_message
    self.on_domain_msg(domain, message)
  File "/home/sacca/Projects/whad-client/whad/device/__init__.py", line 1673, in on_domain_msg
    self.__connector.on_packet(packet)
  File "/home/sacca/Projects/whad-client/whad/ble/connector/__init__.py", line 735, in on_packet
    self.on_data_pdu(conn_pdu)
  File "/home/sacca/Projects/whad-client/whad/ble/connector/peripheral.py", line 303, in on_data_pdu
    self.__stack.on_data_pdu(pdu.metadata.connection_handle, pdu)
  File "/home/sacca/Projects/whad-client/whad/ble/stack/__init__.py", line 77, in on_data_pdu
    self.send('ll', pdu, tag='data', conn_handle=conn_handle)
  File "/home/sacca/Projects/whad-client/whad/common/stack/layer.py", line 598, in send
    return self.send_from(self.name, destination, data, tag=tag, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sacca/Projects/whad-client/whad/common/stack/layer.py", line 624, in send_from
    handler(data, **kwargs)
  File "/home/sacca/Projects/whad-client/whad/ble/stack/llm/__init__.py", line 693, in on_data_pdu_recv
    self.on_data_pdu(pdu, conn_handle)
  File "/home/sacca/Projects/whad-client/whad/ble/stack/llm/__init__.py", line 723, in on_data_pdu
    self.send(l2cap_layer, bytes(pdu.payload), fragment=(pdu.LLID == 0x1))
  File "/home/sacca/Projects/whad-client/whad/common/stack/layer.py", line 598, in send
    return self.send_from(self.name, destination, data, tag=tag, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sacca/Projects/whad-client/whad/common/stack/layer.py", line 624, in send_from
    handler(data, **kwargs)
  File "/home/sacca/Projects/whad-client/whad/ble/stack/l2cap/__init__.py", line 62, in on_data_received
    self.on_l2cap_packet(L2CAP_Hdr(self.state.fifo[:self.state.expected_len]))
  File "/home/sacca/Projects/whad-client/whad/ble/stack/l2cap/__init__.py", line 89, in on_l2cap_packet
    self.send('smp', packet.getlayer(SM_Hdr))
  File "/home/sacca/Projects/whad-client/whad/common/stack/layer.py", line 598, in send
    return self.send_from(self.name, destination, data, tag=tag, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sacca/Projects/whad-client/whad/common/stack/layer.py", line 622, in send_from
    handler(source, data, **kwargs)
  File "/home/sacca/Projects/whad-client/whad/ble/stack/smp/__init__.py", line 1208, in on_packet
    self.__handlers[int(smp_pkt.sm_command)](smp_pkt.getlayer(1))
  File "/home/sacca/Projects/whad-client/whad/ble/stack/smp/__init__.py", line 1350, in on_public_key
    self.state.peer_public_key = generate_public_key_from_coordinates(x, y)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sacca/Projects/whad-client/whad/ble/crypto.py", line 172, in generate_public_key_from_coordinates
    return EllipticCurvePublicNumbers(x, y, SECP256R1()).public_key()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sacca/.local/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py", line 385, in public_key
    return ossl.load_elliptic_curve_public_numbers(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sacca/.local/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1205, in load_elliptic_curve_public_numbers
    ec_cdata = self._ec_key_set_public_key_affine_coordinates(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sacca/.local/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1366, in _ec_key_set_public_key_affine_coordinates
    raise ValueError("Invalid EC key.")
ValueError: Invalid EC key.
jsmif commented 1 month ago

Can you post which command you used to get that? (I'm curious to try too.)