|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
5 | 5 | import base64
|
| 6 | +import locale |
6 | 7 | import logging
|
7 | 8 | from contextlib import ExitStack
|
8 | 9 | from ctypes import c_ulonglong
|
9 |
| -from typing import TYPE_CHECKING, Any, BinaryIO |
| 10 | +from datetime import datetime |
| 11 | +from typing import TYPE_CHECKING, BinaryIO, TypedDict |
10 | 12 |
|
11 | 13 | from typing_extensions import Self
|
12 | 14 |
|
|
24 | 26 | DEFAULT_LIBS_URL = "https://anisette.dl.mikealmel.ooo/libs?arch=arm64-v8a"
|
25 | 27 |
|
26 | 28 |
|
| 29 | +AnisetteHeaders = TypedDict( |
| 30 | + "AnisetteHeaders", |
| 31 | + { |
| 32 | + "X-Apple-I-Client-Time": str, |
| 33 | + "X-Apple-I-MD": str, |
| 34 | + "X-Apple-I-MD-LU": str, |
| 35 | + "X-Apple-I-MD-M": str, |
| 36 | + "X-Apple-I-MD-RINFO": str, |
| 37 | + "X-Apple-I-SRL-NO": str, |
| 38 | + "X-Apple-I-TimeZone": str, |
| 39 | + "X-Apple-Locale": str, |
| 40 | + "X-MMe-Client-Info": str, |
| 41 | + "X-Mme-Device-Id": str, |
| 42 | + }, |
| 43 | +) |
| 44 | + |
| 45 | + |
27 | 46 | class Anisette:
|
28 | 47 | """
|
29 | 48 | The main Anisette provider class.
|
@@ -158,17 +177,25 @@ def provision(self) -> None:
|
158 | 177 | logging.info("Provisioning...")
|
159 | 178 | self._ani_provider.provisioning_session.provision(self._ds_id)
|
160 | 179 |
|
161 |
| - def get_data(self) -> dict[str, Any]: # FIXME: make TypedDict |
| 180 | + def get_data(self) -> AnisetteHeaders: |
162 | 181 | """
|
163 | 182 | Obtain Anisette headers for this session.
|
164 | 183 |
|
165 | 184 | :return: Anisette headers that may be used for authentication purposes.
|
166 | 185 | """
|
167 | 186 | self.provision()
|
168 | 187 | otp = self._ani_provider.adi.request_otp(self._ds_id)
|
| 188 | + device = self._ani_provider.device |
169 | 189 |
|
170 |
| - # FIXME: return other fields as well |
171 | 190 | return {
|
| 191 | + "X-Apple-I-Client-Time": datetime.now().astimezone().replace(microsecond=0).isoformat() + "Z", |
172 | 192 | "X-Apple-I-MD": base64.b64encode(bytes(otp.otp)).decode(),
|
| 193 | + "X-Apple-I-MD-LU": base64.b64encode(str(device.local_user_uuid).encode()).decode(), |
173 | 194 | "X-Apple-I-MD-M": base64.b64encode(bytes(otp.machine_id)).decode(),
|
| 195 | + "X-Apple-I-MD-RINFO": "17106176", |
| 196 | + "X-Apple-I-SRL-NO": "0", |
| 197 | + "X-Apple-I-TimeZone": str(datetime.now().astimezone().tzinfo), |
| 198 | + "X-Apple-Locale": locale.getdefaultlocale()[0] or "en_US", |
| 199 | + "X-MMe-Client-Info": device.server_friendly_description, |
| 200 | + "X-Mme-Device-Id": device.unique_device_identifier, |
174 | 201 | }
|
0 commit comments