자체 서명 된 인증서를 사용하여 .ps1
에 서명하려고합니다. 사용 사례는 개인용 개발 스테이션에서 직접 작성하는 스크립트 용이므로 사용하지 마십시오. 실제 CA를 사용하거나 지불해야합니다. ). 그러나 내가 읽은 인증서 생성 및 디지털 서명에 관한 많은 가이드가 있더라도 문제없이 작동 할 수는 없습니다.자체 서명 된 인증서 (및 makecert.exe 제외)를 사용하여 PowerShell 스크립트에 서명
는 여기에 지금까지 수행 한 작업은 다음과 같습니다
# Create a certificate to use as trusted root of the signing chain
$root = New-SelfSignedCertificate `
-Subject "CN=PowerShell Trusted Authority" `
-FriendlyName "PowerShell Trusted Authority" `
-KeyUsageProperty Sign `
-KeyUsage CertSign, CRLSign, DigitalSignature `
-CertStoreLocation Cert:\LocalMachine\My\ `
-NotAfter (Get-Date).AddYears(10)
# Create a certificate to use for signing powershell scripts
New-SelfSignedCertificate `
-Signer $root `
-Subject "CN=PowerShell Code Signing" `
-KeyAlgorithm RSA `
-KeyLength 2048 `
-Type CodeSigningCert `
-CertStoreLocation Cert:\LocalMachine\My\
# Move the root cert into Trusted Root CAs
Move-Item "Cert:\LocalMachine\My\$($root.Thumbprint)" Cert:\LocalMachine\Root
관리 PowerShell을 인스턴스에서 수행 위의 모든합니다. 이 작업이 끝나면 예상되는 위치에서 관리 콘솔의 두 인증서를 모두 볼 수 있으며 서명 인증서의 인증서 경로는 유효한 것으로 확인됩니다.
나는 다음 일반 PS 프롬프트를 열고 스크립트를 로그인을 시도 : 당신이 볼 수 있듯이
# Obtain a reference to the signing certificate
PS> $cert = Get-ChildItem Cert:\LocalMachine\My\ -CodeSigningCert
# Attempt at signing
PS> Set-AuthenticodeSignature .\Microsoft.PowerShell_profile.ps1 $cert
Directory: C:\Users\tomas\Documents\WindowsPowerShell
SignerCertificate Status Path
----------------- ------ ----
UnknownError Microsoft.PowerShell_profile.ps1
은 실제 서명이 실패합니다. PowerShell 파일을 보면 스크립트에 서명이 추가되지 않은 것을 볼 수 있습니다.
관리자 프롬프트에서 서명하는 경우 조금 더 많은 것으로 보입니다. 서명 블록이 스크립트에 추가되고 서명 인증서의 지문이 Set-AuthenticodeSignature
의 출력에 인쇄되지만 상태는 여전히 UnknownError
이고 AllSigned
정책의 실행은 여전히 허용되지 않습니다.
# Output some info about the certificate:
PS> $cert | Format-List
Subject : CN=PowerShell Code Signing
Issuer : CN=PowerShell Trusted Authority
Thumbprint : <omitted>
FriendlyName :
NotBefore : 9/20/2017 10:48:59 PM
NotAfter : 9/20/2018 11:08:59 PM
Extensions : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid,
System.Security.Cryptography.Oid, System.Security.Cryptography.Oid}
나는하지만 항상 같은 상태 메시지 (UnknownError
)와, 특히 코드 서명에 대한 인증서를 생성하기 위해, New-SelfSignedCertificate
주술의 변종의 다수를 시도했습니다.
내 궁극적 인 목표는 Set-ExecutionPolicy AllSigned
일 수 있고 내가 직접 만든 스크립트를 실행할 수있게하는 것입니다. 그 일을하기 위해이 과정에서 내가 누락 된 것은 무엇입니까?
흥미 롭습니다. 오류에 대한 자세한 내용은 무엇입니까? –
@Bill_Stewart : 불행히도, 아니. 이 실패 후에'$ Error' 변수는 비어 있습니다. 왜 실패했는지를 보여주는 다른 출력은 어디에도 없습니다. 모든 문제 해결 제안은 매우 환영합니다 :) –
해당 출력의 'Status' 속성은 어떤 유형입니까? –