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

Support s2k_fo #115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 12 additions & 5 deletions endpoint/register/pypush_gsa_icloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def gsa_authenticate(username, password):
r = gsa_authenticated_request(
{"A2k": A, "ps": ["s2k", "s2k_fo"], "u": username, "o": "init"})

if r["sp"] != "s2k":
if r["sp"] not in ["s2k", "s2k_fo"]:
logger.warn(
f"This implementation only supports s2k. Server returned {r['sp']}")
f"This implementation only supports s2k and s2k_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"], protocol=r["sp"])

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

Expand Down Expand Up @@ -190,8 +190,15 @@ def generate_meta_headers(serial="0", user_id=uuid.uuid4(), device_id=uuid.uuid4
}


def encrypt_password(password, salt, iterations):
p = hashlib.sha256(password.encode("utf-8")).digest()
def encrypt_password(password, salt, iterations, protocol="s2k"):
hash = hashlib.sha256(password.encode("utf-8"))
if protocol == "s2k":
p = hash.digest()
elif protocol == "s2k_fo":
p = hash.hexdigest().encode("utf-8")
else:
raise Exception("Unknown protocol")

return pbkdf2.PBKDF2(p, salt, iterations, SHA256).read(32)


Expand Down