根据
this guide我尝试创建用于签署PowerShell脚本的证书:
CD C:\OpenSSL-Win32\bin REM Create the key for the Certificate Authority. 2048 is the bit encryptiong,you can set it whatever you want openssl genrsa -out C:\Test\ca.key 2048 openssl req -config C:\OpenSSL-Win32\bin\openssl.cfg -new -x509 -days 1826 -key C:\Test\ca.key -out C:\Test\ca.crt REM Now I'm creating the private key that will be for the actual code signing cert openssl genrsa -out C:\Test\codesign.key 2048 openssl req -config C:\OpenSSL-Win32\bin\openssl.cfg -new -key C:\Test\codesign.key -reqexts v3_req -out C:\Test\codesign.csr openssl x509 -req -days 1826 -in C:\Test\codesign.csr -CA C:\Test\ca.crt -CAkey C:\Test\ca.key -extfile C:\OpenSSL-Win32\bin\cnf\opensslTest.cnf -set_serial 01 -out C:\Test\codesign.crt openssl pkcs12 -export -out C:\Test\codesign.pfx -inkey C:\Test\codesign.key -in C:\Test\codesign.crt
发生以下错误:
C:\OpenSSL-Win32\bin>openssl x509 -req -days 1826 -in C:\Test\codesign.csr -CA C:\Test\ca.crt -CAkey C:\Test\ca.key -extfile C:\OpenSSL-Win32\bin\cnf\openssl.cnf -set_serial 01 -out C:\Test\codesign.crt Error Loading extension section default 14516:error:22097082:X509 V3 routines:do_ext_nconf:unknown extension name:crypto\x509v3\v3_conf.c:78: 14516:error:22098080:X509 V3 routines:X509V3_EXT_nconf:error in extension:crypto\x509v3\v3_conf.c:47:name=HOME,value=.
我使用了OpenSSL v1.1.0c.我找到的每个其他指南都创建了无法用于代码签名的证书.
Windows上的OpenSSL没有必要.在Windows 7上,您可以使用我在TechNet脚本库中发布的自己的PowerShell脚本:
Self-signed certificate generator (PowerShell).用法可以是这样的:
原文链接:https://www.f2er.com/windows/367341.htmlNew-SelfsignedCertificateEx -Subject "CN=Test Code Signing" ` -EKU "Code Signing" ` -KeySpec "Signature" ` -KeyUsage "DigitalSignature" ` -FriendlyName "Test code signing" -NotAfter $([datetime]::now.AddYears(5))
(第一个例子).
从Windows 8开始,您可以使用内置的certreq.exe工具生成证书.使用证书配置创建INF文件,例如:
[NewRequest] Subject = "CN=Test Code Signing" KeyLength = 2048 KeyAlgorithm = RSA ProviderName = "Microsoft Enhanced RSA and AES Cryptographic Provider" MachineKeySet = false Exportable = true KeySpec = 2 KeyUsage = 0x80 RequestType = Cert [EnhancedKeyUsageExtension] OID=1.3.6.1.5.5.7.3.3 ; Code signing
然后运行以下命令:
Certreq –new path\inffilename.inf
从Windows 10开始,您可以使用内置PowerShell cmdlet,如下所示:
New-SelfSignedCertificate -CertStoreLocation cert:\currentuser\my ` -Subject "CN=Test Code Signing" ` -KeyAlgorithm RSA ` -KeyLength 2048 ` -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" ` -KeyExportPolicy Exportable ` -KeyUsage DigitalSignature ` -Type CodeSigningCert
但是,在生产环境中进行代码签名的自签名证书使用是dsicouraged.您应该仅在测试环境中使用它们.
对于私人使用(仅限组织内),您应检查公司是否已拥有PKI基础架构并联系相应人员以获得公司批准的代码签名证书.
对于公共脚本(您将随软件包一起分发或向客户提供脚本),我建议从全球信任的商业CA提供商处购买代码.