【问题标题】:Windows kernel mode code signing problemsWindows 内核模式代码签名问题
【发布时间】:2017-02-04 21:17:59
【问题描述】:

问题总结

我的 Windows 应用程序包含一个加载相当简单的驱动程序的服务。此驱动程序包含嵌入的 SHA1 和 SHA256 签名,并包括它们的交叉签名证书链,符合 MS Kernel Signing doc 中描述的 KMCS 要求,用于签署没有 CAT 文件的驱动程序。

驱动程序在大多数 Windows 安装中都可以正常加载,但在极少数情况下无法加载,主要是在 Windows 7 x64 和 Windows 10 x64 上。错误是 0x241 (577):Windows 无法验证此文件的数字签名。最近的硬件或软件更改可能安装了签名错误或损坏的文件,或者可能是来自未知来源的恶意软件。

更多信息

在两周的大部分时间里,我一直在试图找出导致此问题的原因。正如您所料,这个错误只会出现在用户的机器上。我已经安装了 4 台使用 Windows 7 x64 的虚拟机和另外 4 台使用 Windows 10 x64 的虚拟机,它们具有各种配置和不同级别的更新。我甚至在其中一个 Windows 10 虚拟机中完全复制了用户的设置——我花了一整天的时间用正确的语言和他们拥有的所有软件安装了精确的 Windows 版本,以试图复制问题。但是,没有这样的运气:安装我的应用程序时,驱动程序加载得非常好。

希望有人对可能发生的事情有所了解,或者至少可以为我指明正确的方向,我决定在这里问:什么可能导致驱动程序明显正确签名在某些 Windows 安装上验证失败

更多详情

我正在使用 StartCom 3 类代码签名证书。我从Microsoft Cross-Certificates for Kernel Mode Code Signing 页面下载了交叉签名的 StartCom 证书。

我的证书在 pfx 文件中,我正在对驱动程序进行如下签名:

signtool.exe sign /v /ac "MS_xs_st.crt" /d "Driver description" /du "https://webpage/" /f my_certificate.pfx /t http://timestamp.verisign.com/scripts/timstamp.dll /p %1 driver.sys
signtool.exe sign /v /ac "MS_xs_st.crt" /d "Driver description" /du "https://webpage/" /f my_certificate.pfx /fd sha256 /tr http://timestamp.comodoca.com/?td=sha256 /td sha256 /as /p %1 driver.sys

由于这不是需要安装的硬件驱动程序,因此它不包含 .CAT 文件或 .INF 文件。它只是一个在服务启动时加载并在服务停止时卸载的驱动程序。

可以注意到,SHA256 签名添加在 SHA1 签名之后(使用 /as),并且它还使用 SHA256 时间戳服务器。它是双重签名的,以便与旧操作系统兼容,尽管我必须说它无法在 Vista x64 中加载,大概是因为我的证书使用 SHA256 作为签名算法。值得注意的是,驱动程序可以在 Windows XP x64 上正常加载。还值得一提的是,在检查文件属性的“数字签名”选项卡时,所有未能加载的用户都报告说这两个签名都经过了很好的验证。我可以在没有 Vista x64 兼容性的情况下生活,但 Windows 7 和 Windows 10 的问题非常令人担忧,并迫使我将应用程序保持在 beta 测试中。

在各种 Windows 版本的大约 150 多次安装中,我有:

  • 在 Windows 7 x64 中验证失败的 3 个用户。其中一个没有安装所有更新,继续安装了大约 200 个更新,之后验证通过并解决了问题。我建议更新给其他 2 个有同样问题的用户,但我没有收到任何反馈,所以我不知道问题是否已解决,我什至不知道他们的 Windows 是否是最新的。
  • 在 Windows 10 x64 上无法加载驱动程序的 3 个用户。他们所有人都比 Windows 7 用户响应更快,我发现他们都安装了所有更新。使用 Windows 10 周年版安装工具包安装的三个用户中有两个。
  • 1 个用户的驱动程序无法在 Windows 2003 R2 x86 上加载。我还使用此操作系统创建了一个 VM,但未能重现该问题。

每次驱动程序加载失败时,都会在安全事件类别中生成一个审核失败事件,其中包含以下文本: *代码完整性确定文件的图像哈希无效。该文件可能由于未经授权的修改而损坏,或者无效的哈希可能表示潜在的磁盘设备错误。

文件名:\Device\HarddiskVolumeX\Program Files (x86)\path\to\driver.sys*

我在 Vista x64 中遇到完全相同的错误,并且启用代码完整性详细日志会导致大量关于加载所有 .CAT 文件的消息,而没有其他感兴趣的信息。当然,在 Vista x64 中,代码完整性操作日志包含一个关于文件未得到验证的错误,与上面的审核错误非常相似。

