2023-05-02 12:39:11 +00:00
|
|
|
import json
|
2023-05-09 21:03:27 +00:00
|
|
|
from base64 import b64encode
|
|
|
|
from getpass import getpass
|
2023-05-09 22:43:51 +00:00
|
|
|
from base64 import b64decode
|
2023-05-09 19:36:33 +00:00
|
|
|
import apns
|
2023-05-09 21:03:27 +00:00
|
|
|
import ids
|
2023-05-02 12:39:11 +00:00
|
|
|
|
2023-05-03 00:53:18 +00:00
|
|
|
|
2023-05-02 18:10:13 +00:00
|
|
|
def input_multiline(prompt):
|
|
|
|
print(prompt)
|
|
|
|
lines = []
|
|
|
|
while True:
|
|
|
|
line = input()
|
|
|
|
if line == "":
|
|
|
|
break
|
|
|
|
lines.append(line)
|
|
|
|
return "\n".join(lines)
|
|
|
|
|
2023-05-03 00:53:18 +00:00
|
|
|
|
2023-05-09 21:03:27 +00:00
|
|
|
# Try and load config.json
|
|
|
|
try:
|
|
|
|
with open("config.json", "r") as f:
|
2023-05-02 12:39:11 +00:00
|
|
|
|
2023-05-09 21:03:27 +00:00
|
|
|
CONFIG = json.load(f)
|
|
|
|
except FileNotFoundError:
|
|
|
|
CONFIG = {}
|
2023-05-02 12:39:11 +00:00
|
|
|
|
2023-05-09 22:43:51 +00:00
|
|
|
def convert_config(old):
|
|
|
|
new = {}
|
|
|
|
new["id"] = {
|
|
|
|
"key": old["key"],
|
|
|
|
"cert": old["ids_cert"],
|
|
|
|
}
|
|
|
|
new["auth"] = {
|
|
|
|
"key": old["key"],
|
|
|
|
"cert": old["auth_cert"],
|
|
|
|
"user_id": old["user_id"],
|
|
|
|
"handles": [
|
|
|
|
"mailto:user_test2@icloud.com",
|
|
|
|
]
|
|
|
|
#"handles": old["handles"],
|
|
|
|
}
|
|
|
|
new["push"] = {
|
|
|
|
"token": old["push"]["token"],
|
|
|
|
"key": old["push"]["key"],
|
|
|
|
"cert": old["push"]["cert"],
|
|
|
|
}
|
|
|
|
return new
|
|
|
|
|
|
|
|
CONFIG = convert_config(CONFIG)
|
|
|
|
|
2023-05-02 12:39:11 +00:00
|
|
|
|
2023-05-09 21:03:27 +00:00
|
|
|
conn = apns.APNSConnection(
|
|
|
|
CONFIG.get("push", {}).get("key"), CONFIG.get("push", {}).get("cert")
|
|
|
|
)
|
2023-05-09 22:43:51 +00:00
|
|
|
#print(CONFIG.get("push", {}).get("token"))
|
|
|
|
print(b64decode(CONFIG.get("push", {}).get("token")))
|
|
|
|
conn.connect(True, b64decode(CONFIG.get("push", {}).get("token")))
|
|
|
|
print(conn.token)
|
2023-05-02 17:40:06 +00:00
|
|
|
|
2023-05-09 21:03:27 +00:00
|
|
|
user = ids.IDSUser(conn)
|
2023-05-02 17:40:06 +00:00
|
|
|
|
2023-05-09 21:03:27 +00:00
|
|
|
if CONFIG.get("auth", {}).get("cert") is not None:
|
|
|
|
auth_keypair = ids._helpers.KeyPair(CONFIG["auth"]["key"], CONFIG["auth"]["cert"])
|
|
|
|
user_id = CONFIG["auth"]["user_id"]
|
|
|
|
handles = CONFIG["auth"]["handles"]
|
|
|
|
user.restore_authentication(auth_keypair, user_id, handles)
|
2023-05-02 18:10:13 +00:00
|
|
|
else:
|
2023-05-09 21:03:27 +00:00
|
|
|
username = input("Username: ")
|
|
|
|
password = getpass("Password: ")
|
2023-05-03 00:53:18 +00:00
|
|
|
|
2023-05-09 21:03:27 +00:00
|
|
|
user.authenticate(username, password)
|
2023-05-02 22:11:14 +00:00
|
|
|
|
2023-05-09 21:03:27 +00:00
|
|
|
if CONFIG.get("id", {}).get("cert") is not None:
|
|
|
|
id_keypair = ids._helpers.KeyPair(CONFIG["id"]["key"], CONFIG["id"]["cert"])
|
|
|
|
user.restore_identity(id_keypair)
|
|
|
|
else:
|
|
|
|
vd = input_multiline("Enter validation data: ")
|
|
|
|
user.register(vd)
|
|
|
|
|
2023-05-09 22:01:32 +00:00
|
|
|
print(user.lookup(["mailto:textgpt@icloud.com"]))
|
|
|
|
|
2023-05-09 21:03:27 +00:00
|
|
|
# Write config.json
|
|
|
|
CONFIG["id"] = {
|
|
|
|
"key": user._id_keypair.key,
|
|
|
|
"cert": user._id_keypair.cert,
|
|
|
|
}
|
|
|
|
CONFIG["auth"] = {
|
|
|
|
"key": user._auth_keypair.key,
|
|
|
|
"cert": user._auth_keypair.cert,
|
|
|
|
"user_id": user.user_id,
|
|
|
|
"handles": user.handles,
|
|
|
|
}
|
|
|
|
CONFIG["push"] = {
|
|
|
|
"token": b64encode(user.push_connection.token).decode(),
|
|
|
|
"key": user.push_connection.private_key,
|
|
|
|
"cert": user.push_connection.cert,
|
|
|
|
}
|
2023-05-03 00:51:02 +00:00
|
|
|
|
2023-05-09 22:43:51 +00:00
|
|
|
with open("config.json.new", "w") as f:
|
2023-05-03 00:53:18 +00:00
|
|
|
json.dump(CONFIG, f, indent=4)
|