PE文件数字签名工具

"C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\signtool.exe"

 

签名工具是一个命令行工具的数字签名的文件,验证文件和时间戳文件中的签名。

签名工具将自动安装的 Visual Studio 中。 要启动工具,请使用 Visual Studio 命令提示符 签名工具具有以下常规语法:

signtool [command] [options] [file_name | ...]

http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gif参数


参数

说明

command

四个命令之一 catdb sign Timestamp,或 Verify 的指定操作执行的 文件。 每个命令的说明,请参阅下表。

options

修改命令的选项。 除了在全局 /q /v选项,每个命令支持一组唯一的 选项。

file_name

要进行签名的文件的路径。

签名工具支持下列命令。 每个命令使用不同的其各自的各节中列出的选项集。

Command

说明

catdb

Adds a catalog file to, or removes it from, a catalog database. Catalog databases are used for automatic lookup of catalog files and are identified by GUID. For a list of the options supported by the catdb command, see catdb Command Options.

sign

对文件进行数字签名。 Digital signatures protect files from tampering, and enable users to verify the signer based on a signing certificate. For a list of the options supported by the sign command, see sign Command Options.

Timestamp

Time-stamps files. For a list of the options supported by the TimeStamp command, see TimeStamp Command Options.

Verify

Verifies the digital signature of files by determining whether the signing certificate was issued by a trusted authority, whether the signing certificate has been revoked, and, optionally, whether the signing certificate is valid for a specific policy. For a list of the options supported by the Verify command, see Verify Command Options.

下列选项适用于所有签名工具命令。

全局选项

说明

/q

执行成功时不生成输出,执行失败时生成最少的输出。

/v

执行成功、执行失败或产生警告消息时生成详细输出。

http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gifcatdb Command Options


The following table lists the options that can be used with the catdb command.

Catdb 选项

说明

/d

指定更新默认目录数据库。 If neither the /d nor the /g option is used, Sign Tool updates the system component and driver database.

/gGUID

Specifies that the catalog database identified by the globally unique identifier GUID is updated.

/r

Removes the specified catalogs from the catalog database. If this option is not specified, Sign Tool adds the specified catalogs to the catalog database.

/u

指定为添加的目录文件自动生成唯一的名称。 If necessary, the catalog files are renamed to prevent name conflicts with existing catalog files. If this option is not specified, Sign Tool overwrites any existing catalog that has the same name as the catalog being added.

http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gifsign Command Options


The following table lists the options that can be used with the sign command.

Sign command option

说明

/a

自动选择最佳的签名证书。 签名工具将查找满足所有指定的条件的所有有效的证书,并选择一个时间最长为有效的。 如果未指定该选项,签名工具仅查找一个有效的签名证书。

/ac file

文件 附加的证书添加到签名块。

/c CertTemplateName

指定用于对证书进行签名的证书模板名(一个 Microsoft 扩展)。

/csp CSPName

指定包含私钥容器的加密服务提供程序 (CSP)

/d Desc

指定已签名内容的说明。

/du URL

为已签名文档的详细说明指定统一资源定位器 (URL)

/f SignCertFile

指定文件中的签名证书。 如果该文件的个人信息交换 (PFX) 格式且受密码保护,使用 /p选项来指定 密码。 如果该文件不包含私钥,使用 /csp /k选项来指定 CSP 私钥容器名。

/fd

指定要用于创建文件签名文件摘要算法。 默认值为 SHA1

/i IssuerName

指定签名证书的颁发者的名称。 该值可以是整个颁发者名称的子字符串。

/kc PrivKeyContainerName

指定私钥容器名。

/n SubjectName

指定签名证书的主体的名称。 该值可以是整个主体名称的子字符串。

/nph

如果支持,取消页面的可执行文件的哈希值。 默认情况下确定由 SIGNTOOL_PAGE_HASHES 环境变量和 wintrust.dll 版本。

/p Password

指定打开 PFX 文件时使用的密码。 (使用 /f选项来指定) PFX 文件。

/ph

如果支持,生成页的可执行文件的哈希值。

/r RootSubjectName

指定签名证书必须链接到的根证书的主体名称。 该值可以是根证书的整个主题名称的子字符串。

/s StoreName

指定要在搜索证书时打开的存储区。 如果未指定此选项,则 My打开存储区

/sha1 Hash

指定签名证书的 SHA1 哈希。

/sm

指定在计算机存储区而不是一个用户存储区的使用。

/t URL

