On Tue, 24 Nov 2026 13:50:46 GMT, Weijun Wang <[email protected]> wrote:
>> Thank you for pointing that out. >> Existing entries may have a certificate in `LOCALMACHINE` but a private key >> in `CURRENTUSER`. >> Using the provider handle let us determine the key’s actual location and >> delete the correct container. > > Hmm, is this common? > > In this case, does that mean the certificate was added to two places so the > same `PrivateKeyEntry` appears in both keystores? With your current code, the > key and one cert is removed, and the other orphaned cert becomes a cert entry > next time it's loaded. > > I think there are two questions here: > > 1. Shall we always remove the key? Suppose we have cert and key in > CURRENTUSER and also cert in LOCALMACHINE. When we remove the entry in > CURRENTUSER, I'm OK we remove both. But if we remove in LOCALMACHINE, shall > we also remove the key and change the content of CURRENTUSER? > 2. When a cert becomes orphaned, how should we deal with it? I somehow think > it should not automatically becomes a cert entry. We currently use > `CryptAcquireCertificatePrivateKey` to locate its key, but before that, we > need to find a way to see if it has an associated key. I'm not sure how common this is, but I reproduced your example. I agree that deleting the LOCALMACHINE entry should leave the CURRENTUSER key alone. I've updated the deletion logic and verified that I can still sign with that key afterward. Should we look at how to load orphaned certificates in a separate issue? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/33785#discussion_r4705361068
