通过证明对 Windows 10 及更高版本的驱动程序进行签名

本文介绍如何使用证明签名对驱动程序进行签名。 有关证明签名的详细信息和要求,请参阅 Windows 10 证明签名的驱动程序

重要

截至 2023 年 3 月 1 日,面向零售受众的证明签署的驱动程序不再发布Windows 更新。 选择 CoDev测试注册表项/Surface SSRK 选项时,仍支持测试方案的已签名驱动程序。

先决条件

创建 CAB 文件

在本部分中,我们将逐步完成创建 CAB 文件提交的过程。 我们将使用 echo 驱动程序示例来演示该过程。

典型的 CAB 文件提交必须包含以下内容:

  • 驱动程序本身,例如Echo.sys

  • 仪表板用于促进签名过程的驱动程序 INF 文件。

  • 符号文件,用于调试信息。 例如,Echo.pdb。 Microsoft 自动崩溃分析工具需要 .pdb 文件。

  • 目录 .CAT 文件是必需的,仅用于公司验证。 Microsoft 会重新生成目录文件,并替换已提交的任何目录文件。

注意

CAB 文件中的每个驱动程序文件夹都必须支持同一组体系结构。 例如,它们必须支持 x86、x64,或者全都必须同时支持 x86 和 x64。

当引用驱动程序位置 (\\\server\share) 时,请勿使用 UNC 文件共享路径。 必须使用映射的驱动器号才能使 CAB 有效。

若要创建 CAB 文件,请执行以下操作:

  1. 将要签名的二进制文件收集到一个目录中。 在本示例中,我们将使用 C:\\Echo

  2. 以 管理员istrator 身份打开命令提示符窗口。

  3. 输入 MakeCab /? 以查看 MakeCab 选项:

    C:\Echo> MakeCab /?
    Cabinet Maker - Lossless Data Compression Tool
    
    MAKECAB [/V[n]] [/D var=value ...] [/L dir] source [destination]
    MAKECAB [/V[n]] [/D var=value ...] /F directive_file [...]
    
    source         File to compress.
    destination    File name to give compressed file.  If omitted, the
                   last character of the source file name is replaced
                   with an underscore (_) and used as the destination.
    /F directives  A file with MakeCAB directives (may be repeated). Refer to
                   Microsoft Cabinet SDK for information on directive_file.
    /D var=value   Defines variable with specified value.
    /L dir         Location to place destination (default is current directory).
    /V[n]          Verbosity level (1..3).
    
  4. 准备 cab 文件 DDF 输入文件。 对于我们的 Echo 驱动程序,它可能如下所示。

    ;*** Echo.ddf example
    ;
    .OPTION EXPLICIT     ; Generate errors
    .Set CabinetFileCountThreshold=0
    .Set FolderFileCountThreshold=0
    .Set FolderSizeThreshold=0
    .Set MaxCabinetSize=0
    .Set MaxDiskFileCount=0
    .Set MaxDiskSize=0
    .Set CompressionType=MSZIP
    .Set Cabinet=on
    .Set Compress=on
    ;Specify file name for new cab file
    .Set CabinetNameTemplate=Echo.cab
    ; Specify the subdirectory for the files.  
    ; Your cab file should not have files at the root level,
    ; and each driver package must be in a separate subfolder.
    .Set DestinationDir=Echo
    ;Specify files to be included in cab file
    C:\Echo\Echo.Inf
    C:\Echo\Echo.Sys
    
  5. 输入以下内容以创建 CAB 文件。

    C:\Echo> MakeCab /f "C:\Echo\Echo.ddf
    

    MakeCab 的输出应显示创建的 CAB 文件中的文件数。 在本例中,应该有两个文件。

    C:\Echo> MakeCab /f Echo.ddf
    Cabinet Maker - Lossless Data Compression Tool
    
    17,682 bytes in 2 files
    Total files:              2
    Bytes before:        17,682
    Bytes after:          7,374
    After/Before:            41.70% compression
    Time:                     0.20 seconds ( 0 hr  0 min  0.20 sec)
    Throughput:              86.77 Kb/second
    
  6. Disk1 子目录中找到 CAB 文件。 可以在文件资源管理器中选择 CAB 文件,以验证它是否包含所需的文件。

使用 EV 证书对 CAB 文件进行签名

  1. 使用 EV 证书提供商推荐的过程通过 EV 证书对 CAB 文件进行签名。 例如,要使用 SHA256 证书/摘要算法/时间戳对 CAB 文件进行签名,请输入以下命令:

    C:\Echo> SignTool sign /ac "C:\MyEVCert.cer" /s MY /n "Company Name" /fd sha256 /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /td sha256 /v "C:\Echo\Disk1\Echo.cab"
    

    重要

    切记使用行业最佳做法管理 EV 代码签名过程的安全性。

使用合作伙伴中心提交 EV 签名的 Cab 文件

  1. 转到合作伙伴中心硬件仪表板并使用凭据登录。

  2. 选择“提交新硬件”

    Screenshot of the the list of submitted hardware.

  3. 在“包和签名属性”部分,输入驱动程序提交的产品名称。 此名称可用于搜索和组织驱动程序提交。

    注意

    如果与其他公司共享你的驱动程序,他们会看到该名称。

  4. 取消选中这两个测试签名选项。

  5. 对于“请求的签名”,选择希望包含在驱动程序包中的签名

    A screenshot showing the options for submitting the echo driver for signing.

  6. 向下浏览页面,然后选择“提交”

  7. 签名过程完成后,请从硬件仪表板下载已签名的驱动程序。

验证驱动程序是否已正确签名

完成以下步骤以确保驱动程序已正确签名。

  1. 下载提交文件后,解压缩驱动程序文件。

  2. 以 管理员istrator 身份打开命令提示符窗口。

  3. 输入以下命令来验证驱动程序是否已按预期签名。

    C:\Echo> SignTool verify Echo.Sys
    
  4. 若要列出其他信息,并让 signtool 验证包含多个签名的文件中的所有签名,请输入以下命令:

     C:\Echo> SignTool verify /pa /ph /v /d Echo.Sys
    
  5. 若要确认驱动程序的 EKU,请完成以下步骤。

    1. 打开 Windows 资源管理器并找到二进制文件。 选择并按住(或右键单击)该文件并选择“属性”

    2. “数字签名”选项卡上,选择“签名 ”列表中的列出项。

    3. 选择“详细信息”,然后选择“查看证书”

    4. 在“详细信息”选项卡上,选择“增强型密钥用法”

当驱动程序由仪表板重新签名时,将使用以下过程。

  • 追加 Microsoft SHA2 嵌入式签名。
  • 如果客户使用自己的证书对驱动程序二进制文件进行嵌入式签名,将不会覆盖这些签名。
  • 使用 SHA2 Microsoft 证书创建并签名新目录文件。 此目录替换客户提供的任何现有目录。

在 Windows 10 上测试驱动程序

使用以下说明安装示例驱动程序。

  1. 以 管理员istrator 身份打开命令提示符窗口。 转到你的驱动程序包文件夹,然后输入以下命令。

    C:\Echo> devcon install echo.inf root\ECHO
    
  2. 确认驱动程序安装过程不会显示“Windows 无法验证该驱动程序软件的发布者。”Windows 安全对话框。

创建包含多个驱动程序的提交

若要同时提交多个驱动程序,请执行以下操作:

  1. 为每个驱动程序创建一个子目录,如下所示。

    A diagram showing an example driver signing directory structure.

  2. 准备一个引用子目录的 CAB 文件 DDF 输入文件。 它应如下所示:

    ;*** Submission.ddf multiple driver example
    ;
    .OPTION EXPLICIT     ; Generate errors
    .Set CabinetFileCountThreshold=0
    .Set FolderFileCountThreshold=0
    .Set FolderSizeThreshold=0
    .Set MaxCabinetSize=0
    .Set MaxDiskFileCount=0
    .Set MaxDiskSize=0
    .Set CompressionType=MSZIP
    .Set Cabinet=on
    .Set Compress=on
    ;Specify file name for new cab file
    .Set CabinetNameTemplate=Echo.cab
    ;Specify files to be included in cab file
    ; First Driver
    .Set DestinationDir=DriverPackage1
    C:\DriverFiles\DriverPackage1\Driver1.sys
    C:\DriverFiles\DriverPackage1\Driver1.inf
    ; Second driver
    .Set DestinationDir=DriverPackage2
    C:\DriverFiles\DriverPackage2\Driver2.sys
    C:\DriverFiles\DriverPackage2\Driver2.inf