Last active
November 17, 2022 02:23
-
-
Save Brandon-T/58771cb9c96f2aa0a521a1a0561eaeb4 to your computer and use it in GitHub Desktop.
Parses Provisioning Profiles and converts them to JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import glob | |
| import os | |
| from datetime import datetime | |
| from subprocess import Popen, PIPE | |
| def plist_to_json(filename): | |
| command = 'security cms -D -i "' + filename + '"' | |
| cleanup_command = 'sed "s/data/string/g" | sed "s/date/string/g"' | |
| content = Popen(command + " | " + cleanup_command, shell=True, stdout=PIPE).stdout.read() | |
| args = ["plutil", "-convert", "json", "-o", "-", "--", "-"] | |
| p = Popen(args, stdin=PIPE, stdout=PIPE) | |
| out, err = p.communicate(content) | |
| return json.loads(out.decode("utf-8")) | |
| def parse_all_provisioning_profiles_matching(directory, teamID, profileName, bundleID): | |
| for file in glob.glob(directory): | |
| try: | |
| result = plist_to_json(file) | |
| if result["TeamIdentifier"][0] == teamID and result["Name"] == profileName and result["Entitlements"]["application-identifier"] == teamID + "." + bundleID: | |
| expiration_date = datetime.strptime(result["ExpirationDate"], '%Y-%m-%dT%H:%M:%SZ') | |
| if expiration_date > datetime.now(): | |
| return file | |
| except: | |
| print("Sorry.. Something Went Wrong..") | |
| return None | |
| if __name__ == "__main__": | |
| profile_path = parse_all_provisioning_profiles_matching( | |
| directory=os.path.expanduser("~/Library/MobileDevice/Provisioning Profiles/*.mobileprovision"), | |
| teamID="", | |
| profileName="", | |
| bundleID="") | |
| print(profile_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import glob | |
| import os | |
| from subprocess import Popen, PIPE | |
| def plist_to_json(filename): | |
| command = 'security cms -D -i "' + filename + '"' | |
| cleanup_command = 'sed "s/data/string/g" | sed "s/date/string/g"' | |
| content = Popen(command + " | " + cleanup_command, shell=True, stdout=PIPE).stdout.read() | |
| args = ["plutil", "-convert", "json", "-o", "-", "--", "-"] | |
| p = Popen(args, stdin=PIPE, stdout=PIPE) | |
| out, err = p.communicate(content) | |
| return json.loads(out.decode("utf-8")) | |
| if __name__ == "__main__": | |
| for file in glob.glob(os.path.expanduser("~/Library/MobileDevice/Provisioning Profiles/*.mobileprovision")): | |
| try: | |
| result = plist_to_json(file) | |
| print(result) | |
| # file = open("profile.json", "w") | |
| # file.write(json.dumps(result, indent=4, sort_keys=True)) | |
| # file.close() | |
| except: | |
| print(err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment