@@ -9,6 +9,7 @@ SPDX-License-Identifier: Apache-2.0
99package pkcs11
1010
1111import (
12+ "fmt"
1213 "os"
1314
1415 "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
@@ -24,15 +25,27 @@ const (
2425)
2526
2627type (
27- PKCS11Opts = pkcs11.PKCS11Opts
28+ // PKCS11Opts is a defined type (not an alias) over the fabric-lib PKCS11
29+ // options so it can carry a redacting String().
30+ PKCS11Opts pkcs11.PKCS11Opts
2831 KeyIDMapping = pkcs11.KeyIDMapping
2932)
3033
34+ // String renders the PKCS11 With redacted Pin,
35+ // So interpolated (with %v/%s/%+v) doesn't reach a log line.
36+ func (o PKCS11Opts ) String () string {
37+ return fmt .Sprintf (
38+ "{Security:%d Hash:%s Library:%s Label:%s Pin:[REDACTED] SoftwareVerify:%t Immutable:%t AltID:%s KeyIDs:%v SessionCacheSize:%d}" ,
39+ o .Security , o .Hash , o .Library , o .Label , o .SoftwareVerify , o .Immutable , o .AltID , o .KeyIDs , o .SessionCacheSize ,
40+ )
41+ }
42+
3143// NewProvider returns a pkcs11 provider
3244func NewProvider (opts PKCS11Opts , ks bccsp.KeyStore , mapper func (ski []byte ) []byte ) (* pkcs11.Provider , error ) {
33- csp , err := pkcs11 .New (opts , ks , pkcs11 .WithKeyMapper (mapper ))
45+ csp , err := pkcs11 .New (pkcs11 . PKCS11Opts ( opts ) , ks , pkcs11 .WithKeyMapper (mapper ))
3446 if err != nil {
35- return nil , errors .WithMessagef (err , "Failed initializing PKCS11 library with config [%+v]" , opts )
47+ // opts.String() redacts the PIN, so the secret never reaches the error string.
48+ return nil , errors .WithMessagef (err , "Failed initializing PKCS11 library with config [%v]" , opts )
3649 }
3750 return csp , nil
3851}
0 commit comments