跑步

signtool.exe verify /v /kp driver.sys

结果:

Verifying: driver.sys
Signature Index: 0 (Primary Signature)
Hash of file (sha1): EE2FE2A16395DC66ACCB5264742987D99ECF5A66

Signing Certificate Chain:
    Issued to: StartCom Certification Authority
    Issued by: StartCom Certification Authority
    Expires:   Wed Sep 17 22:46:36 2036
    SHA1 hash: 3E2BF7F2031B96F38CE6C4D8A85D3E2D58476A0F

        Issued to: StartCom Class 3 Object CA
        Issued by: StartCom Certification Authority
        Expires:   Mon Dec 16 04:00:05 2030
        SHA1 hash: E181101EE744817E49B6F97466E14DFA0809BD46

            Issued to: My company
            Issued by: StartCom Class 3 Object CA
            Expires:   Sun Aug 04 16:18:18 2019
            SHA1 hash: 62...E9

The signature is timestamped: Sun Sep 25 12:49:52 2016
Timestamp Verified by:
    Issued to: Thawte Timestamping CA
    Issued by: Thawte Timestamping CA
    Expires:   Fri Jan 01 02:59:59 2021
    SHA1 hash: BE36A4562FB2EE05DBB3D32323ADF445084ED656

        Issued to: Symantec Time Stamping Services CA - G2
        Issued by: Thawte Timestamping CA
        Expires:   Thu Dec 31 02:59:59 2020
        SHA1 hash: 6C07453FFDDA08B83707C09B82FB3D15F35336B1

            Issued to: Symantec Time Stamping Services Signer - G4
            Issued by: Symantec Time Stamping Services CA - G2
            Expires:   Wed Dec 30 02:59:59 2020
            SHA1 hash: 65439929B67973EB192D6FF243E6767ADF0834E4

Cross Certificate Chain:
    Issued to: Microsoft Code Verification Root
    Issued by: Microsoft Code Verification Root
    Expires:   Sat Nov 01 16:54:03 2025
    SHA1 hash: 8FBE4D070EF8AB1BCCAF2A9D5CCAE7282A2C66B3

        Issued to: StartCom Certification Authority
        Issued by: Microsoft Code Verification Root
        Expires:   Thu Apr 15 23:23:19 2021
        SHA1 hash: E6069E048DEA8D817AFC4188B1BEF1D888D0AF17

            Issued to: StartCom Class 3 Object CA
            Issued by: StartCom Certification Authority
            Expires:   Mon Dec 16 04:00:05 2030
            SHA1 hash: E181101EE744817E49B6F97466E14DFA0809BD46

                Issued to: My company
                Issued by: StartCom Class 3 Object CA
                Expires:   Sun Aug 04 16:18:18 2019
                SHA1 hash: 62...E9


Successfully verified: driver.sys

Number of files successfully Verified: 1
Number of warnings: 0
Number of errors: 0

跑步

signtool.exe verify /v /pa /all driver.sys

结果:

Verifying: driver.sys
Signature Index: 0 (Primary Signature)
Hash of file (sha1): EE2FE2A16395DC66ACCB5264742987D99ECF5A66

Signing Certificate Chain:
    Issued to: StartCom Certification Authority
    Issued by: StartCom Certification Authority
    Expires:   Wed Sep 17 22:46:36 2036
    SHA1 hash: 3E2BF7F2031B96F38CE6C4D8A85D3E2D58476A0F

        Issued to: StartCom Class 3 Object CA
        Issued by: StartCom Certification Authority
        Expires:   Mon Dec 16 04:00:05 2030
        SHA1 hash: E181101EE744817E49B6F97466E14DFA0809BD46

            Issued to: My company
            Issued by: StartCom Class 3 Object CA
            Expires:   Sun Aug 04 16:18:18 2019
            SHA1 hash: 62...E9

The signature is timestamped: Sun Sep 25 12:49:52 2016
Timestamp Verified by:
    Issued to: Thawte Timestamping CA
    Issued by: Thawte Timestamping CA
    Expires:   Fri Jan 01 02:59:59 2021
    SHA1 hash: BE36A4562FB2EE05DBB3D32323ADF445084ED656

        Issued to: Symantec Time Stamping Services CA - G2
        Issued by: Thawte Timestamping CA
        Expires:   Thu Dec 31 02:59:59 2020
        SHA1 hash: 6C07453FFDDA08B83707C09B82FB3D15F35336B1

            Issued to: Symantec Time Stamping Services Signer - G4
            Issued by: Symantec Time Stamping Services CA - G2
            Expires:   Wed Dec 30 02:59:59 2020
            SHA1 hash: 65439929B67973EB192D6FF243E6767ADF0834E4

