Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list_accessories_and_characteristics doesnt work over a secure session #80

Open
Jc2k opened this issue Jan 11, 2019 · 3 comments
Open
Assignees
Labels
BLE Transport Issues related to BLE based Accessory bug

Comments

@Jc2k
Copy link
Collaborator

Jc2k commented Jan 11, 2019

A bug, but not the most critical.

It only works now if its called before something that establishes a secure session. Thankfully thats the case with our current pairing code.

The spec says we should call this over secure session after pairing.

@jlusiardi jlusiardi added bug BLE Transport Issues related to BLE based Accessory labels Jan 12, 2019
@jlusiardi jlusiardi self-assigned this Jan 29, 2019
@jlusiardi
Copy link
Owner

Hi,

i guess this fragment serves as reproducible test for this issue?

import json
import argparse

from homekit.controller import Controller
from homekit.log_support import setup_logging, add_log_arguments


def setup_args_parser():
    parser = argparse.ArgumentParser(description='HomeKit get accessories app')
    parser.add_argument('-f', action='store', required=True, dest='file', help='File with the pairing data')
    parser.add_argument('-a', action='store', required=True, dest='alias', help='alias for the pairing')
    parser.add_argument('-o', action='store', dest='output', default='compact', choices=['json', 'compact'],
                        help='Specify output format')
    parser.add_argument('--adapter', action='store', dest='adapter', default='hci0',
                        help='the bluetooth adapter to be used (defaults to hci0)')
    add_log_arguments(parser)
    return parser.parse_args()


if __name__ == '__main__':
    args = setup_args_parser()

    controller = Controller(args.adapter)
    controller.load_data(args.file)

    pairing = controller.get_pairings()[args.alias]
    r = pairing.get_characteristics([(1, 4)])

    del pairing.pairing_data['accessories']
    setup_logging(args.loglevel)

    data = pairing.list_accessories_and_characteristics()

    print(json.dumps(data, indent=4))

The issue is, that list_accessories_and_characteristics() does not take into account if there is a secure connection or not and tries to perform an unsecure read:

DEBUG:root:manufacturer specific data: 066d005c4d317d2d3605003e000102
DEBUG:root:advertising interval 6d
DEBUG:root:manufacturer specific data: 063101b8d12961a1b00a0002000102fe81f1b6
DEBUG:root:advertising interval 31
DEBUG:root:error with length of manufacturer data
DEBUG:root:remaining data: fe81f1b6
DEBUG:root:manufacturer specific data: 066d005c4d317d2d3605003e000102
DEBUG:root:advertising interval 6d
DEBUG:homekit.controller.ble_impl:resolved 8 services
DEBUG:homekit.controller.ble_impl:found service with UUID b0733e83-8434-4c00-a344-25d1c982a0ef (Unknown Service: B0733E83-8434-4C00-A344-25D1C982A0EF)
DEBUG:homekit.controller.ble_impl:      found characteristic with UUID b2fd7f2d-ead3-4f17-b16c-202ec758c697 (Unknown Characteristic B2FD7F2D-EAD3-4F17-B16C-202EC758C697)
DEBUG:homekit.controller.ble_impl:              read characteristic id 1003
DEBUG:homekit.controller.ble_impl.device:read failed: <homekit.controller.ble_impl.gatt.Characteristic object at 0x7f1ceeb71b38> Read not permitted
Traceback (most recent call last):
  File "homekit/test80.py", line 50, in <module>
    data = pairing.list_accessories_and_characteristics()
  File "/home/jlusiardi/Dokumente/src/homekit_python/homekit/controller/ble_impl/__init__.py", line 72, in list_accessories_and_characteristics
    resolved_data = read_characteristics(device)
  File "/home/jlusiardi/Dokumente/src/homekit_python/homekit/controller/ble_impl/__init__.py", line 568, in read_characteristics
    d = parse_sig_read_response(characteristic.read_value(), tid)
  File "/home/jlusiardi/Dokumente/src/homekit_python/homekit/controller/ble_impl/__init__.py", line 591, in parse_sig_read_response
    logger.debug('parse sig read response %s', bytes([int(a) for a in data]).hex())
TypeError: 'NoneType' object is not iterable
DEBUG:homekit.controller.ble_impl:closing session

@Jc2k
Copy link
Collaborator Author

Jc2k commented Jan 29, 2019

Exactly on both counts. Although as Apple advise to do this over a secure session after pairing and we already have a pairing to use this method, I wonder if it should be updated to always create a secure session if one doesn't exist like the other methods on pairing?

jlusiardi added a commit that referenced this issue Jan 29, 2019
jlusiardi added a commit that referenced this issue Jan 29, 2019
@jlusiardi
Copy link
Owner

made some little progress. but this tends to render the accessory to a state were I have to factory reset :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLE Transport Issues related to BLE based Accessory bug
Projects
None yet
Development

No branches or pull requests

2 participants