L o a d i n g . . .
主打一个C++
文章详情

手动生成本地代码签名证书(dll、exe、sys驱动签名)

Posted on 2022-02-24 22:30:24 by 主打一个C++

第一种:使用 PowerShell 和 SignTool 工具生成和导出自签名的代码签名证书,并使用该证书对驱动程序进行签名。

创建一个新的自签名证书,证书类型为代码签名(CodeSigning)

$cert = New-SelfSignedCertificate -Type CodeSigning -DnsName "cpp.vin" -CertStoreLocation "cert:\LocalMachine\My"
$path = "C:\cpp.vin.pfx"
$password = ConvertTo-SecureString -String "cpp.vin" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath $path -Password $password
Import-PfxCertificate -FilePath $path -CertStoreLocation "cert:\LocalMachine\AuthRoot" -Password $password 

关键参数解释:


//证书的 DNS 名称。

-DnsName "cpp.vin"

//表示证书将被存储在本地计算机的证书存储区中。

-CertStoreLocation "cert:\LocalMachine\My"

//即将导出的 PFX 格式证书的文件路径。

$path = "C:\cpp.vin.pfx"

//将一个明文字符串(密码)转换为安全字符串以确保存储的安全性,其中 "cpp.vin" 是密匙密码。

$password = ConvertTo-SecureString -String "cpp.vin" -Force -AsPlainText

//将刚刚创建的自签名证书导出为 PFX 文件,-Cert $cert 指定要导出的证书。-FilePath $path 指定导出的文件路径。-Password $password 用于保护导出的证书文件,确保只有知道密码的人才能使用该证书。

Export-PfxCertificate -Cert $cert -FilePath $path -Password $password

使用signtool对驱动进行签名测试:


/f C:\cpp.vin.pfx                      //指定要使用的 PFX 证书文件的路径。

/p cpp.vin                              //提供证书的密码。

/fd sha256                             //指定要使用的哈希算法,这里选择 SHA-256。

/d "https://cpp.vin"               //用于提供驱动程序的描述。

/du "https://cpp.vin"             //指定一个 URL,通常是指向驱动程序的主页或其他相关信息的链接。

c:/cpp.vin.sys                        //是要被签名的驱动程序文件的名称。

signtool sign /f C:\cpp.vin.pfx /p cpp.vin /fd sha256 /d "https://cpp.vin" /du "https://cpp.vin" /t http://timestamp.digicert.com c:/cpp.vin.sys
//signtool sign /f C:\cpp.vin.pfx /p cpp.vin /fd sha256 /d "https://cpp.vin" c:/cpp.vin.sys

//测试检测时间戳是否有效

signtool verify /pa /v c:/cpp.vin.sys

第二种:使用 MakeCert 生成证书并使用 signtool 进行签名

第一步:

makecert -r -pe -n "CN=tests" -a sha1 -b 01/01/2016 -e 01/01/2034 -sky codeSigning -ss root -sr currentuser

//其中参数就不多阐述,很明显...

提示如下:

image.png

console提示:Succeeded 即表示成功!

第二步:cmd输入:certmgr.msc 打开证书管理界面

image.png

image.png

image.png

image.png

image.png

image.png

image.png

//桌面得到文件:

image.png

第三步:测试对sys驱动进行签名(证书移动到了c盘)

signtool sign /f C:/tests.pfx /fd sha256 /p password /v C:/cpp.vin.sys

其中password 是导出时设置的密码。

//签名结果展示

image.png

image.png

测试完成!

*转载请注明出处:原文链接:https://cpp.vin/page/70.html

作者近期文章
  • 随手笔记
  • 主打一个C++   2025-01-11 20:02:01
  • 都2000000025年了。还有不能随意访问guthub的,仔细看。在国内其实是可以正常访问的,gfw并没屏蔽。这里给出其中一个简单直接的方法稳定访问。1. 随便百度一个”dn
提示
×
确定
数据库执行: 8次 总耗时: 0.01s
页面加载耗时: 



wechat +447752296473
wechat cpp-blog