2023-04-12 12:13:47 -05:00
|
|
|
import plistlib
|
|
|
|
|
|
|
|
import requests
|
2023-07-24 08:18:21 -05:00
|
|
|
import logging
|
|
|
|
logger = logging.getLogger("bags")
|
2023-04-12 12:13:47 -05:00
|
|
|
|
2023-07-27 16:34:38 -05:00
|
|
|
OLD_APNS_BAG = None
|
2023-05-09 19:01:22 -05:00
|
|
|
def apns_init_bag_old():
|
2023-07-27 16:34:38 -05:00
|
|
|
global OLD_APNS_BAG
|
|
|
|
|
|
|
|
if OLD_APNS_BAG is not None:
|
|
|
|
return OLD_APNS_BAG
|
2023-08-22 12:13:31 -05:00
|
|
|
|
2023-04-12 12:13:47 -05:00
|
|
|
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)
|
|
|
|
|
2023-07-24 08:18:21 -05:00
|
|
|
logger.debug("Received APNs old-style init bag")
|
|
|
|
|
2023-07-27 16:34:38 -05:00
|
|
|
OLD_APNS_BAG = bag
|
|
|
|
|
2023-04-12 12:13:47 -05:00
|
|
|
return bag
|
|
|
|
|
|
|
|
|
|
|
|
# This is the same as the above, but the response has a signature which we unwrap
|
2023-07-27 16:34:38 -05:00
|
|
|
APNS_BAG = None
|
2023-05-09 19:01:22 -05:00
|
|
|
def apns_init_bag():
|
2023-07-27 16:34:38 -05:00
|
|
|
global APNS_BAG
|
|
|
|
|
|
|
|
if APNS_BAG is not None:
|
|
|
|
return APNS_BAG
|
2023-08-22 12:13:31 -05:00
|
|
|
|
2023-04-12 12:13:47 -05:00
|
|
|
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"])
|
|
|
|
|
2023-07-24 08:18:21 -05:00
|
|
|
logger.debug("Received APNs new init bag")
|
|
|
|
|
2023-07-27 16:34:38 -05:00
|
|
|
APNS_BAG = bag
|
|
|
|
|
2023-04-12 12:13:47 -05:00
|
|
|
return bag
|
|
|
|
|
|
|
|
|
2023-07-27 16:34:38 -05:00
|
|
|
IDS_BAG = None
|
2023-04-12 12:13:47 -05:00
|
|
|
def ids_bag():
|
2023-07-27 16:34:38 -05:00
|
|
|
global IDS_BAG
|
|
|
|
|
|
|
|
if IDS_BAG is not None:
|
|
|
|
return IDS_BAG
|
2023-08-22 12:13:31 -05:00
|
|
|
|
2023-04-12 12:13:47 -05:00
|
|
|
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"])
|
|
|
|
|
2023-07-24 08:18:21 -05:00
|
|
|
logger.debug("Recieved IDS bag")
|
|
|
|
|
2023-07-27 16:34:38 -05:00
|
|
|
IDS_BAG = bag
|
|
|
|
|
2023-04-12 12:13:47 -05:00
|
|
|
return bag
|
|
|
|
|
2023-10-21 14:52:17 -05:00
|
|
|
GRANDSLAM_BAG = None
|
|
|
|
def grandslam_bag():
|
|
|
|
global GRANDSLAM_BAG
|
|
|
|
|
|
|
|
if GRANDSLAM_BAG is not None:
|
|
|
|
return GRANDSLAM_BAG
|
|
|
|
|
|
|
|
import 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
|
|
|
|
|
|
|
|
|
2023-04-12 12:13:47 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# config = get_config()
|
|
|
|
# print(config)
|
|
|
|
# print(apns_init_bag_2())
|
2023-05-02 19:53:18 -05:00
|
|
|
# print(apns_init_bag_2() == apns_init_bag())
|
2023-10-21 14:52:17 -05:00
|
|
|
print(grandslam_bag())
|