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