visual studio signing error: this certificate is not trusted on this PC

visual studio signing error: this certificate is not trusted on this PC

我正在尝试签署一个 UWP 应用程序,无论是调试还是发布,以便在其他一些设备上进行测试。我的证书似乎无效。

这是我的步骤:

如果我继续,VS 将创建一个包含一些安装文件的文件夹。如果我单击“...x64.msixbundle”,它会显示一个对话框,上面写着“更新...?”,并带有注释“不受信任的应用程序”和下面的消息“此应用程序包未使用受信任的签名证书...”(或者,我可以 运行 在 powershell 中安装 ps1 脚本,得到相同的结果。)我不能更进一步。而且,这是在我进行开发的同一台 PC 上。

我已尝试按照 Create a certificate for package signing 和一些相邻页面上的说明进行操作。他们推断使用 VS 向导应该很简单。

P.S。我以前从未签署过 Windows 应用程序。也许我应该以完全不同的方式来做?

需要信任主题与发布者匹配的证书。

那么该怎么办:

a) 证书是自签名的(颁发者与主题相同)

  • 运行 certlm.msc(机器范围信任)或 certmgr.msc 当前用户信任。
  • 导入证书到Trusted Root Certificate Authorities

b) 证书不是自签名的(颁发者与主题不同)

如果您购买了真实的代码签名证书,则无需执行任何操作,因为您支付的正是我们正在建立的信任...

  • 获得root/issuer证书
    • *有一个.cer
      • 双击cer文件
      • 单击 Certificate Path 选项卡。
      • 双击树中的第一个证书 - 如果只有一个,请询问您从哪里获得证书!
      • 在新打开的 window 上单击 Details 选项卡
      • 点击Copy to file按钮保存根证书。
    • 导入 *.pfx
      • 运行 certmgr.msc
      • 右键单击 Personal 和 select Advanced Tasks | Import 以导入 pfx 文件。
      • 识别导入的证书并导出根证书(查看是否有 *.cer)
  • 运行 certlm.msc(机器范围信任)或 certmgr.msc 当前用户信任。
  • 导入根证书到Trusted Root Certificate Authorities

对于包签名,对证书有额外要求:

The certificate that you use to sign the app package must meet these criteria:

  • The subject name of the certificate must match the Publisher attribute that is contained in the Identity element of the AppxManifest.xml file that is stored within the package. The publisher name is part of the identity of a packaged Windows app, so you have to make the subject name of the certificate match the publisher name of the app. This allows the identity of signed packages to be checked against the digital signature. For info about signing errors that can arise from signing an app package using SignTool, see the Remarks section of How to create an app package signing certificate.
  • The certificate must be valid for code signing. This means that both of these items must be true:
    • The Extended Key Usage (EKU) field of the certificate must either be unset or contain the EKU value for code signing (1.3.6.1.5.5.7.3.3).
    • The Key Usage (KU) field of the certificate must either be unset or contain the usage bit for digital signature (0x80).
  • The certificate contains a private key.
  • The certificate is valid. It is active, hasn't expired, and hasn't been revoked.

来源:https://docs.microsoft.com/en-us/windows/win32/appxpkg/how-to-sign-a-package-using-signtool

将 VS 配置为使用签署了您要使用的证书的客户 CA(证书颁发机构)。

此 CA 应该是根 CA,因此任何中间 CA 也将受到信任。

此问题的一般原因是缺少根 CA 并且无法完成信任链,这意味着您可能只安装了中间 CA。