powershell - Signtool allows me to sign code but Set-AuthenticodeSignature says the "certificate is not suitable for code signing" -


i have self signed code signing certificate (made directions this answer) , works fine when when use signtool.exe. if try sign using powershell, fails.

signing signtool

c:\>signtool sign /v /n "vetweb" setuprdppermissions.ps1 following certificate selected:     issued to: vetweb     issued by: vetweb ca     expires:   sat dec 31 18:59:59 2039     sha1 hash: 84136ebf8d2603c2cd6668c955f920c6c6482ee4  done adding additional store signed: setuprdppermissions.ps1  number of files signed: 1 number of warnings: 0 

signing in powershell

ps c:\> $cert = @(get-childitem cert:\currentuser\my | where-object -filterscript {$_.subject -eq 'cn=vetweb'})[0] ps c:\> set-authenticodesignature setuprdppermissions.ps1 $cert set-authenticodesignature : cannot sign code. specified certificate not suitable code signing. @ line:1 char:26 + set-authenticodesignature <<<<  setuprdppermissions.ps1 $cert     + categoryinfo          : invalidargument: (:) [set-authenticodesignature], psargumentexception     + fullyqualifiederrorid : argument,microsoft.powershell.commands.setauthenticodesignaturecommand  ps c:\> $cert | format-list *   pspath             : microsoft.powershell.security\certificate::currentuser\my\84136ebf8d2603c2cd6668c955f920c6c6482ee4 psparentpath       : microsoft.powershell.security\certificate::currentuser\my pschildname        : 84136ebf8d2603c2cd6668c955f920c6c6482ee4 psdrive            : cert psprovider         : microsoft.powershell.security\certificate psiscontainer      : false archived           : false extensions         : {system.security.cryptography.oid} friendlyname       : issuername         : system.security.cryptography.x509certificates.x500distinguishedname notafter           : 12/31/2039 5:59:59 pm notbefore          : 6/1/2012 1:49:31 pm hasprivatekey      : true privatekey         : system.security.cryptography.rsacryptoserviceprovider publickey          : system.security.cryptography.x509certificates.publickey rawdata            : {48, 130, 1, 235...} serialnumber       : cf330347f35ac0b4427affa82db51238 subjectname        : system.security.cryptography.x509certificates.x500distinguishedname signaturealgorithm : system.security.cryptography.oid thumbprint         : 84136ebf8d2603c2cd6668c955f920c6c6482ee4 version            : 3 handle             : 479608336 issuer             : cn=vetweb ca subject            : cn=vetweb 

why can sign using signtool.exe, not powershell?


p.s. running get-childitem cert:\currentuser\my -codesigningcert returns no results.

i had same problem , answer figured out had create 2 certificates. first, trusted root certificate authority using

makecert -n "cn=powershell local certificate root" -a sha1 -eku 1.3.6.1.5.5.7.3.3 -r -sv root.pvk root.cer -ss root -sr localmachine 

and personal certificate above certificate authority using

makecert -pe -n "cn=powershell user" -ss -a sha1 -eku 1.3.6.1.5.5.7.3.3 -iv root.pvk -ic root.cer 

once these created, use

$cert = @(get-childitem cert:\currentuser\my -codesigning)[0] 

for signing (assuming have 1 codesigning certificate). example, if script's name xyz.ps1, use command in powershell

set-authenticodesignature path/to/xyz.ps1 $cert 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -