diff --git a/demo.py b/demo.py index 1c31a2e..de1e870 100644 --- a/demo.py +++ b/demo.py @@ -14,6 +14,7 @@ import ids import imessage import trio +import argparse logging.basicConfig( level=logging.NOTSET, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()] @@ -64,7 +65,7 @@ def safe_config(): with open("config.json", "w") as f: json.dump(CONFIG, f, indent=4) -async def main(): +async def main(args: argparse.Namespace): # Load any existing push credentials token = CONFIG.get("push", {}).get("token") token = b64decode(token) if token is not None else b"" @@ -146,6 +147,14 @@ async def main(): }) safe_config() + if args.reregister: + print("Re-registering...") + import emulated.nac + vd = emulated.nac.generate_validation_data() + vd = b64encode(vd).decode() + users = ids.register(conn, users, vd) + + # You CANNOT turn around and re-register like this: # It will BREAK the tie between phone number and Apple ID @@ -275,4 +284,7 @@ async def output_task(im: imessage.iMessageUser): if __name__ == "__main__": - trio.run(main) \ No newline at end of file + parser = argparse.ArgumentParser() + parser.add_argument("--reregister", action="store_true", help="Force re-registration") + args = parser.parse_args() + trio.run(main, args) \ No newline at end of file diff --git a/ids/__init__.py b/ids/__init__.py index c433257..af8cab2 100644 --- a/ids/__init__.py +++ b/ids/__init__.py @@ -117,7 +117,8 @@ def register(push_connection: apns.APNSConnection, users: list[IDSUser], validat # Construct user payloads user_payloads = [] for user in users: - user.handles = user.possible_handles() + if user.handles == []: + user.handles = user.possible_handles() if user.encryption_identity is not None: special_data = DEFAULT_CLIENT_DATA.copy() special_data["public-message-identity-key"] = user.encryption_identity.encode() @@ -125,7 +126,7 @@ def register(push_connection: apns.APNSConnection, users: list[IDSUser], validat special_data = DEFAULT_CLIENT_DATA user_payloads.append({ "client-data": special_data, - "tag": "SIM" if isinstance(user, IDSPhoneUser) else None, + "tag": "SIM" if user.user_id.startswith("P:") else None, "uris": [{"uri": handle} for handle in user.handles], "user-id": user.user_id, })