2

I am using a classic advapi32 based ImpersonateValidUser code.

I use the user's credentials to submit a request to the CA using CertEnrollLib. I initiate the request from the private key by building a CX509PrivateKey.

If the user has the profile (the user's folder under C:\users) then this code works fine; if the user does not have a profile, the code fails with

System.IO.FileNotFoundException: CertEnroll::CX509PrivateKey::Create: The system  cannot find the file specified. 0x80070002 (WIN32: 2)

I looked into loading user profile but it seems to fail for me 'invalid handle' errors.

Any suggestions?

zaitsman
  • 8,984
  • 6
  • 47
  • 79
  • Related posts - For on-premise deployement : [CryptographicException was unhandled: System cannot find the specified file](https://stackoverflow.com/q/17840825/465053). For Azure deployment : [Certenroll on Azure - Generating self signed certificates](https://stackoverflow.com/q/58800004/465053) – RBT Nov 21 '21 at 08:05
  • It's amazing that you replied to this old question :) unfortunately this was specifically and only happening where user was impersonated, so IIS workarounds did not work and this was an on-prem windows deployment. – zaitsman Nov 22 '21 at 01:04
  • And the azure question you linked is basically the same as IIS - tell the system to load user profile. – zaitsman Nov 22 '21 at 01:05

0 Answers0