From a6a9080bdc3db1b981268f80221d8257e4419300 Mon Sep 17 00:00:00 2001 From: David Enyeart Date: Thu, 9 May 2024 12:16:23 -0400 Subject: [PATCH] Add logging for pkcs11 initialize Add warnings and debug logging to troubleshoot pkcs11 initialize function. Signed-off-by: David Enyeart --- bccsp/pkcs11/pkcs11.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bccsp/pkcs11/pkcs11.go b/bccsp/pkcs11/pkcs11.go index 61b8be4..a55f63c 100644 --- a/bccsp/pkcs11/pkcs11.go +++ b/bccsp/pkcs11/pkcs11.go @@ -138,7 +138,7 @@ func (csp *Provider) initialize(opts PKCS11Opts) (*Provider, error) { return nil, fmt.Errorf("pkcs11: instantiation failed for %s", opts.Library) } if err := ctx.Initialize(); err != nil { - logger.Debugf("initialize failed: %v", err) + logger.Warnf("initialize failed: %v", err) } slots, err := ctx.GetSlotList(true) @@ -147,9 +147,15 @@ func (csp *Provider) initialize(opts PKCS11Opts) (*Provider, error) { } for _, s := range slots { info, err := ctx.GetTokenInfo(s) - if err != nil || opts.Label != info.Label { + if err != nil { + logger.Warnf("Failed to get TokenInfo for slot %d: %v", s, err) + continue + } + if opts.Label != info.Label { + logger.Warnw("PKCS11 labels did not match", "slot", s, "configLabel", opts.Label, "tokenLabel", info.Label) continue } + logger.Debugw("Found a matching PKCS11 label to use", "slot", s, "label", info.Label, "pin", opts.Pin) csp.slot = s csp.ctx = ctx