是否可以对 VB6 应用程序进行数字签名?

Is it possible to digitally sign a VB6 application?

我在 2001 年为一家公司编写了一个 VB6 应用程序,它显然今天仍在使用。公司要求我对其进行数字签名,这样他们就可以避免 "Windows protected your PC" 对话框:

甚至可以对 VB6 应用程序进行数字签名吗?如果是这样,有人可以指点我教程或类似的东西。

我认为这会对你有所帮助:

https://msdn.microsoft.com/en-us/library/ms995332.aspx

Summary: CAPICOM is a new security technology from Microsoft that allows Microsoft Visual Basic, Visual Basic Script, ASP, and C++ programmers to easily incorporate digital signing and encryption into their application. (5 printed pages)

首先,一般答案是 "yes" - VB6 创建的 EXE 和 DLL 文件可以进行数字签名。

我的理解是,签名过程最终会向已签名的二进制文件添加一些 "metadata",以便稍后检查。这似乎是一个通用的 Windows 特性,并不特定于 VB6 或任何其他特定的编译器(据我所知)。

我签名的具体方法是Visual Build Pro. This signs the binary using a PFX certificate file and also timestamps it. (There are other configuration options as well).

中的构建步骤

请注意,我使用此工具是因为它也是我们用于 VB6 构建自动化的工具(而且效果很好!)但我相信可以使用其他签名工具。

我们一直在使用 Platform SDK 中的 signtool.exe,直到它停止生成 sha-1 签名(为了与 XP 兼容),因此不得不迁移到 osslsigncode 开源实现(带有丑陋的 cygwin 依赖项) .

这是我们的codesign.bat,我们用它来同时使用 sha-1 和更新的 sha-256 签名对可执行文件进行签名。也可以签署 .msi 可再发行组件。

@echo off
setlocal
set CYGWIN=nodosfilewarning
set tmpfile=%TEMP%\~$intermediate.tmp

:: set code-signing certficate .pfx file and password here
set osslsigncode="%~dp0osslsigncode.exe" sign -pkcs12 "%~dp0ucs_code_sign_current.pfx" -pass #########
set signtool="%~dp0signtool.exe" sign /f "%~dp0ucs_code_sign_current.pfx" /p ########

:: set default description and URL here (both options skipped if left empty)
set desc=
set durl=

:parse_params
if [%~1]==[] goto :parse_complete
if [%~1]==[/d] set desc="%~2"& shift /1 & shift /1 & goto :parse_params
if [%~1]==[/du] set durl="%~2"& shift /1 & shift /1 & goto :parse_params
set infile=%~1
set intype=%~x1
shift /1 & goto :parse_params
:parse_complete
if [%infile%]==[] goto :usage

if not [%desc%]==[] (
    set osslsigncode=%osslsigncode% -n %desc%
    set signtool=%signtool% /d %desc%
)
if not [%durl%]==[] (
    set osslsigncode=%osslsigncode% -i %durl%
    set signtool=%signtool% /du %durl%
)

if [%intype%]==[.msi] goto :msi_sign

%osslsigncode% -h sha1 -t http://timestamp.comodoca.com -in "%infile%" -out "%tmpfile%" > nul
if errorlevel 1 %osslsigncode% -h sha1 -t http://timestamp.globalsign.com/scripts/timestamp.dll -in "%infile%" -out "%tmpfile%" > nul
if errorlevel 1 exit /b 1
%osslsigncode% -nest -h sha2 -ts http://timestamp.comodoca.com -in "%tmpfile%" -out "%infile%" > nul
if errorlevel 1 %osslsigncode% -nest -h sha2 -ts http://timestamp.globalsign.com/?signature=sha2 -in "%tmpfile%" -out "%infile%" > nul
if errorlevel 1 exit /b 1
goto :cleanup

:msi_sign
::%signtool% /t "http://timestamp.comodoca.com" "%infile%"
::if errorlevel 1 %signtool% /t "http://timestamp.globalsign.com/scripts/timestamp.dll" "%infile%"
%osslsigncode% -h sha1 -t http://timestamp.comodoca.com -add-msi-dse -in "%infile%" -out "%tmpfile%" > nul
if errorlevel 1 %osslsigncode% -h sha1 -t http://timestamp.globalsign.com/scripts/timestamp.dll -add-msi-dse -in "%infile%" -out "%tmpfile%" > nul
if errorlevel 1 exit /b 1
copy "%tmpfile%" "%infile%" /y > nul

:cleanup
del "%tmpfile%" /q
goto :eof

:usage
echo usage: %~nx0 [options] ^<infile^>
echo.
echo where options:
echo     /d  ^<desc^>    Optional file description
echo     /du ^<url^>     Optional company URL
echo.
goto :eof

您需要 PFX 格式的商业代码签名证书。您可以根据自己的需要调整此批次,或者仅将其用作实现的灵感。