一、写在前面
苹果官方公告【查看】:
不进行公证的应用,通过网络传输下载,或者隔空传递传输的方式安装后,打开是这样的:
公证后是这样的:
网上关于nwjs签名公证的文章少之又少。。。
注:本文中使用的nwjs版本为27.5,体积相对小点。
二、签名准备
- Developer ID开发者证书;官方文档有点老了,在选择证书类型的时候应该选择
Developer ID Application
,创建完成,下载安装,证书没有小三角问题看这里。 - 查看证书的
identity
即唯一标识;
终端运行:security find-identity -p codesigning
运行结果:
Policy: Code Signing
Matching identities
1)" AKLJDKSAJFKKJK34J432J3K523312L3DASNLQ321L9 "Developer ID Application: xxxxx (Rxxxxxxx)"
1 identities found
AKLJDKSAJFKKJK34J432J3K523312L3DASNLQ321L9
即为签名所需要的identity
- 安装Xcode;为了上传文件
xcrun altool
命令所用 - 为App Store Connect API创建API密钥【苹果官方文档】
需要参数:apiKey(密钥ID)
、apiIssuer
、.p8文件
只能下载一次,请妥善保管 - 桌面右上角
前往>个人
新建private_keys
将.p8文件
放置此文件夹。
三、开始签名
- 终端命令进入
app应用
所在文件夹,如:你的nwjs.app放在pack
文件夹cd /Users/xxxxx/Desktop/pack
- 终端输入
sudo touch entitlements-parent.plist
回车可能要输入密码,此时会创建一个entitlements-parent.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>com.apple.security.automation.apple-events</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-executable-page-protection</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.app-sandbox</key>
<false/>
</dict>
</plist>
- 终端输入
sudo touch sign.command
回车可能给要输入密码,此时会创建一个sign.command
文件,打开文件,粘贴以下文本并保存,此文件即为所有签名命令。
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
app="$dir/yourappname.app"
#您的证书唯一标识
identity="Adasfadadsfasdfadsf43243242342349"
entitlement="$dir/entitlements-parent.plist"
echo "### signing app"
ITEMS=""
FRAMEWORKS_DIR="$app/Contents"
if [ -d "$FRAMEWORKS_DIR" ] ; then
FRAMEWORKS=$(find "${FRAMEWORKS_DIR}" -depth -type d -name "*.framework" -or -type d -name "*.app" -or -type d -name "*.xpc" -or -name "*.dylib" -or -name "*.bundle" -or -path "*/Helpers/*" | sed -e "s/\(.*\/\(.*\)\.framework\)$/\1\/Versions\/A\/\2/")
#
RESULT=$?
if [[ $RESULT != 0 ]] ; then
exit 1
fi
ITEMS="${FRAMEWORKS}"
fi
echo "Found:"
echo "${ITEMS}"
# Change the Internal Field Separator (IFS) so that spaces in paths will not cause problems below.
SAVED_IFS=$IFS
IFS=$(echo -en "\n\b")
#如果报/Us错误请用下边一行
#IFS=$'\n'
# Loop through all items.
for ITEM in $ITEMS;
do
echo "Signing '${ITEM}'"
codesign --verbose --force --deep --strict --options runtime --timestamp --sign "$identity" --entitlements "$entitlement" "${ITEM}"
RESULT=$?
if [[ $RESULT != 0 ]] ; then
echo "Failed to sign '${ITEM}'."
IFS=$SAVED_IFS
exit 1
fi
done
# Restore $IFS.
IFS=$SAVED_IFS
codesign --verbose --force --deep --strict --options runtime --timestamp --sign "$identity" --entitlements "$entitlement" "$app"
echo "### verifying signature"
codesign -vvv -d "$app"
- 注:参考
https://github.com/nwjs/nw.js/issues/7117
- 终端输入:
chmod u+x sign.command
获取权限,双击打开sign.command
开始签名,出现一下结果即为签名成功!
Authority=Developer ID Application: xxxxxxxxxxxx (RKxxxxxxxxx)
Authority=Developer ID Certification Authority
Authority=Apple Root CA
签名成功后,需打包成dmg,(打包步骤请参照上一篇[nwjs macOS打包成dmg])上传给苹果公证。
四、公证
- 上传dmg文件。
参考:https://wiki.freepascal.org/Notarization_for_macOS_10.14.5%2B
参考:https://successfulsoftware.net/2018/11/16/how-to-notarize-your-software-on-macos/
xcrun altool --notarize-app -f xxxx.dmg --primary-bundle-id com.companyname.appname -u 苹果开发者账号 --apiKey 您的apiKey(准备工作中有提到) --apiIssuer 您的apiIssuer(准备工作中有提到) --verbose
- 终端输入以下命令回车,开始上传公证,上传成功返回
RequestUUID
需记录。
No errors uploading /Users/xxxx/Desktop/xxxxx.dmg'.
RequestUUID = 2edcfe9a-1111-2222-2222-99864444709ae
xcrun altool --notarization-info 2edcfe9a-1111-2222-2222-99864444709ae(上一步的RequestUUID) -u 苹果开发者账号 --apiKey 您的apiKey(准备工作中有提到) --apiIssuer 您的apiIssuer(准备工作中有提到) --verbose
- 终端输入以上命令,获取公证结果,当结果中包含
Status: in progress
,公证成功的结果为
RequestUUID: 00000-11111-22222-33333-44444444
Status: success
Status Code: 0
Status Message: Package Approved
- 如果公证失败,请根据
LogFileUrl
排查相关错误。 - 至此,公证基本完成,可以通过将dmg发给其他电脑安装测试。还可以根据参考二,对公证结果进行验证。
xcrun stapler staple -v xxx.dmg
输出:"The staple and validate action worked!"
- 解压安装后
spctl -a -v /Applications/xxx.app
输出:
/Applications/xxx.app: accepted
source=Notarized Developer ID
好运~~~~
参考链接:
1.https://github.com/nwjs/nw.js/wiki/MAS:-Requesting-certificates
2.https://wiki.freepascal.org/Notarization_for_macOS_10.14.5%2B
3.https://successfulsoftware.net/2018/11/16/how-to-notarize-your-software-on-macos/