Skip to content

Commit

Permalink
Add logging for pkcs11 initialize
Browse files Browse the repository at this point in the history
Add warnings and debug logging to troubleshoot
pkcs11 initialize function.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed May 9, 2024
1 parent 2d80476 commit a6a9080
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bccsp/pkcs11/pkcs11.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit a6a9080

Please sign in to comment.