whoops forgot to format

This commit is contained in:
JJTech0130 2023-04-23 13:42:43 -04:00
parent 97fbdae4cb
commit 84d81be41f
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6

19
ids.py
View file

@ -158,12 +158,15 @@ def _auth_token_request(username: str, password: str) -> any:
r = plistlib.loads(r.content) r = plistlib.loads(r.content)
return r return r
# Gets an IDS auth token for the given username and password # 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 True, GSA authentication will be used, which requires anisette
# If use_gsa is False, it will use a old style 2FA code # 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 # 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) # 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: if use_gsa:
g = gsa.authenticate(username, password, gsa.Anisette()) g = gsa.authenticate(username, password, gsa.Anisette())
pet = g["t"]["com.apple.gs.idms.pet"]["token"] pet = g["t"]["com.apple.gs.idms.pet"]["token"]
@ -177,7 +180,7 @@ def _get_auth_token(username: str, password: str, use_gsa: bool = False, factor_
pet = password + factor_gen() pet = password + factor_gen()
r = _auth_token_request(username, pet) r = _auth_token_request(username, pet)
# print(r) # print(r)
if 'description' in r: if "description" in r:
raise Exception(f"Error: {r['description']}") raise Exception(f"Error: {r['description']}")
service_data = r["delegates"]["com.apple.private.ids"]["service-data"] service_data = r["delegates"]["com.apple.private.ids"]["service-data"]
realm_user_id = service_data["realm-user-id"] 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}") # print(f"Auth token for {realm_user_id}: {auth_token}")
return realm_user_id, auth_token return realm_user_id, auth_token
from cryptography import x509 from cryptography import x509
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives import hashes, serialization
@ -198,9 +202,7 @@ def _generate_csr(private_key: rsa.RSAPrivateKey) -> str:
.subject_name( .subject_name(
x509.Name( x509.Name(
[ [
x509.NameAttribute( x509.NameAttribute(NameOID.COMMON_NAME, random.randbytes(20).hex()),
NameOID.COMMON_NAME, random.randbytes(20).hex()
),
] ]
) )
) )
@ -243,13 +245,18 @@ def _get_auth_cert(user_id, token) -> str:
def test(): def test():
import getpass import getpass
# Prompt for username # Prompt for username
username = input("Enter iCloud username: ") username = input("Enter iCloud username: ")
# Prompt for password # Prompt for password
password = getpass.getpass("Enter iCloud password: ") password = getpass.getpass("Enter iCloud password: ")
def factor_gen(): def factor_gen():
return input("Enter iCloud 2FA code: ") 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) cert = _get_auth_cert(user_id, token)
print(cert) print(cert)