Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
983 views
in Technique[技术] by (71.8m points)

certificate - keyset does not exist when the private key clearly exists

We have a service that will generate a CA cert and use that CA cert to sign all other required certs on startup.

The CA cert has an associated private key and is stored in the windows certificate store with Exportable flag. This works fine on most machines but on one of our QA's machine we run into some nasty issues.

When I load the CA cert from the cert store in code and checked HasPrivateKey flag it returns true. Then when I attempt to use the CA cert to sign another cert. It throws keyset does not exist exception.

In the certificate store it says the certificate is valid. On the general page it says

You have a private key that corresponds to this certificate

Good sign! But when we try to right click -> Task -> Export it. The include private key button is grayed out and says

The associated private key cannot be found. Only the certificate can be exported

We thought its a permission issue so we run mmc in admin mode and still the same result.

On my dev machine I noticed that the private key file is stored in %APPDATA%MicrosoftCryptoKeys but its not the case for our QA's machine. We cannot find the private key file in the same folder with the timestamp = CA cert generated time. We also looked into

%ALLUSERSPROFILE%Application DataMicrosoftCryptoSystemKeys
%WINDIR%ServiceProfilesLocalService
%ALLUSERSPROFILE%Application DataMicrosoftCryptoKeys

but no luck still.

The account used to run the service is Local System so permission shouldnt be an issue here. No special anti-virus installed other than Windows Defender and nothing in Defender's history either.

question from:https://stackoverflow.com/questions/65888910/keyset-does-not-exist-when-the-private-key-clearly-exists

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...