Signature Index: 1
Hash of file (sha256): 79E9A2EF552906EA10F56FF7B2F95A1999B52902BCD9B78DD076157B563E900B

Signing Certificate Chain:
    Issued to: StartCom Certification Authority
    Issued by: StartCom Certification Authority
    Expires:   Wed Sep 17 22:46:36 2036
    SHA1 hash: 3E2BF7F2031B96F38CE6C4D8A85D3E2D58476A0F

        Issued to: StartCom Class 3 Object CA
        Issued by: StartCom Certification Authority
        Expires:   Mon Dec 16 04:00:05 2030
        SHA1 hash: E181101EE744817E49B6F97466E14DFA0809BD46

            Issued to: My company
            Issued by: StartCom Class 3 Object CA
            Expires:   Sun Aug 04 16:18:18 2019
            SHA1 hash: 62...E9

The signature is timestamped: Sun Sep 25 12:49:53 2016
Timestamp Verified by:
    Issued to: UTN-USERFirst-Object
    Issued by: UTN-USERFirst-Object
    Expires:   Tue Jul 09 21:40:36 2019
    SHA1 hash: E12DFB4B41D7D9C32B30514BAC1D81D8385E2D46

        Issued to: COMODO SHA-256 Time Stamping Signer
        Issued by: UTN-USERFirst-Object
        Expires:   Tue Jul 09 21:40:36 2019
        SHA1 hash: 36527D4FA26A68F9EB4596F1D99ABB2C0EA76DFA


Successfully verified: driver.sys

Number of signatures successfully Verified: 2
Number of warnings: 0
Number of errors: 0

有点奇怪的是,不使用特殊开关进行验证会导致证书链错误。再说一次,我在检查 VMWare 驱动程序时遇到了同样的错误,所以我想这没什么好担心的。无论如何,运行:

signtool.exe verify /v /all driver.sys

结果:

Verifying: driver.sys
Signature Index: 0 (Primary Signature)
Hash of file (sha1): EE2FE2A16395DC66ACCB5264742987D99ECF5A66

Signing Certificate Chain:
    Issued to: StartCom Certification Authority
    Issued by: StartCom Certification Authority
    Expires:   Wed Sep 17 22:46:36 2036
    SHA1 hash: 3E2BF7F2031B96F38CE6C4D8A85D3E2D58476A0F

        Issued to: StartCom Class 3 Object CA
        Issued by: StartCom Certification Authority
        Expires:   Mon Dec 16 04:00:05 2030
        SHA1 hash: E181101EE744817E49B6F97466E14DFA0809BD46

            Issued to: My company
            Issued by: StartCom Class 3 Object CA
            Expires:   Sun Aug 04 16:18:18 2019
            SHA1 hash: 62...E9

The signature is timestamped: Sun Sep 25 12:49:52 2016
Timestamp Verified by:
    Issued to: Thawte Timestamping CA
    Issued by: Thawte Timestamping CA
    Expires:   Fri Jan 01 02:59:59 2021
    SHA1 hash: BE36A4562FB2EE05DBB3D32323ADF445084ED656

        Issued to: Symantec Time Stamping Services CA - G2
        Issued by: Thawte Timestamping CA
        Expires:   Thu Dec 31 02:59:59 2020
        SHA1 hash: 6C07453FFDDA08B83707C09B82FB3D15F35336B1

            Issued to: Symantec Time Stamping Services Signer - G4
            Issued by: Symantec Time Stamping Services CA - G2
            Expires:   Wed Dec 30 02:59:59 2020
            SHA1 hash: 65439929B67973EB192D6FF243E6767ADF0834E4

SignTool Error: A certificate chain processed, but terminated in a root
        certificate which is not trusted by the trust provider.
Signature Index: 1
Hash of file (sha256): 79E9A2EF552906EA10F56FF7B2F95A1999B52902BCD9B78DD076157B563E900B

Signing Certificate Chain:
    Issued to: StartCom Certification Authority
    Issued by: StartCom Certification Authority
    Expires:   Wed Sep 17 22:46:36 2036
    SHA1 hash: 3E2BF7F2031B96F38CE6C4D8A85D3E2D58476A0F

        Issued to: StartCom Class 3 Object CA
        Issued by: StartCom Certification Authority
        Expires:   Mon Dec 16 04:00:05 2030
        SHA1 hash: E181101EE744817E49B6F97466E14DFA0809BD46

            Issued to: My company
            Issued by: StartCom Class 3 Object CA
            Expires:   Sun Aug 04 16:18:18 2019
            SHA1 hash: 62...E9

