Skip to content

Commit 0ffb6f7

Browse files
authored
Bugfixes in the AirTagGeneration scripts (#68)
* Add .gitignore * Add support for s2k_fo password encryption * Add required endianness parameter to int.from_bytes()
1 parent 0d9529a commit 0ffb6f7

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

AirTagGeneration/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data.json
2+
LocationMap_*.html
3+
venv/
4+
keys/*

AirTagGeneration/cores/pypush_gsa_icloud.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ def gsa_authenticate(username, password, second_factor='sms'):
7575
if "sp" not in r:
7676
print("Authentication Failed. Check your Apple ID and password.")
7777
raise Exception("AuthenticationError")
78-
if r["sp"] != "s2k":
79-
print(f"This implementation only supports s2k. Server returned {r['sp']}")
78+
if r["sp"] != "s2k" and r["sp"] != "s2k_fo":
79+
print(f"This implementation only supports s2k and s2k_fo. Server returned {r['sp']}")
8080
return
8181

8282
# Change the password out from under the SRP library, as we couldn't calculate it without the salt.
83-
usr.p = encrypt_password(password, r["s"], r["i"])
83+
usr.p = encrypt_password(password, r["s"], r["i"], r["sp"] == "s2k_fo")
8484

8585
M = usr.process_challenge(r["s"], r["B"])
8686

@@ -207,8 +207,9 @@ def generate_meta_headers(serial="0", user_id=uuid.uuid4(), device_id=uuid.uuid4
207207
}
208208

209209

210-
def encrypt_password(password, salt, iterations):
211-
p = hashlib.sha256(password.encode("utf-8")).digest()
210+
def encrypt_password(password, salt, iterations, hex=False):
211+
hash = hashlib.sha256(password.encode("utf-8"))
212+
p = hash.hexdigest() if hex else hash.digest()
212213
return pbkdf2.PBKDF2(p, salt, iterations, SHA256).read(32)
213214

214215

AirTagGeneration/request_reports.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def decrypt(enc_data, algorithm_dkey, mode):
3131
def decode_tag(data):
3232
latitude = struct.unpack(">i", data[0:4])[0] / 10000000.0
3333
longitude = struct.unpack(">i", data[4:8])[0] / 10000000.0
34-
confidence = int.from_bytes(data[8:9])
35-
status = int.from_bytes(data[9:10])
34+
confidence = int.from_bytes(data[8:9], 'big')
35+
status = int.from_bytes(data[9:10], 'big')
3636
return {'lat': latitude, 'lon': longitude, 'conf': confidence, 'status': status}
3737

3838

0 commit comments

Comments
 (0)