Das Zertifikat ist bereits auf dem Computer installiert. Jetzt möchte ich dem Anwendungsbenutzer die Leseberechtigung für den privaten Schlüssel des Zertifikats erteilen.
Lösung des Problems
Die akzeptierte Antwort funktionierte für mich nicht als $_.privatekey
zurückgegebene Null. Ich habe es geschafft, Zugriff auf den privaten Schlüssel zu erhalten und meinem Anwendungspool Leseberechtigungen wie folgt zuzuweisen:
param (
[string]$certStorePath = "Cert:\LocalMachine\My",
[string]$AppPoolName,
[string]$certThumbprint
)
Import-Module WebAdministration
$certificate = Get-ChildItem $certStorePath | Where thumbprint -eq $certThumbprint
if ($certificate -eq $null)
{
$message="Certificate with thumbprint:"+$certThumbprint+" does not exist at "+$certStorePath
Write-Host $message -ForegroundColor Red
exit 1;
}else
{
$rsaCert = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($certificate)
$fileName = $rsaCert.key.UniqueName
$path = "$env:ALLUSERSPROFILE\Microsoft\Crypto\Keys\$fileName"
$permissions = Get-Acl -Path $path
$access_rule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS AppPool\$AppPoolName", 'Read', 'None', 'None', 'Allow')
$permissions.AddAccessRule($access_rule)
Set-Acl -Path $path -AclObject $permissions
}
Keine Kommentare:
Kommentar veröffentlichen