Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to iterate over cetificates in store #72

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions certtostore_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ import (
"unsafe"

"github.com/google/deck"
"golang.org/x/crypto/cryptobyte/asn1"
"github.com/hashicorp/go-multierror"
"golang.org/x/crypto/cryptobyte"
"golang.org/x/crypto/cryptobyte/asn1"
"golang.org/x/sys/windows"
"github.com/hashicorp/go-multierror"
)

// WinCertStorage provides windows-specific additions to the CertStorage interface.
Expand Down Expand Up @@ -438,8 +438,8 @@ func (w *WinCertStore) Cert() (*x509.Certificate, error) {
// such as looking up the private key with CertKey().
//
// You must call FreeCertContext on the context after use.
func (w *WinCertStore) CertWithContext() (*x509.Certificate, *windows.CertContext, error) {
c, ctx, err := w.cert(w.issuers, my, w.storeDomain())
func (w *WinCertStore) CertWithContext(prev ...*windows.CertContext) (*x509.Certificate, *windows.CertContext, error) {
c, ctx, err := w.cert(w.issuers, my, w.storeDomain(), prev...)
if err != nil {
return nil, nil, err
}
Expand All @@ -455,13 +455,18 @@ func (w *WinCertStore) CertWithContext() (*x509.Certificate, *windows.CertContex

// cert is a helper function to lookup certificates based on a known issuer.
// store is used to specify which store to perform the lookup in (system or user).
func (w *WinCertStore) cert(issuers []string, searchRoot *uint16, store uint32) (*x509.Certificate, *windows.CertContext, error) {
func (w *WinCertStore) cert(issuers []string, searchRoot *uint16, store uint32, prevCtx ...*windows.CertContext) (*x509.Certificate, *windows.CertContext, error) {
h, err := w.storeHandle(store, searchRoot)
if err != nil {
return nil, nil, err
}

var prev *windows.CertContext

if len(prevCtx) == 1 {
prev = prevCtx[0]
}

var cert *x509.Certificate
for _, issuer := range issuers {
i, err := windows.UTF16PtrFromString(issuer)
Expand Down
Loading