mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2025-01-09 17:33:47 +00:00
stash trying to test sms registration
This commit is contained in:
parent
d5faef2cbc
commit
af71383f5d
3 changed files with 64 additions and 10 deletions
31
demo.py
31
demo.py
|
@ -46,7 +46,7 @@ except FileNotFoundError:
|
||||||
CONFIG = {}
|
CONFIG = {}
|
||||||
|
|
||||||
# Re-register if the commit hash has changed
|
# Re-register if the commit hash has changed
|
||||||
if CONFIG.get("commit_hash") != commit_hash:
|
if CONFIG.get("commit_hash") != commit_hash or True:
|
||||||
logging.warning("pypush commit is different, forcing re-registration...")
|
logging.warning("pypush commit is different, forcing re-registration...")
|
||||||
CONFIG["commit_hash"] = commit_hash
|
CONFIG["commit_hash"] = commit_hash
|
||||||
if "id" in CONFIG:
|
if "id" in CONFIG:
|
||||||
|
@ -86,11 +86,35 @@ async def main():
|
||||||
|
|
||||||
user.authenticate(username, password)
|
user.authenticate(username, password)
|
||||||
|
|
||||||
|
import sms_registration
|
||||||
|
phone_sig = safe_b64decode(CONFIG.get("phone", {}).get("sig"))
|
||||||
|
phone_number = CONFIG.get("phone", {}).get("number")
|
||||||
|
|
||||||
|
if phone_sig is None or phone_number is None:
|
||||||
|
print("Registering phone number...")
|
||||||
|
phone_number, phone_sig = sms_registration.register(user.push_connection.credentials.token)
|
||||||
|
CONFIG["phone"] = {
|
||||||
|
"number": phone_number,
|
||||||
|
"sig": b64encode(phone_sig).decode(),
|
||||||
|
}
|
||||||
|
if CONFIG.get("phone", {}).get("auth_key") is not None:
|
||||||
|
phone_auth_keypair = ids._helpers.KeyPair(CONFIG["phone"]["auth_key"], CONFIG["phone"]["auth_cert"])
|
||||||
|
else:
|
||||||
|
phone_auth_keypair = ids.profile.get_phone_cert(phone_number, user.push_connection.credentials.token, [phone_sig])
|
||||||
|
CONFIG["phone"]["auth_key"] = phone_auth_keypair.key
|
||||||
|
CONFIG["phone"]["auth_cert"] = phone_auth_keypair.cert
|
||||||
|
|
||||||
|
|
||||||
user.encryption_identity = ids.identity.IDSIdentity(
|
user.encryption_identity = ids.identity.IDSIdentity(
|
||||||
encryption_key=CONFIG.get("encryption", {}).get("rsa_key"),
|
encryption_key=CONFIG.get("encryption", {}).get("rsa_key"),
|
||||||
signing_key=CONFIG.get("encryption", {}).get("ec_key"),
|
signing_key=CONFIG.get("encryption", {}).get("ec_key"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#user._auth_keypair = phone_auth_keypair
|
||||||
|
#user.handles = [f"tel:{phone_number}"]
|
||||||
|
#user.user_id = f"P:{phone_number}"
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
CONFIG.get("id", {}).get("cert") is not None
|
CONFIG.get("id", {}).get("cert") is not None
|
||||||
and user.encryption_identity is not None
|
and user.encryption_identity is not None
|
||||||
|
@ -104,7 +128,10 @@ async def main():
|
||||||
vd = emulated.nac.generate_validation_data()
|
vd = emulated.nac.generate_validation_data()
|
||||||
vd = b64encode(vd).decode()
|
vd = b64encode(vd).decode()
|
||||||
|
|
||||||
user.register(vd)
|
user.register(vd, [("P:" + phone_number, phone_auth_keypair)], ["tel:" + phone_number, "tel:1"])
|
||||||
|
#user.register(vd)
|
||||||
|
|
||||||
|
print("Handles: ", user.handles)
|
||||||
|
|
||||||
# Write config.json
|
# Write config.json
|
||||||
CONFIG["encryption"] = {
|
CONFIG["encryption"] = {
|
||||||
|
|
|
@ -50,7 +50,7 @@ class IDSUser:
|
||||||
|
|
||||||
# Uses an existing authentication keypair
|
# Uses an existing authentication keypair
|
||||||
def restore_authentication(
|
def restore_authentication(
|
||||||
self, auth_keypair: _helpers.KeyPair, user_id: str, handles: dict
|
self, auth_keypair: _helpers.KeyPair, user_id: str, handles: list
|
||||||
):
|
):
|
||||||
self._auth_keypair = auth_keypair
|
self._auth_keypair = auth_keypair
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
|
@ -58,7 +58,7 @@ class IDSUser:
|
||||||
self.current_handle = self.handles[0]
|
self.current_handle = self.handles[0]
|
||||||
|
|
||||||
# This is a separate call so that the user can make sure the first part succeeds before asking for validation data
|
# This is a separate call so that the user can make sure the first part succeeds before asking for validation data
|
||||||
def register(self, validation_data: str):
|
def register(self, validation_data: str, additional_keys: list[tuple[str, _helpers.KeyPair]] = [], additional_handles: list[str] = []):
|
||||||
"""
|
"""
|
||||||
self.ec_key, self.rsa_key will be set to a randomly gnenerated EC and RSA keypair
|
self.ec_key, self.rsa_key will be set to a randomly gnenerated EC and RSA keypair
|
||||||
if they are not already set
|
if they are not already set
|
||||||
|
@ -66,18 +66,34 @@ class IDSUser:
|
||||||
if self.encryption_identity is None:
|
if self.encryption_identity is None:
|
||||||
self.encryption_identity = identity.IDSIdentity()
|
self.encryption_identity = identity.IDSIdentity()
|
||||||
|
|
||||||
|
auth_keys = [(self.user_id, self._auth_keypair)]
|
||||||
|
auth_keys.extend(additional_keys)
|
||||||
|
|
||||||
|
handles_request = self.handles
|
||||||
|
|
||||||
|
handles_request.extend(additional_handles)
|
||||||
|
|
||||||
|
|
||||||
cert = identity.register(
|
cert = identity.register(
|
||||||
b64encode(self.push_connection.credentials.token),
|
b64encode(self.push_connection.credentials.token),
|
||||||
self.handles,
|
self.handles,
|
||||||
self.user_id,
|
self.user_id,
|
||||||
self._auth_keypair,
|
auth_keys,
|
||||||
self._push_keypair,
|
self._push_keypair,
|
||||||
self.encryption_identity,
|
self.encryption_identity,
|
||||||
validation_data,
|
validation_data,
|
||||||
)
|
)
|
||||||
self._id_keypair = _helpers.KeyPair(self._auth_keypair.key, cert)
|
self._id_keypair = _helpers.KeyPair(self._auth_keypair.key, cert)
|
||||||
|
|
||||||
|
# Refresh handles
|
||||||
|
self.handles = profile.get_handles(
|
||||||
|
b64encode(self.push_connection.credentials.token),
|
||||||
|
self.user_id,
|
||||||
|
self._auth_keypair,
|
||||||
|
self._push_keypair,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def restore_identity(self, id_keypair: _helpers.KeyPair):
|
def restore_identity(self, id_keypair: _helpers.KeyPair):
|
||||||
self._id_keypair = id_keypair
|
self._id_keypair = id_keypair
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ class IDSIdentity:
|
||||||
return output.getvalue()
|
return output.getvalue()
|
||||||
|
|
||||||
def register(
|
def register(
|
||||||
push_token, handles, user_id, auth_key: KeyPair, push_key: KeyPair, identity: IDSIdentity, validation_data
|
push_token, handles, user_id, auth_keys: list[tuple[str, KeyPair]], push_key: KeyPair, identity: IDSIdentity, validation_data
|
||||||
):
|
):
|
||||||
logger.debug(f"Registering IDS identity for {handles}")
|
logger.debug(f"Registering IDS identity for {handles}")
|
||||||
uris = [{"uri": handle} for handle in handles]
|
uris = [{"uri": handle} for handle in handles]
|
||||||
|
@ -141,20 +141,31 @@ def register(
|
||||||
},
|
},
|
||||||
"uris": uris,
|
"uris": uris,
|
||||||
"user-id": user_id,
|
"user-id": user_id,
|
||||||
}
|
|
||||||
|
},
|
||||||
|
# {
|
||||||
|
# "uris": uris,
|
||||||
|
# "user-id": auth_keys[1][0]
|
||||||
|
# }
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"validation-data": b64decode(validation_data),
|
"validation-data": b64decode(validation_data),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug(body)
|
||||||
|
|
||||||
body = plistlib.dumps(body)
|
body = plistlib.dumps(body)
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"x-protocol-version": PROTOCOL_VERSION,
|
"x-protocol-version": PROTOCOL_VERSION,
|
||||||
"x-auth-user-id-0": user_id,
|
#"x-auth-user-id-0": user_id,
|
||||||
}
|
}
|
||||||
add_auth_signature(headers, body, "id-register", auth_key, push_key, push_token, 0)
|
for i, (user_id, keypair) in enumerate(auth_keys):
|
||||||
|
headers[f"x-auth-user-id-{i}"] = user_id
|
||||||
|
add_auth_signature(headers, body, "id-register", keypair, push_key, push_token, i)
|
||||||
|
|
||||||
|
print(headers)
|
||||||
|
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
"https://identity.ess.apple.com/WebObjects/TDIdentityService.woa/wa/register",
|
"https://identity.ess.apple.com/WebObjects/TDIdentityService.woa/wa/register",
|
||||||
|
|
Loading…
Reference in a new issue