-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbags.py
105 lines (72 loc) · 2.38 KB
/
bags.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import plistlib
import requests
import logging
logger = logging.getLogger("bags")
OLD_APNS_BAG = None
def apns_init_bag_old():
global OLD_APNS_BAG
if OLD_APNS_BAG is not None:
return OLD_APNS_BAG
r = requests.get("https://init.push.apple.com/bag", verify=False)
if r.status_code != 200:
raise Exception("Failed to get APNs init bag")
# Parse the config as a plist
bag = plistlib.loads(r.content)
logger.debug("Received APNs old-style init bag")
OLD_APNS_BAG = bag
return bag
# This is the same as the above, but the response has a signature which we unwrap
APNS_BAG = None
def apns_init_bag():
global APNS_BAG
if APNS_BAG is not None:
return APNS_BAG
r = requests.get("http://init-p01st.push.apple.com/bag", verify=False)
if r.status_code != 200:
raise Exception("Failed to get APNs init bag 2")
content = plistlib.loads(r.content)
bag = plistlib.loads(content["bag"])
logger.debug("Received APNs new init bag")
APNS_BAG = bag
return bag
IDS_BAG = None
def ids_bag():
global IDS_BAG
if IDS_BAG is not None:
return IDS_BAG
r = requests.get(
"https://init.ess.apple.com/WebObjects/VCInit.woa/wa/getBag?ix=3", verify=False
)
if r.status_code != 200:
raise Exception("Failed to get IDS bag")
# Parse the config as a plist
content = plistlib.loads(r.content)
# Load the inner bag
bag = plistlib.loads(content["bag"])
logger.debug("Recieved IDS bag")
IDS_BAG = bag
return bag
GRANDSLAM_BAG = None
def grandslam_bag():
global GRANDSLAM_BAG
if GRANDSLAM_BAG is not None:
return GRANDSLAM_BAG
import icloud.gsa as gsa
r = requests.get(
"https://gsa.apple.com/grandslam/GsService2/lookup", verify=False,
headers = {
# We have to provide client info so that the server knows which version of the bag to give us
"X-Mme-Client-Info": gsa.build_client(),
"User-Agent": gsa.USER_AGENT,
}
)
if r.status_code != 200:
raise Exception("Failed to get Grandslam bag: " + r.status_code)
GRANDSLAM_BAG = plistlib.loads(r.content)
return GRANDSLAM_BAG
if __name__ == "__main__":
# config = get_config()
# print(config)
# print(apns_init_bag_2())
# print(apns_init_bag_2() == apns_init_bag())
print(grandslam_bag())