mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-17 21:53:57 +02:00
Update keygen to fix index alignment
This commit is contained in:
@@ -5,7 +5,8 @@ Example showing how to retrieve the primary key of your own AirTag, or any other
|
||||
This key can be used to retrieve the device's location for a single day.
|
||||
"""
|
||||
import plistlib
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from findmy import FindMyAccessory
|
||||
|
||||
@@ -13,11 +14,11 @@ from findmy import FindMyAccessory
|
||||
# For nearby devices, you can use `device_scanner.py` to find it.
|
||||
PUBLIC_KEY = ""
|
||||
# Path to a .plist dumped from the Find My app.
|
||||
PLIST_PATH = "airtag.plist"
|
||||
PLIST_PATH = Path("airtag.plist")
|
||||
|
||||
# == The variables below are auto-filled from the plist!! ==
|
||||
|
||||
with open(PLIST_PATH, "rb") as f:
|
||||
with PLIST_PATH.open("rb") as f:
|
||||
device_data = plistlib.load(f)
|
||||
|
||||
# PRIVATE master key. 28 (?) bytes.
|
||||
@@ -29,30 +30,34 @@ SKN = device_data["sharedSecret"]["key"]["data"]
|
||||
# "Secondary" shared secret. 32 bytes.
|
||||
SKS = device_data["secondarySharedSecret"]["key"]["data"]
|
||||
|
||||
# Lookahead in time slots. Each time slot is 15 minutes.
|
||||
# Should be AT LEAST the time that has passed since you paired the accessory!
|
||||
delta = datetime.now() - device_data["pairingDate"]
|
||||
MAX_LOOKAHEAD = int(delta.total_seconds() / (15 * 60)) + 1
|
||||
|
||||
|
||||
def main() -> None:
|
||||
airtag = FindMyAccessory(MASTER_KEY, SKN, SKS)
|
||||
paired_at = device_data["pairingDate"].replace(tzinfo=timezone.utc)
|
||||
airtag = FindMyAccessory(MASTER_KEY, SKN, SKS, paired_at)
|
||||
|
||||
now = datetime.now(tz=timezone.utc)
|
||||
lookup_time = paired_at.replace(
|
||||
minute=paired_at.minute // 15 * 15,
|
||||
second=0,
|
||||
microsecond=0
|
||||
) + timedelta(minutes=15)
|
||||
|
||||
while lookup_time < now:
|
||||
keys = airtag.keys_at(lookup_time)
|
||||
for key in keys:
|
||||
if key.adv_key_b64 != PUBLIC_KEY:
|
||||
continue
|
||||
|
||||
for i in range(MAX_LOOKAHEAD):
|
||||
prim_key, sec_key = airtag.keys_at(i)
|
||||
if PUBLIC_KEY in (prim_key.adv_key_b64, sec_key.adv_key_b64):
|
||||
print("KEY FOUND!!")
|
||||
print(f"This key was found at index {i}."
|
||||
f" It was likely paired approximately {i * 15} minutes ago.")
|
||||
print()
|
||||
print("KEEP THE BELOW KEY SECRET! IT CAN BE USED TO RETRIEVE THE DEVICE'S LOCATION!")
|
||||
if prim_key.adv_key_b64 == PUBLIC_KEY:
|
||||
print(f"PRIMARY key: {prim_key.private_key_b64}")
|
||||
else:
|
||||
print(f"SECONDARY key: {sec_key.private_key_b64}")
|
||||
break
|
||||
else:
|
||||
print("No match found! :(")
|
||||
print(f" - Key: {key.private_key_b64}")
|
||||
print(f" - Approx. Time: {lookup_time}")
|
||||
print(f" - Type: {key.key_type}")
|
||||
return
|
||||
|
||||
lookup_time += timedelta(minutes=15)
|
||||
|
||||
print("No match found! :(")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user