From b0cde7f15680f946f2c43b09f720e99699dbaadc Mon Sep 17 00:00:00 2001 From: CertoToStore Team Date: Sun, 23 Nov 2025 19:18:22 -0800 Subject: [PATCH] Add support for removing certificates on Windows via subject and serial (aka CertInfo struct), via new method RemoveByCertInfo(). PiperOrigin-RevId: 836021983 --- certtostore_windows.go | 75 ++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/certtostore_windows.go b/certtostore_windows.go index d82e893..7a23720 100644 --- a/certtostore_windows.go +++ b/certtostore_windows.go @@ -42,8 +42,8 @@ import ( "unsafe" "github.com/google/deck" - "golang.org/x/crypto/cryptobyte" "golang.org/x/crypto/cryptobyte/asn1" + "golang.org/x/crypto/cryptobyte" "golang.org/x/sys/windows" ) @@ -52,9 +52,11 @@ type WinCertStorage interface { CertStorage // Remove removes certificates issued by any of w.issuers from the user and/or system cert stores. - // If it is unable to remove any certificates, it returns an error. Remove(removeSystem bool) error + // RemoveByCertInfo removes certificate(s) with the given subject and serial number from the user and/or system cert stores. + RemoveByCertInfo(certinfo *windows.CertInfo, removeSystem bool) error + // Link will associate the certificate installed in the system store to the user store. Link() error @@ -98,8 +100,10 @@ const ( certStoreLocalMachineID = 2 // CERT_SYSTEM_STORE_LOCAL_MACHINE_ID infoIssuerFlag = 4 // CERT_INFO_ISSUER_FLAG compareNameStrW = 8 // CERT_COMPARE_NAME_STR_A + compareSubjectCert = 11 // CERT_COMPARE_SUBJECT_CERT compareShift = 16 // CERT_COMPARE_SHIFT findIssuerStr = compareNameStrW<