Skip to content

Instantly share code, notes, and snippets.

@clydebarrow
Last active July 12, 2021 06:33
Show Gist options
  • Save clydebarrow/718be773de24960840b43967d31a6bf0 to your computer and use it in GitHub Desktop.
Save clydebarrow/718be773de24960840b43967d31a6bf0 to your computer and use it in GitHub Desktop.
List Apple provisioning profiles with certificate information
import os
import plistlib
import hashlib
from cryptography import x509
profileLib = os.getenv("HOME") + "/Library/MobileDevice/Provisioning Profiles"
for filename in os.listdir(profileLib):
stream = os.popen('security cms -D -i "' + profileLib + '"/' + filename)
input = stream.read()
stream.close()
plist = plistlib.loads(bytes(input, "utf-8"))
print(f'Profile: {filename}: {plist["Name"]}')
print(f' Expires {plist["ExpirationDate"]}, AppId={plist["Entitlements"]["application-identifier"]}')
print(" Certificates:")
for data in plist['DeveloperCertificates']:
sha1 = hashlib.sha1()
sha1.update(data)
hash = sha1.hexdigest().upper()
cert = x509.load_der_x509_certificate(data)
print(f' {hash}: {cert.subject}, expires {cert.not_valid_after}')
if 'ProvisionedDevices' in plist:
print(" Devices:")
for device in plist['ProvisionedDevices']:
print(f' {device}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment