gitee.com/hyperledger/fabric-ca@v2.0.0-alpha+incompatible/util/configurebccspnopkcs11.go (about) 1 // +build !pkcs11 2 3 /* 4 Copyright IBM Corp. All Rights Reserved. 5 6 SPDX-License-Identifier: Apache-2.0 7 */ 8 9 package util 10 11 import ( 12 "path" 13 "strings" 14 15 "github.com/cloudflare/cfssl/log" 16 "github.com/hyperledger/fabric/bccsp/factory" 17 "github.com/pkg/errors" 18 ) 19 20 // ConfigureBCCSP configures BCCSP, using 21 func ConfigureBCCSP(optsPtr **factory.FactoryOpts, mspDir, homeDir string) error { 22 var err error 23 if optsPtr == nil { 24 return errors.New("nil argument not allowed") 25 } 26 opts := *optsPtr 27 if opts == nil { 28 opts = &factory.FactoryOpts{} 29 } 30 if opts.ProviderName == "" { 31 opts.ProviderName = "SW" 32 } 33 if strings.ToUpper(opts.ProviderName) == "SW" { 34 if opts.SwOpts == nil { 35 opts.SwOpts = &factory.SwOpts{} 36 } 37 if opts.SwOpts.HashFamily == "" { 38 opts.SwOpts.HashFamily = "SHA2" 39 } 40 if opts.SwOpts.SecLevel == 0 { 41 opts.SwOpts.SecLevel = 256 42 } 43 if opts.SwOpts.FileKeystore == nil { 44 opts.SwOpts.FileKeystore = &factory.FileKeystoreOpts{} 45 } 46 // The mspDir overrides the KeyStorePath; otherwise, if not set, set default 47 if mspDir != "" { 48 opts.SwOpts.FileKeystore.KeyStorePath = path.Join(mspDir, "keystore") 49 } else if opts.SwOpts.FileKeystore.KeyStorePath == "" { 50 opts.SwOpts.FileKeystore.KeyStorePath = path.Join("msp", "keystore") 51 } 52 } 53 err = makeFileNamesAbsolute(opts, homeDir) 54 if err != nil { 55 return errors.WithMessage(err, "Failed to make BCCSP files absolute") 56 } 57 log.Debugf("Initializing BCCSP: %+v", opts) 58 if opts.SwOpts != nil { 59 log.Debugf("Initializing BCCSP with software options %+v", opts.SwOpts) 60 } 61 // Init the BCCSP factories 62 err = factory.InitFactories(opts) 63 if err != nil { 64 return errors.WithMessage(err, "Failed to initialize BCCSP Factories") 65 } 66 *optsPtr = opts 67 return nil 68 }