mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2024-12-23 11:22:42 -06:00
whoops forgot to format
This commit is contained in:
parent
97fbdae4cb
commit
84d81be41f
1 changed files with 15 additions and 8 deletions
23
ids.py
23
ids.py
|
@ -158,12 +158,15 @@ def _auth_token_request(username: str, password: str) -> any:
|
|||
r = plistlib.loads(r.content)
|
||||
return r
|
||||
|
||||
|
||||
# Gets an IDS auth token for the given username and password
|
||||
# If use_gsa is True, GSA authentication will be used, which requires anisette
|
||||
# If use_gsa is False, it will use a old style 2FA code
|
||||
# If factor_gen is not None, it will be called to get the 2FA code, otherwise it will be prompted
|
||||
# Returns (realm user id, auth token)
|
||||
def _get_auth_token(username: str, password: str, use_gsa: bool = False, factor_gen: callable = None) -> tuple[str, str]:
|
||||
def _get_auth_token(
|
||||
username: str, password: str, use_gsa: bool = False, factor_gen: callable = None
|
||||
) -> tuple[str, str]:
|
||||
if use_gsa:
|
||||
g = gsa.authenticate(username, password, gsa.Anisette())
|
||||
pet = g["t"]["com.apple.gs.idms.pet"]["token"]
|
||||
|
@ -176,8 +179,8 @@ def _get_auth_token(username: str, password: str, use_gsa: bool = False, factor_
|
|||
else:
|
||||
pet = password + factor_gen()
|
||||
r = _auth_token_request(username, pet)
|
||||
#print(r)
|
||||
if 'description' in r:
|
||||
# print(r)
|
||||
if "description" in r:
|
||||
raise Exception(f"Error: {r['description']}")
|
||||
service_data = r["delegates"]["com.apple.private.ids"]["service-data"]
|
||||
realm_user_id = service_data["realm-user-id"]
|
||||
|
@ -185,6 +188,7 @@ def _get_auth_token(username: str, password: str, use_gsa: bool = False, factor_
|
|||
# print(f"Auth token for {realm_user_id}: {auth_token}")
|
||||
return realm_user_id, auth_token
|
||||
|
||||
|
||||
from cryptography import x509
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import hashes, serialization
|
||||
|
@ -198,9 +202,7 @@ def _generate_csr(private_key: rsa.RSAPrivateKey) -> str:
|
|||
.subject_name(
|
||||
x509.Name(
|
||||
[
|
||||
x509.NameAttribute(
|
||||
NameOID.COMMON_NAME, random.randbytes(20).hex()
|
||||
),
|
||||
x509.NameAttribute(NameOID.COMMON_NAME, random.randbytes(20).hex()),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
@ -225,7 +227,7 @@ def _get_auth_cert(user_id, token) -> str:
|
|||
"realm-user-id": user_id,
|
||||
}
|
||||
|
||||
#print(body["csr"])
|
||||
# print(body["csr"])
|
||||
|
||||
body = plistlib.dumps(body)
|
||||
|
||||
|
@ -243,13 +245,18 @@ def _get_auth_cert(user_id, token) -> str:
|
|||
|
||||
def test():
|
||||
import getpass
|
||||
|
||||
# Prompt for username
|
||||
username = input("Enter iCloud username: ")
|
||||
# Prompt for password
|
||||
password = getpass.getpass("Enter iCloud password: ")
|
||||
|
||||
def factor_gen():
|
||||
return input("Enter iCloud 2FA code: ")
|
||||
user_id, token = _get_auth_token(username, password, use_gsa=False, factor_gen=factor_gen)
|
||||
|
||||
user_id, token = _get_auth_token(
|
||||
username, password, use_gsa=False, factor_gen=factor_gen
|
||||
)
|
||||
cert = _get_auth_cert(user_id, token)
|
||||
print(cert)
|
||||
|
||||
|
|
Loading…
Reference in a new issue