この問題を自分で調べているうちに、自己署名PowerShellスクリプトで解決策を見つけることができませんでした。だから、AllSigned
実行ポリシーを利用してシステムをより良く保護するために、PowerShell自体の中にすべて自己完結型で対応していますか?自己署名PowerShellスクリプトの作成が完了するまで
1
A
答えて
1
これは、自己署名PowerShellスクリプトの現代的なアプローチです。旧バージョンのPowerShell ISE(確認済み2.0のみ)がBig EndianとUTF-8のスクリプトをエンコードし、署名に問題が発生することが判明しました。この方法では、ここではv4 +を使用しているので、これに慣れるべきではありません。
要件:PoSH 4.0+。
この機能は、Pfx証明書が存在するかどうかをチェックし、それをLocalMachine\TrustedPublisher
にインポートします。証明書が渡されたかどうかを確認し、Pfx証明書にエクスポートしてインポートします。証明書をLocalMachine\Personal
に作成し、エクスポートしてインポートします。 \My
(Personal)以外のCert:\CurrentUser
ストアを使用する権限を私に与えることができませんでした。すべてが言わおよび実行された後
$ErrorActionPreference = 'Stop'
Function New-SelfSignedCertificate
{
Param([Parameter(Mandatory=$True)]$PfxCertPath,$CertObj)
# Creates a SecureString object
$Cred = (Get-Credential).Password
If (Test-Path $PfxCertPath)
{
Try {
Import-PfxCertificate -FilePath $PfxCertPath -Password $Cred -CertStoreLocation Cert:\LocalMachine\TrustedPublisher
Write "$($PfxCertPath.FriendlyName) exists and is valid. Imported certificate to TrustedPublishers"
} Catch {
Write "Type mismatch or improper permission. Ensure your PFX cert is formed properly."
Write "[$($_.Exception.GetType().FullName)] $($_.Exception.Message)"
}
} ElseIf ($CertObj) {
Try {
Export-PfxCertificate -Cert $CertObj -FilePath $PfxCertPath -Password $Cred -Force
Import-PfxCertificate -FilePath $PfxCertPath -Password $Cred -CertStoreLocation Cert:\LocalMachine\TrustedPublisher
} Catch {
Write "[$($_.Exception.GetType().FullName)] $($_.Exception.Message)"
}
} Else {
Try {
$DNS = "$((GWMI Win32_ComputerSystem).DNSHostName).$((GWMI Win32_ComputerSystem).Domain)"
$CertObj = New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName $DNS -Type CodeSigningCert -FriendlyName 'Self-Sign'
Export-PfxCertificate -Cert $CertObj -FilePath $PfxCertPath -Password $Cred -Force
Import-PfxCertificate -FilePath $PfxCertPath -Password $Cred -CertStoreLocation Cert:\LocalMachine\TrustedPublisher
} Catch {
Write "[$($_.Exception.GetType().FullName)] $($_.Exception.Message)"
}
}
}
# Can be called like:
# Sign-Script -File C:\Script.ps1 -Certificate (GCI Cert:\LocalMachine\TrustedPublisher -CodeSigningCert)
#
# After the cert is imported to TrustedPublisher, you can use the
# exported pfx cert to sign on the machine instead of this method
Function Sign-Script
{
Param($File,$Cert)
If($Cert-is[String]){Try{$Cert=Get-PfxCertificate("$Cert")}Catch{}}
Set-AuthenticodeSignature -FilePath $File -Certificate $Cert -Force
}
Function Check-SignedScript
{
Param($File)
Get-AuthenticodeSignature -FilePath $File
}
、あなたは管理者としてSet-ExecutionPolicy AllSigned
を実行し、すべてのスクリプトを署名するこのスクリプトを使用することができます。 Check-SignedScript
は、標識が有効かどうかを教えてくれるので、ファイルとしてSign-Script
が働いているかどうかを確認するには、最後に# SIG # Begin signature block
があるはずです。実行するためには、署名されたスクリプトの編集をすべて再署名する必要があります。
関連する問題
- 1. は、自己署名証明書の作成 - PowerShellの
- 2. 自己完了コードが
- 3. 自己署名証明書を使用してPowerShellスクリプトに署名する(とmakecert.exeを使用しない)
- 4. 自己署名証明書のセキュリティ例外を作成する
- 5. PowerShell新しい自己署名証明書のIPアドレス
- 6. 自己署名J2MEアプリケーション
- 7. 自己署名証明書
- 8. Docusign API - 自己署名
- 9. Consul Check HTTPS自己署名
- 10. openssl自己署名証明書ファイルからJavaキーストアを作成
- 11. 自己署名証明書を生成し、それを使ってPowerShellスクリプトに署名するにはどうすればよいですか?
- 12. ウィンドウ上で開いたsslで自己署名証明書を作成する
- 13. WCFサービス用にプログラムで自己署名証明書を作成する方法
- 14. ウィンドウ上のlocalhostの自己署名証明書を作成する
- 15. APKの署名の自己チェック
- 16. Javaの自己署名証明書 - 署名XMLファイル
- 17. httpsの自己署名証明書
- 18. PrincipalContext LDAPS自己署名証明書の
- 19. 自己署名入りの証明書
- 20. 新自己署名証明書コマンドレットによってコード署名証明書を作成する方法
- 21. ドッカーで自己署名証明書を生成
- 22. makecertを使用して自己署名証明書を作成する方法
- 23. pyopensslを使用して自己署名入り証明書を作成する
- 24. 自己署名証明書とHTTPSエラー
- 25. ssl自己署名証明書エラー - localhost
- 26. Keystone.js自己署名証明書
- 27. AdminClient自己署名証明書
- 28. 無効な自己署名証明書
- 29. Tomcatと自己署名証明書
- 30. 自己署名証明書発行