-
Notifications
You must be signed in to change notification settings - Fork 62
Newly implemented GCM encryption method #442
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Implements support for SwitchBot’s upcoming AES-GCM encryption mode (alongside existing AES-CTR) for encrypted BLE devices.
Changes:
- Added
AESModedetection from the encryption init response and mode-specific IV parsing (CTR=16 bytes, GCM=12 bytes with padding trim). - Updated encryption/decryption flow to support GCM (including returning a 2-byte header derived from the GCM tag and incrementing GCM IV after encrypted commands).
- Expanded unit tests to cover mode resolution, GCM IV increment behavior, and updated
_encryptreturn shape.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
switchbot/devices/device.py |
Adds AES mode enum/detection, GCM-specific IV parsing, encryption/decryption changes, and GCM IV increment logic. |
tests/test_encrypted_device.py |
Updates tests for new _encrypt return type and adds coverage for GCM mode behavior and mode resolution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks @zerzhang I did some tweaks. If its all still working as expected, please let me know and I'll merge and do a release. |
@bdraco All works well |
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Breaking change
SwitchBot will be implementing the new AES_GCM encryption method in its upcoming firmware update.
Switchbot Encryption Modes (CTR/GCM)
Mode Identification
2) indicates the encryption mode:0x00: AES-CTR0x01: AES-GCM0x00/0x01will throw an exception.IV Parsing
result[4:]from the random number response, length is 16 bytes.result[4:-4]from the random number response, length is 12 bytes (the last 4 bytes are for compatibility padding).GCM IV Increment Rule
GCM Tag Handling
decryptor.update(...), notfinalize().