```import subprocess, objc from Foundation import ...
# macos
f
Copy code
import subprocess, objc
from Foundation import NSPropertyListSerialization, NSPropertyListMutableContainers, NSBundle
Security_bundle = NSBundle.bundleWithIdentifier_('com.apple.security')

S_functions = [
               ('SecCertificateCreateWithData', '@@@'),
               ('SecCertificateCopyValues', '@@^@o^@'),
              ]

objc.loadBundleFunctions(Security_bundle, globals(), S_functions)

profile_info = subprocess.check_output(['/usr/libexec/mdmclient', 'QueryInstalledProfiles'])
profile_next = buffer(profile_info.split('will return: ',1)[-1])
profile_list, _, error = NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(profile_next, NSPropertyListMutableContainers, None, None)

signed_profiles = [x for x in profile_list if x['SignerCertificates']]
first_profile   = signed_profiles[0]
first_cert = first_profile['SignerCertificates'][0]

# converting cert data to a cert reference
c = SecCertificateCreateWithData(None, first_cert)
cert_details, errors = SecCertificateCopyValues(c, None, None)