本想直接用fastlane的resign功能,要简单些,基本不需要写代码实现,但是考虑到安装新环境fastlane安装等原因,还是出一个不依赖fastlane的工具
重签名流程,跟安卓的类似
1.解压ipa
2.导出entitlements_temp.plist
3.重签名
4.压缩ipa
1.解压ipa
def unzip_ipa(self,ipa_path):
if os.path.exists(ipa_path):
if '.ipa' in ipa_path:
resign_utils.remove_dir(self.temp_file_dir)
self.zip_file_list = resign_utils.unzip_file(ipa_path, self.temp_file_dir)
payload_path = os.path.join(self.temp_file_dir, 'Payload')
app_PackageName = resign_utils.execute_cmd('ls %s' % (payload_path))
app_path = os.path.join(payload_path, app_PackageName)
self.app_temp_path = resign_utils.handleWhiteSpace(app_path)
print('app_temp_path ==>%s' % self.app_temp_path)
else:
print('文件格式非法')
else:
print('文件不存在')
2.导出entitlements_temp.plist,并且修改替换embedded.mobileprovision
# 根据pp文件导出Entitlements信息
def export_sign_info(self,pp_path):
temp_plist = os.path.join(self.temp_file_dir, 'entitlements_temp.plist')
cmd = 'security cms -D -i "%s" > %s' % (pp_path, temp_plist)
result = resign_utils.execute_cmd(cmd)
cmd = '/usr/libexec/PlistBuddy -x -c "Print:Entitlements" %s > %s' % (temp_plist, self.entitle_plist)
result = resign_utils.execute_cmd(cmd)
resign_utils.copy(pp_path, self.app_temp_path)
file_dir, file_name = os.path.split(pp_path)
resign_utils.rename(os.path.join(self.app_temp_path, file_name), 'embedded.mobileprovision')
os.remove(temp_plist)
3.重签名
def code_sign(self,cert_name, file_path):
cmd = 'codesign -f -s "%s" --entitlements %s "%s"' % (cert_name, self.entitle_plist, file_path)
resign_utils.execute_cmd(cmd)
4.压缩ipa
def zip_ipa(self):
resign_utils.zip_file(os.path.join(self.temp_file_dir, 'Payload'), self.output_ipa_path)
resign_utils.remove_dir(self.temp_file_dir)
# 解压文件
def unzip_file(source_file, output_path):
zip_obj = zipfile.ZipFile(source_file, 'r')
zip_file_list = zip_obj.namelist()
zip_file_list.reverse()
zip_obj.extractall(output_path)
zip_obj.close()
return zip_file_list
# 压缩文件
def zip_file(source_path, output_path):
zip_file = zipfile.ZipFile(output_path, 'w')
pre_len = len(os.path.dirname(source_path))
for parent, dir_names, file_names in os.walk(source_path):
for file_name in file_names:
pathFile = os.path.join(parent, file_name)
arc_name = pathFile[pre_len:].strip(os.path.sep)
zip_file.write(pathFile, arc_name)
zip_file.close()