Skip to content

Add grab-locks-from-api: extract lock secrets via TTLock management API - #2

Open
nsleigh wants to merge 8 commits into
bazuchan:masterfrom
nsleigh:feature/grab-locks-from-api
Open

Add grab-locks-from-api: extract lock secrets via TTLock management API#2
nsleigh wants to merge 8 commits into
bazuchan:masterfrom
nsleigh:feature/grab-locks-from-api

Conversation

@nsleigh

@nsleigh nsleigh commented Jun 26, 2026

Copy link
Copy Markdown

Thanks for sharing this code, I was concerned about not having local control of the lock and now I have it. As I didn't have an Android I had to use another method to get the keys - with the help of Claude (and your code) I created a script to run against the API and thought I'd share it.

NOTE: this is an update to the previous PR with "grad" renamed to "grab".

Summary

  • Adds a new grab-locks-from-api/ directory with a Python script to extract lock secrets (MAC address, AES key, admin_ps, unlock_key) from the TTLock management API
  • No rooted device required — uses TTLock developer API credentials instead of the app database
  • Credentials are loaded from a gitignored .env file to avoid accidental secret commits

Details

The script authenticates via OAuth to the TTLock API and retrieves all lock keys associated with the account. It decodes the aesKeyStr, adminPwd, and lockKey fields using the same TABLE-based XOR algorithm as grab-locks-from-app/db2locks.py, producing values ready for use in ESPHome secrets.yaml.

Output

===== Hardware Found: XXNNN_ffeedd =====
MAC Address             : AA:BB:CC:DD:EE:FF
Lock ID (lock_id)       : 12345678
AES Key (lock_key)      : __aes_key_32_characters__
Admin PS (admin_ps)     : 0x11111111
Unlock Key (unlock_key) : 0x88888888
=============================================

🤖 Generated with Claude Code

nsleigh and others added 8 commits June 25, 2026 14:16
Provides an alternative to the database extraction method that doesn't
require a rooted device — uses the TTLock management API to retrieve
lock MAC addresses and AES keys via OAuth credentials.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds python-dotenv support so credentials are read from a gitignored
.env file rather than hardcoded in the script. Also fixes Windows
console encoding and updates README with install step.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use the aesKeyStr field from the API response instead of lockKey, as it
contains the correct 16-byte key in comma-separated hex format.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Decodes adminPwd and lockKey fields using the same TABLE-based XOR
algorithm as the database extractor to produce the values needed
for ESPHome secrets.yaml.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix typo in folder name and update all references in README files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant