TLS certificate fails to load when the process has no user profile (e.g. IIS app pool)
Describe the bug
GarnetServer on Windows can't load its TLS certificate when the account has no loaded user profile. CertificateUtils imports the key with the default storage flags (LoadPkcs12 after the PEM re-export, LoadPkcs12FromFile for a PFX). The default puts the key into the user key store, and without a profile there is none.
fail: Options[0] Unable to fetch certificate using the provided filename and password ...
CryptographicException: The system cannot find the file specified.
at X509CertificateLoader.ImportPfx(...)
at Garnet.server.TLS.CertificateUtils.GetCertificateFromPemFile(String certFileName, String keyFileName) line 90
warn: GarnetServer[0] ... AuthenticationException: The server mode SSL must use a certificate with the associated private key.
Steps to reproduce the bug
- IIS app pool with ApplicationPoolIdentity and
loadUserProfile=false. - A process in that pool starts GarnetServer with TLS and a PEM pair (
--tls --cert-file-name server-cert.pem --cert-password server-key.pem). - Connect a TLS client: the handshake fails, Garnet logs the errors above.
Expected behavior
Garnet loads the certificate and accepts TLS connections without a loaded user profile.
Screenshots
No response
Release version
v2.2.5
IDE
No response
OS version
Windows Server 2019 (17763), .NET 10.0.11
Additional context
I checked it under the same pool account with the same PEM pair and a server-side SslStream handshake, TLS 1.2:
- default,
UserKeySet,EphemeralKeySet: import fails (0x80070002) CreateFromPemFilewithout the re-import: loads, but the handshake fails ("No credentials are available in the security package")MachineKeySet: works
With loadUserProfile=true all of them work. Could Garnet fall back to X509KeyStorageFlags.MachineKeySet when the default import fails, or make the flags configurable? Loading the profile fixes it too, but that's a host setting we can't require on every installation.
I am working on this with the existing default certificate-loading behavior preserved wherever it succeeds. I will cover both PEM and PFX paths, distinguish the missing-key-store failure from invalid certificate/password errors, and validate certificate loading plus TLS handshakes on Windows. Please flag any parallel implementation or preferred configuration approach.