nwjs macos 签名 公证

一、写在前面

苹果官方公告【查看】:
在这里插入图片描述
不进行公证的应用,通过网络传输下载,或者隔空传递传输的方式安装后,打开是这样的:
在这里插入图片描述
公证后是这样的:
在这里插入图片描述
网上关于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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宁不凡啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值