mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2025-01-09 17:33:47 +00:00
add --reregister flag
This commit is contained in:
parent
4c345a0377
commit
3151089f3e
2 changed files with 17 additions and 4 deletions
16
demo.py
16
demo.py
|
@ -14,6 +14,7 @@ import ids
|
||||||
import imessage
|
import imessage
|
||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
import argparse
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.NOTSET, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()]
|
level=logging.NOTSET, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()]
|
||||||
|
@ -64,7 +65,7 @@ def safe_config():
|
||||||
with open("config.json", "w") as f:
|
with open("config.json", "w") as f:
|
||||||
json.dump(CONFIG, f, indent=4)
|
json.dump(CONFIG, f, indent=4)
|
||||||
|
|
||||||
async def main():
|
async def main(args: argparse.Namespace):
|
||||||
# Load any existing push credentials
|
# Load any existing push credentials
|
||||||
token = CONFIG.get("push", {}).get("token")
|
token = CONFIG.get("push", {}).get("token")
|
||||||
token = b64decode(token) if token is not None else b""
|
token = b64decode(token) if token is not None else b""
|
||||||
|
@ -146,6 +147,14 @@ async def main():
|
||||||
})
|
})
|
||||||
safe_config()
|
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:
|
# You CANNOT turn around and re-register like this:
|
||||||
# It will BREAK the tie between phone number and Apple ID
|
# 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__":
|
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)
|
|
@ -117,6 +117,7 @@ def register(push_connection: apns.APNSConnection, users: list[IDSUser], validat
|
||||||
# Construct user payloads
|
# Construct user payloads
|
||||||
user_payloads = []
|
user_payloads = []
|
||||||
for user in users:
|
for user in users:
|
||||||
|
if user.handles == []:
|
||||||
user.handles = user.possible_handles()
|
user.handles = user.possible_handles()
|
||||||
if user.encryption_identity is not None:
|
if user.encryption_identity is not None:
|
||||||
special_data = DEFAULT_CLIENT_DATA.copy()
|
special_data = DEFAULT_CLIENT_DATA.copy()
|
||||||
|
@ -125,7 +126,7 @@ def register(push_connection: apns.APNSConnection, users: list[IDSUser], validat
|
||||||
special_data = DEFAULT_CLIENT_DATA
|
special_data = DEFAULT_CLIENT_DATA
|
||||||
user_payloads.append({
|
user_payloads.append({
|
||||||
"client-data": special_data,
|
"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],
|
"uris": [{"uri": handle} for handle in user.handles],
|
||||||
"user-id": user.user_id,
|
"user-id": user.user_id,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue