Delete CNG private keys when CleanupCredentials removes expired certs#1030
Open
darkfronza wants to merge 1 commit into
Open
Delete CNG private keys when CleanupCredentials removes expired certs#1030darkfronza wants to merge 1 commit into
darkfronza wants to merge 1 commit into
Conversation
CleanupCredentials previously deleted the certificate from the Windows store but left the paired CNG private key in the provider, accumulating orphan .PCPKSP blobs on disk as certificates were renewed. - Add a `delete-key` URI flag on CAPIKMS.DeleteCertificate. When set, the cert's CNG key is removed via nCryptDeleteKey before the cert context is deleted, so a partial failure leaves the cert in place for retry rather than orphaning the key. - Rewrite CAPIKMS.CleanupCredentials to walk the store directly and delete each expired cert together with its CNG key. Enumeration is restarted after every delete because CertDeleteCertificateFromStore frees the context the next find call would chain from. - TPMKMS.deleteCertificateFromWindowsCertificateStore now sets delete-key=true on its URI, since TPMKMS-managed certs have a 1:1 CNG key with no independent use. - Update TestKMS_CleanupCredentials_capi to assert that both the certificate and the CNG private key are removed. EFF-232 Change-Type: feature Release-Note: yes Audience: developer Impact: low Breaking: false Co-Authored-By: Claude <noreply@anthropic.com>
maraino
reviewed
May 18, 2026
Contributor
maraino
left a comment
There was a problem hiding this comment.
Capi already supports the DeleteKey method, why don't use just that in TPMKMS?
Contributor
Author
|
@maraino I think that the interface for the method is less clear in that internal context for deleting the certificate and associated key, so using |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CleanupCredentials previously deleted the certificate from the Windows store but left the paired CNG private key in the provider, accumulating orphan .PCPKSP blobs on disk as certificates were renewed.
delete-keyURI flag on CAPIKMS.DeleteCertificate. When set, the cert's CNG key is removed via nCryptDeleteKey before the cert context is deleted, so a partial failure leaves the cert in place for retry rather than orphaning the key.EFF-232
Change-Type: feature
Release-Note: yes
Audience: developer
Impact: low
Breaking: false