The signature is timestamped: Sun Sep 25 12:49:53 2016
Timestamp Verified by:
    Issued to: UTN-USERFirst-Object
    Issued by: UTN-USERFirst-Object
    Expires:   Tue Jul 09 21:40:36 2019
    SHA1 hash: E12DFB4B41D7D9C32B30514BAC1D81D8385E2D46

        Issued to: COMODO SHA-256 Time Stamping Signer
        Issued by: UTN-USERFirst-Object
        Expires:   Tue Jul 09 21:40:36 2019
        SHA1 hash: 36527D4FA26A68F9EB4596F1D99ABB2C0EA76DFA

SignTool Error: A certificate chain processed, but terminated in a root
        certificate which is not trusted by the trust provider.

Number of signatures successfully Verified: 0
Number of warnings: 0
Number of errors: 2

我正在使用 VS 2015 附带的 8.1 Windows 工具包中的 signtool.exe,它的版本是 6.3.9600.17298。值得一提的是,驱动程序是使用 WDK 7.1.0 (7600.13685.1) 编译的。

【问题讨论】:

  • 好吧,在启用安全启动的情况下,周年更新后,您的驱动程序可能不会在 Windows 10 x64 上加载,因为 Microsoft 对 KMCS(EV 证书,需要从女士也是)。但我希望你已经知道这一点。当我尝试在未更新的旧 Windows(Vista,7)上加载驱动程序时,我实际上遇到了与您类似的问题。我怀疑问题是由于 Windows 不信任交叉签名证书,因为它是在上次更新日期之后发布的。

标签: windows kernel driver code-signing driver-signing


【解决方案1】:

正如上面的 Martin Drab 所说,问题是双重的。顺便说一句,感谢 Martin,您的评论帮助我解决了问题,通过设置启用了安全启动的 VM,我能够重现 Windows 10 问题。

对于早于 Windows 10 的操作系统,该问题似乎可以通过安装所有最新更新来解决。如果 PC 在 2015 年 11 月 1 日之前(新的 Microsoft 代码验证根证书颁发时)没有更新,它将无法验证,因为内核无法识别根证书。

对于 Windows 10,有一个新的Kernel Mode Code Signining Policy,它指定所有全新安装的 Windows 10 周年版将不会验证任何未经 Microsoft 开发门户(需要 EV 证书)签名的内核代码,除非它已签名具有 2015 年 7 月 29 日之前颁发的交叉签名证书或禁用安全启动。

这个问题很少发生的原因是大多数人没有多年未更新的 Windows 7 机器,而在撰写本文时大多数拥有 Windows 10 的机器没有使用全新安装周年纪念版。

Windows 10 唯一真正的解决方案是获得 EV 证书。

【讨论】:

  • 而且你拿到EV证书后,还得使用Windows Hardware Developer Center Dashboard portal(微软运行的一个网络应用)来给你的驱动签名,对吧?我写了一篇关于这些东西的大文章,如果你有任何意见,我将不胜感激:davidegrayson.com/signing 你的 StartCom 交叉证书是什么时候发布的?您是否尝试过使用 GlobalSign 证书?
  • 你是对的,一旦你有一个 EV 证书,你必须让驱动程序由 MS Dev Portal 签名。我在发帖之前阅读了您的文章,但不知何故我忽略了 Windows 10 部分中的信息,因为我的驱动程序在大多数安装中都可以正常工作,当时我只遇到了 Windows 7 的问题。不错的文章,感谢您抽出宝贵时间帮助他人。
  • 我的证书是在 04.08.2016 颁发的,StartCom 交叉证书链是在 2016 年颁发的。他们没有旧的交叉签名证书,我请求支持。另外,我没有 GlobalSign 证书,但如果您确认它仍然适用于启用安全启动的全新安装的 Windows 10 周年纪念版,请在此处发布,可能值得购买,因为我无法获得 EV证书(由于缺乏公共注册机构,他们不会向离岸公司颁发 EV 证书,而且仅仅为此目的创建一家常规公司太麻烦了)。
  • 仅供参考,如果您想使用它,Windows 2012 R2 中的 Hyper-V 包括也支持安全启动的第 2 代 VM,这就是我重现问题的方式。我很确定 Windows 10 中包含的那个也有这个功能。
  • 由于您无法获得 EV 证书并且您的客户遇到了麻烦,因此尝试 GlobalSign 的普通证书可能是值得的。我基本上不需要签署内核模块,所以我不太可能很快尝试。
猜你喜欢
  • 2011-04-22
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-26
  • 1970-01-01
  • 1970-01-01
  • 2015-07-08
相关资源
最近更新 更多