pybleno icon indicating copy to clipboard operation
pybleno copied to clipboard

security feature not working

Open enmanoj opened this issue 7 years ago • 10 comments

when using 'secure': ['write'] while initialling Characteristics getting a run-time error

File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Smp.py", line 101, in handlePairingConfirm self._r = crypto.r() NameError: global name 'crypto' is not defined

Please fix a patch for this.

enmanoj avatar Feb 22 '18 16:02 enmanoj

Hi @enmanoj, indeed the crypto support has not been ported. Feel free to submit a patch and I will review it, otherwise I hope to get to it soon. Thanks,

Adam-Langley avatar Feb 23 '18 22:02 Adam-Langley

Hi @enmanoj - could you please post a failure case for this? It will speed up reproduction so I can get a fix done. Thanks.

Adam-Langley avatar Mar 04 '18 18:03 Adam-Langley

You need to add 'secure' while defining characteristic to enable security. To do that please follow the below steps. Examples/pizza/PizzaCrustCharacteristic.py -> to __init__() after 'properties': ['read', 'write'] add this 'secure': ['read', 'write']

Execute the peripheral.py file sudo python peripheral.py Read the Characteristic with Uuid '13333333333333333333333333330001'.

You will get the below error. This error is due to typo error in file

/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/AclStream.py

Change self.encypted = False to self.encrypted = False

Output

Hit <ENTER> to disconnect
advertising...
Exception in thread HCISocketPoller:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/BluetoothHCI/BluetoothHCI.py", line 197, in _socket_poller
    self._socket_on_data_user_callback(bytearray(data))
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Hci.py", line 417, in onSocketData
    self.emit('aclDataPkt', [handle, cid, pktData])
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Emit.py", line 15, in emit
    handler(*arguments)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Bindings.py", line 167, in onAclDataPkt
    self._aclStream.push(cid, data)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/AclStream.py", line 18, in push
    self.emit('data', [cid, data])
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Emit.py", line 15, in emit
    handler(*arguments)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Gatt.py", line 255, in onAclStreamData
    self.handleRequest(data)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Gatt.py", line 299, in handleRequest
    response = self.handleReadOrReadBlobRequest(request)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Gatt.py", line 702, in handleReadOrReadBlobRequest
    if handleSecure & 0x02 and not self._aclStream.encrypted:
AttributeError: AclStream instance has no attribute 'encrypted'


terminated.

Once you fixed the above run peripheral.py and read the same again you will find this error

NameError: global name 'crypto' is not defined

Output


Exception in thread HCISocketPoller:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/BluetoothHCI/BluetoothHCI.py", line 197, in _socket_poller
    self._socket_on_data_user_callback(bytearray(data))
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Hci.py", line 417, in onSocketData
    self.emit('aclDataPkt', [handle, cid, pktData])
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Emit.py", line 15, in emit
    handler(*arguments)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Bindings.py", line 167, in onAclDataPkt
    self._aclStream.push(cid, data)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/AclStream.py", line 18, in push
    self.emit('data', [cid, data])
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Emit.py", line 15, in emit
    handler(*arguments)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Smp.py", line 47, in onAclStreamData
    self.handlePairingConfirm(data)
  File "/usr/local/lib/python2.7/dist-packages/pybleno/hci_socket/Smp.py", line 101, in handlePairingConfirm
    self._r = crypto.r()
NameError: global name 'crypto' is not defined

Note: Am using nRF Connect for Mobile as master for reading and writing data.

enmanoj avatar Mar 13 '18 11:03 enmanoj

Hi @enmanoj, I've committed a fix for some syntactical issues that you identified, but the crypto stuff is not yet implemented - I haven't been able to exercise it. Can you reproduce this same issue using either Windows, MacOS or iOS, and post the repro scenario here? I don't have Android available to me. Thanks,

Adam-Langley avatar May 10 '18 03:05 Adam-Langley

Is there any way to bypass this secure feature? I'm running the echo and battery services without any change and the program is stuck at the crypto point.

shrsulav avatar Sep 10 '19 10:09 shrsulav

Hi @shrsulav - can you switch to the 'transpiled' branch and try that? Those bugs are all resolved on that branch. Please feed back your experience here. Thanks

Adam-Langley avatar Sep 11 '19 02:09 Adam-Langley

Hello @Adam-Langley, I checked out the transpiled branch and ran the main.py of the echo example. And, this is the error I'm getting:

pybleno/bleno/examples/echo# python3 main.py Traceback (most recent call last): File "main.py", line 2, in from bleno.supporting import * ModuleNotFoundError: No module named 'bleno'

shrsulav avatar Sep 11 '19 04:09 shrsulav

Hi @shrsulav have you followed the instructions under 'Running The Examples'? Because there is currently no pip module for that branch, you cannot run the examples the way you appear to have.

Adam-Langley avatar Sep 11 '19 08:09 Adam-Langley

Another option is: pip install -e .

This Installs the project in editable mode from the current project repositry. This will link the package to the local files meaning any changes locally would be available in your environment

ukBaz avatar Sep 11 '19 09:09 ukBaz

@Adam-Langley I cloned the repo, checked out to the transpiled branch and on using the command $ python3 -m bleno.examples.echo.main

I got the following error: "ModuleNotFoundError: No module named 'bleno.supporting.math'"

shrsulav avatar Sep 17 '19 06:09 shrsulav