指定时间戳服务器的 URL 如果此选项 (或 /tr 不是存在,已签名的文件将不是时间戳 如果时间戳操作失败,将生成一个警告。 此选项不能与 /tr 选项一起使用。

/td alg

使用 /tr选项以请求一个摘要算法,所使用的 RFC 3161 时间戳服务器。

/tr URL

指定 RFC 3161 时间戳服务器的 URL 如果此选项 (或 /t 不是存在,已签名的文件将不是时间戳 如果时间戳操作失败,将生成一个警告。 此选项不能与 /t 选项一起使用。

/u Usage

指定签名证书中必须存在的增强型密钥用法 (EKU) 可以通过 OID 或字符串指定该用法的值。 默认用法为代码签名”(1.3.6.1.5.5.7.3.3)

/uw

指定"Windows 系统组件验证"1.3.6.1.4.1.311.10.3.6 的使用的情况。

http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gif时间戳命令选项


下表列出了该选项可使用 TimeStamp命令。

时间戳选项

说明

/t URL

指定时间戳服务器的 URL 要执行时间戳操作的文件必须在以前已经进行了签名。 或者在 /t /tr选项是必需的

/td alg

请求所使用的 RFC 3161 时间戳服务器的摘要算法。 /td用于在/tr选项

/tr URL

指定 RFC 3161 时间戳服务器的 URL 要执行时间戳操作的文件必须在以前已经进行了签名。 或者在 /tr /t选项是必需的

http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gif验证命令选项


验证选项

说明

/a

指定可以使用所有方法来验证文件。 首先,搜索目录数据库以确定是否在目录中对文件进行了签名。 如果未在任何目录中对文件进行签名,签名工具将尝试验证文件的嵌入签名。 验证可以或不能在目录中进行签名的文件时,建议使用该选项。 这些文件的示例包括 Windows 文件或驱动程序。

/ad

通过使用默认目录数据库查找目录。

/as

通过使用系统组件 (驱动程序) 目录数据库查找目录。

/agCatDBGUID

CatDBGUID 按标识的目录数据库中查找目录。

/cCatFile

通过名称指定目录文件。

/d

指定签名工具应打印描述和说明的 URL

/kp

指定的内核模式驱动程序签名策略与执行验证。

/oVersion

通过操作系统版本验证文件。 版本 具有以下形式: PlatformID : VerMajor VerMinor.BuildNumber

/pa

指定应使用默认的验证码验证策略。 如果 /pa未指定选项,签名工具使用 Windows 驱动程序验证策略。 此选项不能使用 catdb选项

/pgPolicyGUID

通过 GUID 指定验证策略。 PolicyGUID 对应于验证策略的 ActionID 此选项不能使用 catdb选项

/ph

指定签名工具应打印,并验证页的哈希值。

/rRootSubjectName

指定签名证书必须链接到的根证书的主体名称。 该值可以是根证书的整个主题名称的子字符串。

/tw

指定是否签名不是时间戳操作应生成一个警告。

http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gif返回值


签名工具返回下面的退出代码之一时终止。

退出代码

说明

0

执行成功。

1

执行失败。

2

执行已完成但出现警告。

http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gif示例


下面的命令添加到系统组件和驱动程序数据库的编录文件 MyCatalogFileName.cat /v选项生成一个唯一的名称,如有必要防止替换现有的编录文件命名为 MyCatalogFileName.cat

复制

signtool catdb /v /u MyCatalogFileName.cat

下面的命令使用的最佳证书自动签署的文件。

复制

signtool sign /a MyFile.exe

下面的命令对文件进行数字签名通过使用密码保护的 PFX 文件中存储的证书。

复制

signtool sign /f MyCert.pfx /p MyPassword MyFile.exe

以下命令数字符号和时间戳的文件。 用于对文件进行签名的证书存储在一个 PFX 文件。

复制

signtool sign /f MyCert.pfx /t http://timestamp.verisgn/com/scripts.timstamp.dll MyFile.exe

下面的命令通过使用位于 My的主题名称的存储区 中证书签名的文件 My Company Certificate

复制

signtool sign /n "My Company Certificate" MyFile.exe

下面的命令对签名的 ActiveX 控件,并提供提示用户安装该控件时,通过 Internet Explorer 显示的信息。

复制

Signtool sign /f MyCert.pfx /d: "MyControl" /du http://www.example.com/MyControl/info.html MyControl.exe

以下命令时间-戳已经已经过数字签名的文件。

复制

signtool timestamp /t http://timestamp.verisgn/com/scripts.timstamp.dll MyFile.exe

下面的命令将验证已签名的文件。

复制

signtool verify MyFile.exe

下面的命令将验证可能会在目录中进行签名的系统文件。

复制

signtool verify /a SystemFile.dll

下面的命令将验证系统文件进行签名,在一个目录中名为 MyCatalog.cat

复制

signtool verify /c MyCatalog.cat SystemFile.dll

 

 

posted @ 2011-07-21 11:48  ahuo  阅读(1932)  评论(0编辑  收藏  举报