-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-2883] Add option to build without PKCS11 support
https://jira.hyperledger.org/browse/FAB-2883 This patch enables the option to build components without PKCS11 support. The reason is due to the fact that PKCS11 support adds a dependency on libtool which makes it difficult to build binaries locally. Additonally, tools like configtxgen don't actually require PKCS11 support but due to their dependency on bccsp PKCS11 was being included. The following changes were made: - bccsp/factory - added a build tag "nopkcs11" and rearranged code into 2 files - pkcs11.go and nopkcs11.go - which use the tag. The default is to build with PKCS11 support - added a GO_TAGS variable to Makefile which is used for build/bin/* targets - modified the configtxgen target to always build without PKCS11 support Change-Id: I2d983d8c71eb6c214ad0d9e4d67e73310126afa2 Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
- Loading branch information
1 parent
397f5de
commit 0616a9d
Showing
6 changed files
with
157 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// +build nopkcs11 | ||
|
||
/* | ||
Copyright IBM Corp. 2017 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package factory | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hyperledger/fabric/bccsp" | ||
) | ||
|
||
type FactoryOpts struct { | ||
ProviderName string `mapstructure:"default" json:"default" yaml:"Default"` | ||
SwOpts *SwOpts `mapstructure:"SW,omitempty" json:"SW,omitempty" yaml:"SwOpts"` | ||
} | ||
|
||
// InitFactories must be called before using factory interfaces | ||
// It is acceptable to call with config = nil, in which case | ||
// some defaults will get used | ||
// Error is returned only if defaultBCCSP cannot be found | ||
func InitFactories(config *FactoryOpts) error { | ||
factoriesInitOnce.Do(func() { | ||
// Take some precautions on default opts | ||
if config == nil { | ||
config = &DefaultOpts | ||
} | ||
|
||
if config.ProviderName == "" { | ||
config.ProviderName = "SW" | ||
} | ||
|
||
if config.SwOpts == nil { | ||
config.SwOpts = DefaultOpts.SwOpts | ||
} | ||
|
||
// Initialize factories map | ||
bccspMap = make(map[string]bccsp.BCCSP) | ||
|
||
// Software-Based BCCSP | ||
if config.SwOpts != nil { | ||
f := &SWFactory{} | ||
err := initBCCSP(f, config) | ||
if err != nil { | ||
factoriesInitError = fmt.Errorf("[%s]", err) | ||
} | ||
} | ||
|
||
var ok bool | ||
defaultBCCSP, ok = bccspMap[config.ProviderName] | ||
if !ok { | ||
factoriesInitError = fmt.Errorf("%s\nCould not find default `%s` BCCSP", factoriesInitError, config.ProviderName) | ||
} | ||
}) | ||
|
||
return factoriesInitError | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// +build !nopkcs11 | ||
|
||
/* | ||
Copyright IBM Corp. 2017 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package factory | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hyperledger/fabric/bccsp" | ||
) | ||
|
||
type FactoryOpts struct { | ||
ProviderName string `mapstructure:"default" json:"default" yaml:"Default"` | ||
SwOpts *SwOpts `mapstructure:"SW,omitempty" json:"SW,omitempty" yaml:"SwOpts"` | ||
Pkcs11Opts *PKCS11Opts `mapstructure:"PKCS11,omitempty" json:"PKCS11,omitempty" yaml:"PKCS11"` | ||
} | ||
|
||
// InitFactories must be called before using factory interfaces | ||
// It is acceptable to call with config = nil, in which case | ||
// some defaults will get used | ||
// Error is returned only if defaultBCCSP cannot be found | ||
func InitFactories(config *FactoryOpts) error { | ||
factoriesInitOnce.Do(func() { | ||
// Take some precautions on default opts | ||
if config == nil { | ||
config = &DefaultOpts | ||
} | ||
|
||
if config.ProviderName == "" { | ||
config.ProviderName = "SW" | ||
} | ||
|
||
if config.SwOpts == nil { | ||
config.SwOpts = DefaultOpts.SwOpts | ||
} | ||
|
||
// Initialize factories map | ||
bccspMap = make(map[string]bccsp.BCCSP) | ||
|
||
// Software-Based BCCSP | ||
if config.SwOpts != nil { | ||
f := &SWFactory{} | ||
err := initBCCSP(f, config) | ||
if err != nil { | ||
factoriesInitError = fmt.Errorf("[%s]", err) | ||
} | ||
} | ||
|
||
// PKCS11-Based BCCSP | ||
if config.Pkcs11Opts != nil { | ||
f := &PKCS11Factory{} | ||
err := initBCCSP(f, config) | ||
if err != nil { | ||
factoriesInitError = fmt.Errorf("%s\n[%s]", factoriesInitError, err) | ||
} | ||
} | ||
|
||
var ok bool | ||
defaultBCCSP, ok = bccspMap[config.ProviderName] | ||
if !ok { | ||
factoriesInitError = fmt.Errorf("%s\nCould not find default `%s` BCCSP", factoriesInitError, config.ProviderName) | ||
} | ||
}) | ||
|
||
return factoriesInitError | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build !nopkcs11 | ||
|
||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
|