Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/bugfix pypush_gsa_icloud.py #68

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pypush_gsa_icloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def gsa_authenticate(username, password, second_factor='sms'):

r = gsa_authenticated_request({"A2k": A, "ps": ["s2k", "s2k_fo"], "u": username, "o": "init"})

if r["sp"] != "s2k":
print(f"This implementation only supports s2k. Server returned {r['sp']}")
if r["sp"] not in ["s2k", "s2k_fo"]:
print(f"This implementation only supports s2k and sk2_fo. Server returned {r['sp']}")
return

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

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

Expand Down Expand Up @@ -197,8 +197,11 @@ def generate_meta_headers(serial="0", user_id=uuid.uuid4(), device_id=uuid.uuid4
"X-Apple-I-SRL-NO": serial, # Serial number
}

def encrypt_password(password, salt, iterations):
def encrypt_password(password, salt, iterations, protocol):
assert protocol in ["s2k", "s2k_fo"]
p = hashlib.sha256(password.encode("utf-8")).digest()
if protocol == "s2k_fo":
p = p.hex().encode("utf-8")
return pbkdf2.PBKDF2(p, salt, iterations, SHA256).read(32)

def create_session_key(usr, name):
Expand Down