Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This was happening to me too - my setup script would add the cert and grant access to the PK file fine, and the app would work. Then later, after I had closed the PowerShell editor I re-launched the app and it failed with a keyset not found. </p> <p>Adding the PersistKeySet flag when importing the cert fixed the problem. Here's the PowerShell code for adding the cert and private key with persistence:</p> <pre><code>param( [string]$certStore = "LocalMachine\TrustedPeople", [string]$filename = "sp.pfx", [string]$password = "password", [string]$username = "$Env:COMPUTERNAME\WebSiteUser" ) function getKeyFilePath($cert) { return "$ENV:ProgramData\Microsoft\Crypto\RSA\MachineKeys\" + $cert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName } $certFromFile = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($filename, $password) $certFromStore = Get-ChildItem "Cert:\$certStore" | Where-Object {$_.Thumbprint -eq $certFromFile.Thumbprint} $certExistsInStore = $certFromStore.Count -gt 0 $keyExists = $certExistsInStore -and ($certFromStore.PrivateKey -ne $null) -and (Test-Path(getKeyFilePath($certFromStore))) if ((!$certExistsInStore) -or (!$keyExists)) { $keyFlags = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet $keyFlags = $keyFlags -bor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet $certFromFile.Import($filename, $password, $keyFlags) $store = Get-Item "Cert:\$certStore" $store.Open("ReadWrite") if ($certExistsInStore) { #Cert is in the store, but we have no persisted private key #Remove it so we can add the one we just imported with the key file $store.Remove($certFromStore) } $store.Add($certFromFile) $store.Close() $certFromStore = $certFromFile "Installed x509 certificate" } $pkFile = Get-Item(getKeyFilePath($certFromStore)) $pkAcl = $pkFile.GetAccessControl("Access") $readPermission = $username,"Read","Allow" $readAccessRule = new-object System.Security.AccessControl.FileSystemAccessRule $readPermission $pkAcl.AddAccessRule($readAccessRule) Set-Acl $pkFile.FullName $pkAcl "Granted read permission on private key to web user" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload