Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X509 Certificate Access to private Key Denied

I am importing X509 from PKCS #12 file (using PFXImportCertStore Cryptographic API) in Computer's Personal Store.

Problem:

Any process running under "Local Service" account or any non-admin account can not access privates key (restricted to Admin user by Windows).

How to give access to private keys of a certificate to non-admin users and local service?

Note:

Since multiple process use certificates, I preferred using Computers store instead user's store.

like image 482
Satbir Avatar asked Feb 02 '26 17:02

Satbir


1 Answers

This is a tricky one with some pitfalls. I had the same problem and was close to despair, when I finally found the remark which saved me in this post

I succeeded to do this for a local service running under the Network Service account.

First, there is the option to grant other users access to the private key of a certificate in the MS certificate store. Already this I'd classify as druid knowledge: this option is available in the context menu (right click the certificate), but only if the certificate resides in the localMachine\Personal store. There, in the entry All tasks, you will find the sub entry Manage Private Keys. This is not available in other stores, not even in the CurrentUser\Personal store.

This entry opens a dialog which allows you to add access rights to the certificate for other users. Here, the next hurdle waits for you: the default setting is to search for users in the domain, not on the local machine. The desired user may not be found, unless you change the search filter.

To this result I came very fast by googling, but it did not help. I could get the service to run, but only if I changed the service user to the logon account, which is not what I wanted (this leads, btw, to a workaround: create a local user account for services and import the certificate from within that user account. You can then place the certificate in almost any store and it will work fine)

This is where the post cited above comes in, the last hurdle for me: the procedure described above seems to work only if you import the certificate into the certificate store from within the MMC snapin. Select the store localMachine\Personal and use the context menu to import the certificate in question. (I chose to make the private key exportable, this may or may not be relevant here). If you import the certificate by double clicking on it in the file system, it will be imported into some store in the Current User location. I used to do this and then move it into the localMachine\Personal folder and changed the access right -- this did never work for me. Only after importing it from within localMachine\Personal in the MMC certificate snap-in it worked immediately...

(Also note that you have to place the certificate into a store which can be found by the service user. Your current user stores usually does not allow this, so localMachine is the better choice, anyway)

I don't know whether you can move the certificate around afterwards, but that's easy to check in the system..

like image 129
Thomas Avatar answered Feb 05 '26 06:02

Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!