From cd1e72d2586e407858d465febd7d8be6637b57b8 Mon Sep 17 00:00:00 2001 From: Matthias Urhahn Date: Fri, 11 Jul 2025 08:42:35 +0200 Subject: [PATCH] Updated AirPod Keys (markdown) --- AirPod-Keys.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/AirPod-Keys.md b/AirPod-Keys.md index c0c1a7e..98ccbe1 100644 --- a/AirPod-Keys.md +++ b/AirPod-Keys.md @@ -105,7 +105,72 @@ Any MacOS version should work. This example is from a Mac Air (M1) running Sonom ### Linux -You can retrieve the keys on Linux using the [Home Assistant Private BLE Device Integration](https://www.home-assistant.io/integrations/private_ble_device/). This integration allows you to extract the necessary information from the AirPods. +You can retrieve the keys via this custom script, thanks to [@kavishdevar](https://github.com/kavishdevar) :heart: + +```python +import sys +import socket + +PROXIMITY_KEY_TYPES = { + 0x01: "IRK", + 0x04: "ENC_KEY", +} + +def parse_proximity_keys_response(data): + if len(data) < 7 or data[4] != 0x31: + return None + key_count = data[6] + keys = [] + offset = 7 + for _ in range(key_count): + if offset + 3 >= len(data): + break + key_type = data[offset] + key_length = data[offset + 2] + offset += 4 + if offset + key_length > len(data): + break + key_bytes = data[offset:offset + key_length] + keys.append((PROXIMITY_KEY_TYPES.get(key_type, f"TYPE_{key_type:02X}"), key_bytes)) + offset += key_length + return keys + +def hexdump(data): + return " ".join(f"{b:02X}" for b in data) + +def main(): + if len(sys.argv) != 2: + print(f"Usage: {sys.argv[0]} ") + sys.exit(1) + + bdaddr = sys.argv[1] + PSM = 0x1001 + + handshake = bytes.fromhex("00 00 04 00 01 00 02 00 00 00 00 00 00 00 00 00") + key_req = bytes.fromhex("04 00 04 00 30 00 05 00") + + sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET, socket.BTPROTO_L2CAP) + sock.connect((bdaddr, PSM)) + sock.send(handshake) + sock.send(key_req) + + try: + while True: + pkt = sock.recv(1024) + keys = parse_proximity_keys_response(pkt) + if keys is not None: + print("Proximity Keys:") + for name, key_bytes in keys: + print(f" {name}: {hexdump(key_bytes)}") + break + finally: + sock.close() + +if __name__ == "__main__": + main() +``` + +_Via https://github.com/d4rken-org/capod/issues/290#issuecomment-3046151031_ ### Windows