mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
Add private key export support
- Add PRIVATE_KEY and DISABLED event types - Add packet parsing for private key export responses - Add export_private_key() method to DeviceCommands - Add comprehensive unit tests - Add BLE private key export example - Update documentation with security notes
This commit is contained in:
parent
c697c960a6
commit
e0f71482c6
6 changed files with 305 additions and 0 deletions
30
README.md
30
README.md
|
|
@ -515,6 +515,8 @@ All commands are async methods that return `Event` objects. Commands are organiz
|
|||
| **Device Actions** ||||
|
||||
| `send_advert(flood=False)` | `flood: bool` | `OK` | Send advertisement (optionally flood network) |
|
||||
| `reboot()` | None | None | Reboot device (no response expected) |
|
||||
| **Security** ||||
|
||||
| `export_private_key()` | None | `PRIVATE_KEY/DISABLED` | Export device private key (requires PIN auth & enabled firmware) |
|
||||
|
||||
#### Contact Commands (`meshcore.commands.*`)
|
||||
|
||||
|
|
@ -601,6 +603,33 @@ meshcore.subscribe(
|
|||
)
|
||||
```
|
||||
|
||||
## Private Key Export Example
|
||||
|
||||
Export your device's private key over BLE (requires PIN pairing and supported firmware):
|
||||
|
||||
```python
|
||||
import asyncio
|
||||
from meshcore import MeshCore, EventType
|
||||
|
||||
async def main():
|
||||
# Connect to device over BLE with PIN authentication
|
||||
meshcore = await MeshCore.create_ble(address="12:34:56:78:90:AB", pin="123456")
|
||||
|
||||
# Export the private key
|
||||
result = await meshcore.commands.export_private_key()
|
||||
|
||||
if result.type == EventType.PRIVATE_KEY:
|
||||
private_key = result.payload["private_key"] # 64 bytes
|
||||
print(f"Private key: {private_key.hex()}")
|
||||
elif result.type == EventType.DISABLED:
|
||||
print("Private key export is disabled on this device.")
|
||||
|
||||
await meshcore.disconnect()
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
|
||||
|
||||
## Examples in the Repo
|
||||
|
||||
Check the `examples/` directory for more:
|
||||
|
|
@ -609,5 +638,6 @@ Check the `examples/` directory for more:
|
|||
- `serial_infos.py`: Quick device info retrieval
|
||||
- `serial_msg.py`: Message sending and receiving
|
||||
- `ble_pin_pairing_example.py`: BLE connection with PIN pairing
|
||||
- `ble_private_key_export.py`: BLE private key export with PIN authentication
|
||||
- `ble_t1000_infos.py`: BLE connections
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue