I don't think you're able to import certificates into another user's personal store. I would recommend adding it to the machine's store and giving the service user access to the certificates/keys there. You might also try logging on/runas the service user and adding it that way but I've never tried that.
Edit: I have confirmed this after testing, although I am not sure if this is the expected behavior due to poor documentation of certutil. certutil.exe -store -service (StoreName) seems to be the proper syntax to access the certificates under a service store. The service store is located at HKLM\SOFTWARE\Microsoft\Cryptography\Services\(ServiceName)\ in the registry, but certutil inserts the current user's SID instead of the service name when searching like this: HKLM\Software\Microsoft\Cryptography\Services\(SID)\SystemCertificates\, making the search fail. You can override the SID with the -sid parameter, but it doesn't seem to work if you provide the service name. If you look up the service SID with sc.exe showsid (ServiceName) and plug that in, it says "The user name or password is incorrect." It seems that certutil only supports a couple of well-known SIDs (I even tried converting the service SID to its numeric form). If you'd like to replicate my work, you'll need to bust out Procmon.
So, having found that, I am going to assume you can only import certificates if you run certutil under the context of the service. It seems the easiest way to solve your issue would be to either
- manually edit the registry
- store the certificates in the machine store, and give the service permissions to them
- store the certificates in the user store of the user that the service runs as
This is about service stores (not service users' stores) which mmc can look at but certutil apparently cannot.
– Andrew J. Brehm Jul 08 '21 at 15:05-rflag which allows you to interact with a service, but that may not work since I think psexec runs as its own service. You could also potentially try something in PowerShell like this:New-PSDrive MySvcCert -PSProvider Certificate -Root '(ServiceName)\My'thencd MySvcCert:but I've never done that. – flashbang Jul 12 '21 at 16:35S-1-5-20SID. Didn't feel like checking the others, but I'd assume it would be similar. The other two it claims to support are 22 and 23 for Local System/Local Service. – flashbang Jul 13 '21 at 15:47[system.security.cryptography.x509certificates.storelocation], which only has values forCurrentUserandLocalMachine. https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.storelocation – LeeM Mar 16 '23 at 05:28Certutilas abandonware and isn't fixing the bug or providing a PS alternative, I get around it like this: install the required cert to the LocalMachine store, grant LocalService Read perms, and copy the cert into the Service store location in the registry. To check cert validity and so on, my scripts read the details out of the LocalMachine copy. Another annoyance is that I haven't figured out how to create the Service store the first time without using the Certificates MMC. – LeeM Mar 16 '23 at 05:34