-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathHelperTool-CodeSign.py
More file actions
executable file
·129 lines (91 loc) · 3.77 KB
/
Copy pathHelperTool-CodeSign.py
File metadata and controls
executable file
·129 lines (91 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/python
'''Place this file in a folder named 'scripts' at
the root of your project.
Add this next line (including quotes) as a "Run Script"
right after Target Dependencies
"${PROJECT_DIR}/scripts/helper-tool-codesing-config.py"
'''
import os
import subprocess
import plistlib
'''If the helper tool's root folder is in a folder named something other
than helper At the root of your project make the adjustments here'''
HELPER_INFO = 'helper/helper-Info.plist'
HELPER_LAUNCHD = 'helper/helper-Launchd.plist'
'''the name for the helper tool will be default to this format com.your.app.helper
which is the main apps bundleID with a .helper extension. if the executable you're
insatlling is something other than that specify it here'''
HELPER_NAME_OVERRIDE = ''
TMP_FILENAME = 'code_sign_tmp_file'
def get_code_sing_ident(build_dir):
'''Get code signing identity'''
identity = os.getenv('CODE_SIGN_IDENTITY')
check_var(identity)
_file = os.path.join(build_dir, TMP_FILENAME)
open(_file, 'w').close()
result = subprocess.check_output(['codesign', '--force', '--sign', identity, _file])
result = subprocess.check_output(['codesign', '-d', '-r', '-', _file])
cid = result.split("=> ")[1]
cid = cid.rstrip(os.linesep)
os.remove(_file)
return cid
def edit_app_info_plist(cert_id, app_name):
'''Edit app info.plist with correct cert identity'''
app_info_plist = os.getenv('PRODUCT_SETTINGS_PATH')
check_var(app_info_plist)
try:
plist = plistlib.readPlist(app_info_plist)
bundle_id = plist['CFBundleIdentifier'].split("$")[0]
if not HELPER_NAME_OVERRIDE:
helper_id = ''.join([bundle_id, app_name, '.helper'])
else:
helper_id = HELPER_NAME_OVERRIDE
csstring = cert_id.replace(TMP_FILENAME, helper_id)
plist['SMPrivilegedExecutables'] = {helper_id:csstring}
except Exception:
print "There is No Info.plist for them main app, somethings really wrong"
exit(1)
plistlib.writePlist(plist, app_info_plist)
return bundle_id, helper_id
def edit_helper_info_plist(cert_id, project_path, bundle_id, app_name):
'''Edit the helper.plist file to match the cert identity'''
helper_info_plist = os.path.join(project_path, HELPER_INFO)
check_var(helper_info_plist)
app_id = ''.join([bundle_id, app_name])
csstring = cert_id.replace(TMP_FILENAME, app_id)
try:
plist = plistlib.readPlist(helper_info_plist)
plist['SMAuthorizedClients'] = [csstring]
except Exception:
print "There is No Info.plist for helper tool, somethings really wrong"
exit(1)
plistlib.writePlist(plist, helper_info_plist)
def edit_helper_launchd(project_path, helper_id):
'''Edit helper launchd'''
helper_launchd_plist = os.path.join(project_path, HELPER_LAUNCHD)
check_var(helper_launchd_plist)
try:
plist = plistlib.readPlist(helper_launchd_plist)
plist['Label'] = helper_id
plist['MachServices'] = {helper_id:True}
except Exception:
plist = {'Label':helper_id, 'MachServices':{helper_id:True}}
plistlib.writePlist(plist, helper_launchd_plist)
def check_var(var):
'''Check for empty string or None'''
if var == "" or var == None:
exit(1)
def main():
'''main'''
# Configure info from environment
build_dir = os.getenv('BUILT_PRODUCTS_DIR')
project_path = os.getenv('PROJECT_DIR')
app_name = os.getenv('PRODUCT_NAME')
# Get the existing cert values
cs_ident = get_code_sing_ident(build_dir)
# write out to the helper tool
bundle_id, helper_id = edit_app_info_plist(cs_ident, app_name)
edit_helper_info_plist(cs_ident, project_path, bundle_id, app_name)
edit_helper_launchd(project_path, helper_id)
if __name__ == "__main__":
main()