github.com/tw-bc-group/fabric-ca-gm@v0.0.0-20201218004200-3b690512bd5a/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/pkg/errors" 17 "github.com/tw-bc-group/fabric-gm/bccsp/factory" 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 = "GM" 32 } 33 SetProviderName(opts.ProviderName) 34 if strings.ToUpper(opts.ProviderName) == "SW" { 35 if opts.SwOpts == nil { 36 opts.SwOpts = &factory.SwOpts{} 37 } 38 if opts.SwOpts.HashFamily == "" { 39 opts.SwOpts.HashFamily = "SHA2" 40 } 41 if opts.SwOpts.SecLevel == 0 { 42 opts.SwOpts.SecLevel = 256 43 } 44 if opts.SwOpts.FileKeystore == nil { 45 opts.SwOpts.FileKeystore = &factory.FileKeystoreOpts{} 46 } 47 // The mspDir overrides the KeyStorePath; otherwise, if not set, set default 48 if mspDir != "" { 49 opts.SwOpts.FileKeystore.KeyStorePath = path.Join(mspDir, "keystore") 50 } else if opts.SwOpts.FileKeystore.KeyStorePath == "" { 51 opts.SwOpts.FileKeystore.KeyStorePath = path.Join("msp", "keystore") 52 } 53 } 54 if strings.ToUpper(opts.ProviderName) == "GM" { 55 if opts.SwOpts == nil { 56 opts.SwOpts = &factory.SwOpts{} 57 } 58 if opts.SwOpts.HashFamily == "" { 59 opts.SwOpts.HashFamily = "GMSM3" 60 } 61 if opts.SwOpts.SecLevel == 0 { 62 opts.SwOpts.SecLevel = 256 63 } 64 if opts.SwOpts.FileKeystore == nil { 65 opts.SwOpts.FileKeystore = &factory.FileKeystoreOpts{} 66 } 67 // The mspDir overrides the KeyStorePath; otherwise, if not set, set default 68 if mspDir != "" { 69 opts.SwOpts.FileKeystore.KeyStorePath = path.Join(mspDir, "keystore") 70 } else if opts.SwOpts.FileKeystore.KeyStorePath == "" { 71 opts.SwOpts.FileKeystore.KeyStorePath = path.Join("msp", "keystore") 72 } 73 } 74 err = makeFileNamesAbsolute(opts, homeDir) 75 if err != nil { 76 return errors.WithMessage(err, "Failed to make BCCSP files absolute") 77 } 78 log.Debugf("Initializing BCCSP: %+v", opts) 79 if opts.SwOpts != nil { 80 log.Debugf("Initializing BCCSP with software options %+v", opts.SwOpts) 81 } 82 // Init the BCCSP factories 83 err = factory.InitFactories(opts) 84 if err != nil { 85 return errors.WithMessage(err, "Failed to initialize BCCSP Factories") 86 } 87 *optsPtr = opts 88 return nil 89 }