在 Mac 上使用 electron-builder 协同设计 Windows 构建,无法正常工作

Codesigning a Windows build with electron-builder, on a Mac, not working

我在 Mac 上使用 Apple 生成并存储在 Mac 钥匙串中的 .p12 证书对 Windows .exe 构建进行代码签名时遇到问题.

我的 electron-builder 版本是:20.28.1 我正在尝试 运行 的目标构建是 Windows ia32 构建。

Mac 应用程序的代码设计工作正常。但是当尝试签署 Windows 构建时,它无法签署它。

如果可能的话,我想尝试在 macOS 机器上签署 Windows build,因为我在文档中读到这是可能的(我希望我没看错?)

尝试协同设计后,我使用以下方法检查构建: codesign -dv [path/to/app/appname].exe

并且总是得到(仅对于 Windows 构建,Mac 应用程序签名正常): code object is not signed at all

我正在为 Mac 和 Windows 构建,但是对于 Windows 我目前只为 ia32 架构构建。这是我的构建配置在 package.json

中的样子
"build": {
    "appId": "[my-app-id]",
    "files": [
      "public/**/*",
      "node_modules/**/*",
      "package.json"
    ],
    "directories": {
      "buildResources": "build/resources"
    },
    "mac": {
      "category": "public.app-category.productivity",
      "target": [
        "dmg",
        "zip"
      ],
      "publish": {
        "provider": "s3",
        "bucket": "[BUCKET_NAME]",
        "path": "my-path"
      }
    },
    "win": {
      "target": [
        {
          "target": "nsis",
          "arch": [
            "ia32"
          ]
        }
      ],
      "publish": {
        "provider": "s3",
        "bucket": "[BUCKET NAME]",
        "path": "my-path"
      }
    },
    "extends": null
  },

这也是我的 .env 文件的样子,我在其中为 electron-builder 加载了环境变量:

export ENV_NAME=staging

export CSC_NAME='[certificatename]' #example 1A3JKJD89O
export CSC_LINK=./path/to/mycert/cert.p12
export CSC_KEY_PASSWORD='my-passowrd'
export WIN_CSC_LINK=./path/to/mycert/cert.p12
export WIN_CSC_KEY_PASSWORD='my-passowrd'
export CSC_IDENTITY_AUTO_DISCOVERY=true
export DEBUG=electron-builder

export AWS_ACCESS_KEY_ID=[AWSKEYID]
export AWS_SECRET_ACCESS_KEY=[AWSSECRETACCESSKEY]
export AWS_S3_ENDPOINT=[S3ENDPOINT]

最后,这是我 运行 打包构建的 yarn 命令(这是在 yarn 脚本中)

export $(grep -v '^#' ./path/t/my/env/file/staging.env | xargs) && electron-builder -p never -mw --ia32 

我不确定我在这里遗漏了什么?有人知道我还需要做什么吗? 谢谢! :)

据我了解,您必须使用兼容的证书:

https://www.electron.build/code-signing

To sign an app on Windows, there are two types of certificates:

EV Code Signing Certificate

Code Signing Certificate

个人很难获得正确的证书。适用于 Windows 的证书并不容易获得,我必须通过大量的文书工作才能完成。 我希望这篇文章能让你的生活更轻松: https://blog.dcpos.ch/how-to-make-your-electron-app-sexy

转到部分:已签名的安装程序

引用文章:

To get a Windows signing certificate, we recommend Digicert. The documentation for Windows app signing is surprisingly bad. If you go with the wrong vendor, they'll ask you to mail them notarized paperwork. That makes it a slow and annoying process to get the cert. Digicert is easier: they just send you a password via Certified Mail, you go to the post office, show your ID to pick it up, and bam, you get your signing certificate.

对于实际上在 Mac 上使用证书时遇到问题的任何人,这对我有用:(我最终通过 windows 获得了证书,通过Mac)

  1. 在 Windows 上使用 IE 11 来请求证书(它应该生成它 自动通过您首选的证书提供者网站(我使用 Comodo,因为您无需等待他们发​​送 U 盘)
  2. 一旦他们向您颁发证书,请使用您的证书提供商发送给您的电子邮件 link 并使用您请求它的同一浏览器 打开。它应该说“成功”,但视觉上不会发生任何其他事情。
  3. 打开 IE 设置,在“内容”中找到证书并导出为带有私钥的 .PFX。 (您需要指定密码)
  4. 将证书复制到您的 Mac,然后在钥匙串中打开。
  5. 最后,您现在可以将其导出为 .p12 格式 并保存到应用程序中指定的目录,并通过构建命令 built/sign 应用程序。

如果有人知道更简单的方法,请分享!