Skip to content

Commit a93d1a5

Browse files
authored
Add logging for pkcs11 initialize (#33)
Add warnings and debug logging to troubleshoot pkcs11 initialize function. Signed-off-by: David Enyeart <[email protected]>
1 parent 2d80476 commit a93d1a5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

bccsp/pkcs11/pkcs11.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (csp *Provider) initialize(opts PKCS11Opts) (*Provider, error) {
138138
return nil, fmt.Errorf("pkcs11: instantiation failed for %s", opts.Library)
139139
}
140140
if err := ctx.Initialize(); err != nil {
141-
logger.Debugf("initialize failed: %v", err)
141+
logger.Warnf("initialize failed: %v", err)
142142
}
143143

144144
slots, err := ctx.GetSlotList(true)
@@ -147,9 +147,15 @@ func (csp *Provider) initialize(opts PKCS11Opts) (*Provider, error) {
147147
}
148148
for _, s := range slots {
149149
info, err := ctx.GetTokenInfo(s)
150-
if err != nil || opts.Label != info.Label {
150+
if err != nil {
151+
logger.Warnf("Failed to get TokenInfo for slot %d: %v", s, err)
152+
continue
153+
}
154+
if opts.Label != info.Label {
155+
logger.Warnw("PKCS11 labels did not match", "slot", s, "configLabel", opts.Label, "tokenLabel", info.Label)
151156
continue
152157
}
158+
logger.Debugw("Found a matching PKCS11 label to use", "slot", s, "label", info.Label, "pin", opts.Pin)
153159

154160
csp.slot = s
155161
csp.ctx = ctx

0 commit comments

Comments
 (0)