add --reregister flag

This commit is contained in:
JJTech0130 2023-08-27 09:27:24 -04:00
parent 4c345a0377
commit 3151089f3e
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6
2 changed files with 17 additions and 4 deletions

16
demo.py
View file

@ -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)
parser = argparse.ArgumentParser()
parser.add_argument("--reregister", action="store_true", help="Force re-registration")
args = parser.parse_args()
trio.run(main, args)

View file

@ -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,
})