参考文章:https://objccn.io/issue-17-2/
- 查看本地证书
security find-identity -v -p codesigning -
查看IPA签名信息(注意是.app 而不是.ipa ,查看的是解压后的包。通过预览空格也可以查看基本信息)
codesign -vv -d ipaName.app
- 你需要查看的第一件事是以 Authority 开头的那三行。这三行告诉你到底是哪一个证书为这个 app 设置了签名。在这里当然是我的证书,iPhone Developer: chunhua zhou (PM246VG2Z9)。我的这个证书则是被证书 Apple Worldwide Developer Relations Certification Authority 设置了签名的,依此类推这个证书则是被证书 Apple Root CA 设置了签名。
- 查看.mobileprovision 的内容
security cms -D -i embedded.mobileprovision
签名流程
- 解压IPA
unzip ipaName.ipa - 删除 app 原有签名
rm -rf Payload/ipaName.app/_CodeSignature/ - 替换证书配置文件(mobileprovision文件从开发者网站下载Provisioning Profiles并改名为embedded.mobileprovision)
$ cp ~/Desktop/embedded.mobileprovision Payload/ipaName.app/embedded.mobileprovision
- 如果存在Frameworks子目录,则对.app文件夹下的所有Frameworks进行签名,在Frameworks文件夹下的.dylib或.framework
codesigning - 重签名
$ security cms -D -i "xxx.mobileprovision"
//使用该命令进行查看xxx.mobileprovision文件的相关内容,可以找到以Entitlements为key的字典值。
//新建一个.plist文件,将上述值复制到plist文件中。如下示例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>keychain-access-groups</key>
<array>
<string>AD9JDJKJKA.*</string>
</array>
<key>get-task-allow</key>
<false/>
<key>application-identifier</key>
<string>AD9JDJKJKA.com.resign.test</string>
<key>com.apple.developer.team-identifier</key>
<string>AD9JDJKJKA</string>
<key>aps-environment</key>
<string>production</string>
<key>beta-reports-active</key>
<true/>
</dict>
</plist>
codesign -f -s "iPhone Distribution: ******* Co., Ltd." --entitlements entitlements.plist Payload/ipaName.app
- -f :codesign 会用你选择的签名替换掉已经存在的那一个,如果要签名没有签名的APP可以不用 -f 。
- 还需要进入 Payload/ipaName.app 中修改 info.plist 。
- 重新打包
zip -qr ipaName-resigned.ipa Payload/
# !/bin/bash
SOURCEIPA="/Users/maccarduo/Desktop/wechat.ipa"
MOBILEPROV="/Users/maccarduo/Desktop/embedded.mobileprovision"
#DYLIB="/Users/maccarduo/Desktop/FishChat.dylib"
cd ${SOURCEIPA%/*}
security find-identity -v -p codesigning > cers.txt
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ "$line" =~ "iPhone Developer" ]]; then
DEVELOPER=${line:47:${#line}-48}
fi
done < cers.txt
unzip -qo "$SOURCEIPA" -d extracted
APPLICATION=$(ls extracted/Payload/)
echo "Copying dylib and mobileprovision"
cp "$DYLIB" "extracted/Payload/$APPLICATION/${DYLIB##*/}"
cp "$MOBILEPROV" "extracted/Payload/$APPLICATION/embedded.mobileprovision"
echo "Insert dylib into Mach-O file"
yololib "extracted/Payload/$APPLICATION/${APPLICATION%.*}" "${DYLIB##*/}"
echo "Resigning with certificate: $DEVELOPER"
find -d extracted \( -name "*.app" -o -name "*.appex" -o -name "*.framework" -o -name "*.dylib" \) > directories.txt
security cms -D -i "extracted/Payload/$APPLICATION/embedded.mobileprovision" > t_entitlements_full.plist
/usr/libexec/PlistBuddy -x -c 'Print:Entitlements' t_entitlements_full.plist > t_entitlements.plist
while IFS='' read -r line || [[ -n "$line" ]]; do
/usr/bin/codesign --continue -f -s "$DEVELOPER" --entitlements "t_entitlements.plist" "$line"
done < directories.txt
echo "Creating the Signed IPA"
cd extracted
zip -qry ../extracted.ipa *
cd ..
rm -rf "extracted"
rm directories.txt
rm cers.txt
rm t_entitlements.plist
rm t_entitlements_full.plist
echo "Installing APP to your iOS Device"
mobiledevice install_app extracted.ipa
rm extracted.ipa
通过将命令合并写到一个autoswimfi.sh文件中(如果无法执行,打开终端,输入:chmod 777 autoswimfi.sh 给该文件赋予权限),可以一步到位执行命令。