Skip to content

Instantly share code, notes, and snippets.

@Seasons7
Created July 11, 2015 06:44
Show Gist options
  • Save Seasons7/205a9ab5f6e578580a28 to your computer and use it in GitHub Desktop.
Save Seasons7/205a9ab5f6e578580a28 to your computer and use it in GitHub Desktop.
Keychain codesign information
import commands
import re
def get_codesign_entries_from_keychain():
cm = 'security find-identity -v -p codesigning'
result = commands.getoutput(cm)
entries = []
if result:
items = result.split('\n')
for item in items:
m = re.search('([0-9A-Z]{40,})\s+\"(.+)\(([0-9A-Z]{10,})\)\"', item)
if m:
teamID = str(m.group(3))
certificate = str(m.group(2))
entry = (teamID, certificate + "(" + teamID + ")")
# (teamID, certificate)
entries.append(entry)
return entries
def select_codesign_entry():
entries = get_codesign_entries_from_keychain()
if entries:
number = 1
for teamID, cert in entries:
print(str(number) + " : " + cert)
number += 1
while True:
print('Select number(' + str(number) + ' = Exit) >>')
value = input()
if 0 < value and value < number:
value -= 1
return entries[value]
if value == number:
break
if __name__ == '__main__':
ret = select_codesign_entry()
print(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment