2016-03-27 12 views
0

Ben bir sertifika oluşturulur ve geçerli olduğunu: Ps-script'imi daha önce boş bırakmadan nasıl imzalayabilirim?

Thumbprint      Subject 
----------      ------- 
0562....................4944E CN=Callis PowerShell 

Şimdi benim komut LoadAndParse.ps1 imzalamak istiyorum. Denersem
Ama :

PS C:\...\X> $cert = @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0] 
PS C:\...\X> Set-AuthenticodeSignature LoadAndParse.ps1 $cert 
Directory: C:\...\ 
SignerCertificate    Status   Path 
-----------------    ------   ---- 
            UnknownError LoadAndParse.ps1 

Biraz tek komut ekleyerek siparişlerin benim dizisini değiştirirseniz ve bunu imzalamış olsun - ama şimdi boş :(

PS C:\...\X> echo get-location > LoadAndParse.ps1 
    PS C:\...\X> $cert = @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0] 
    PS C:\...\X> Set-AuthenticodeSignature LoadAndParse.ps1 $cert 

    Directory: C:\...\X 

    SignerCertificate    Status  Path 
    -----------------    ------  ---- 
    056260.............E24944E Valid  LoadAndParse.ps1 

Şimdi komut vardır sadece anahtar blok - iyi bir senaryo sabitlemek için şaşırtıcı bir yöntemdir !!

kod ellenmezse çünkü bir şey yapmak mümkün bir script imzalamak nasıl peşin
sayesinde, 0? Gooly

cevap

0

Çözüm var. PS-ISE, Set-AuthenticodeSignature'ın anlamadığı Unicode Big Endian'a kaydeder. Komut dosyasını UTF-8'e kaydetmek için Notepad ++ kullanın ve sorun yok.

Hata ipucu doğru yönde işaret ederse veya Powershell kendi kodu olduğunu anlarsa - birkaç saat beni kurtarırdı! İşte

bu tuzağa hatırlatır benim senaryom:

<# 
    .SYNOPSIS 
    check whether the file is in UTF8 and sign it - otherwise give hint what to do 
    but this file has to be signed too eventually 
    #> 
    [CmdletBinding()] Param (
     [Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] [string]$Path, 
     [Parameter(Mandatory = $False, ValueFromPipelineByPropertyName = $True)] [int]$Idx=0 
) 

    function isUTF8 ([string]$Path, [int]$Idx) 
    { 
     [byte[]]$byte = get-content -Encoding byte -ReadCount 4 -TotalCount 4 -Path $Path 

     if ($byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf) { 
     Write-Output "$Path`r`nis UTF8, going to sign it using cert. index: $Idx" 
     sign $Path $Idx 
     } else { 
     [console]::beep(500,600) 
     Write-Output "$Path is NOT UTF8!`r`nLoad it in Notepad++ and save it in UTF8 - otherwise it can't be signed" 
     } 
    } 


    function sign ([string]$Path, [int]$Idx) { 
    $cert = @(gci cert:\currentuser\my -codesigning)[$Idx] 
    Set-AuthenticodeSignature $Path $cert 
    } 

    isUTF8 $Path $Idx 
Bir MS-komut :(

çalıştırmak için olmayan bir MS-produt kullanmayı hayal bile edemediğini

İlgili konular