Skip to content

aioble: Add pairing and bonding multitests #1021

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andrewleech
Copy link
Contributor

Summary

Adds comprehensive multitests for BLE pairing and bonding functionality to the aioble library.

New Tests Added

1. ble_pair.py - Pairing without persistent bonding

  • Tests encryption with bond=False
  • Verifies temporary pairing that doesn't persist
  • Expected result: encrypted=1 authenticated=0 bonded=0

2. ble_bond.py - Pairing with persistent bonding

  • Tests encryption with bond=True
  • Verifies persistent bonding with secret storage
  • Expected result: encrypted=1 authenticated=0 bonded=1 + secrets_exist yes

Technical Implementation

  • Custom EncryptedCharacteristic: Extends aioble.Characteristic with _FLAG_READ_ENCRYPTED to require pairing for access
  • Cross-compatibility: Works with both BTstack and NimBLE implementations
  • State management: Proper timing and bond file management for deterministic testing
  • Comprehensive coverage: Tests pairing initiation, encryption, characteristic access, and bond persistence

Testing

Both tests pass consistently on BTstack-enabled MicroPython builds:

python ./tests/run-multitests.py -i pyb:/dev/ttyACM0 -i pyb:/dev/ttyACM1 -t -p2 micropython/bluetooth/aioble/multitests/ble_pair.py
python ./tests/run-multitests.py -i pyb:/dev/ttyACM0 -i pyb:/dev/ttyACM1 -t -p2 micropython/bluetooth/aioble/multitests/ble_bond.py

Motivation

These tests fill a critical gap in aioble testing coverage by providing:

  • Validation of security features (pairing/bonding)
  • Verification of encrypted characteristic access
  • Regression testing for BTstack pairing improvements
  • Examples for developers implementing secure BLE applications

The tests complement the recent BTstack pairing/bonding implementation and demonstrate that aioble's async API works correctly with the underlying security features.

🤖 Generated with Claude Code

@andrewleech
Copy link
Contributor Author

This was used to test micropython/micropython#17469 and was run with a RPI_PICO2_W and PYBD_SF^

Adds comprehensive tests for BLE pairing and bonding functionality:

- ble_pair.py: Tests encryption without persistent bonding (bond=False)
- ble_bond.py: Tests encryption with persistent bonding (bond=True)

Both tests verify:
- Encrypted characteristic access requiring pairing
- Proper connection state tracking (encrypted, authenticated, bonded)
- Cross-compatibility with BTstack implementation
- Bond storage via aioble.security module

Tests use custom EncryptedCharacteristic class to add _FLAG_READ_ENCRYPTED
requirement, ensuring pairing is mandatory for characteristic access.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant