Skip to content

Commit 38a266b

Browse files
committed
add support for keystore path
Signed-off-by: Angelo De Caro <angelo.decaro@gmail.com>
1 parent daa90ee commit 38a266b

File tree

6 files changed

+25
-31
lines changed

6 files changed

+25
-31
lines changed

platform/fabric/core/generic/id/info_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestInfoIdemix(t *testing.T) {
4646
}
4747

4848
func TestInfoX509(t *testing.T) {
49-
p, err := x5092.NewProvider("./testdata/x509", "apple", nil)
49+
p, err := x5092.NewProvider("./testdata/x509", "", "apple", nil)
5050
assert.NoError(t, err)
5151
id, _, err := p.Identity(nil)
5252
assert.NoError(t, err)

platform/fabric/core/generic/msp/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (s *service) RegisterX509MSP(id string, path string, mspID string) error {
255255
s.mspsMutex.Lock()
256256
defer s.mspsMutex.Unlock()
257257

258-
provider, err := x509.NewProvider(path, mspID, s.signerService)
258+
provider, err := x509.NewProvider(path, "", mspID, s.signerService)
259259
if err != nil {
260260
return errors.Wrapf(err, "failed instantiating idemix msp provider from [%s]", path)
261261
}

platform/fabric/core/generic/msp/x509/loader.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,11 @@ func (i *IdentityLoader) Load(manager driver.Manager, c config.MSP) error {
4444

4545
// Try without "msp"
4646
rootPath := filepath.Join(manager.Config().TranslatePath(c.Path))
47-
provider, err := NewProviderWithBCCSPConfig(
48-
rootPath,
49-
c.MSPID,
50-
manager.SignerService(),
51-
bccspOpts,
52-
)
47+
provider, err := NewProviderWithBCCSPConfig(rootPath, "", c.MSPID, manager.SignerService(), bccspOpts)
5348
if err != nil {
5449
logger.Warnf("failed reading bccsp msp configuration from [%s]: [%s]", rootPath, err)
5550
// Try with "msp"
56-
provider, err = NewProviderWithBCCSPConfig(
57-
filepath.Join(rootPath, "msp"),
58-
c.MSPID,
59-
manager.SignerService(),
60-
bccspOpts,
61-
)
51+
provider, err = NewProviderWithBCCSPConfig(filepath.Join(rootPath, "msp"), "", c.MSPID, manager.SignerService(), bccspOpts)
6252
if err != nil {
6353
logger.Warnf("failed reading bccsp msp configuration from [%s and %s]: [%s]",
6454
rootPath, filepath.Join(rootPath, "msp"), err,

platform/fabric/core/generic/msp/x509/provider.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ type Provider struct {
3232

3333
// NewProvider returns a new X509 provider. If the configuration path contains the secret key,
3434
// then the provider can generate also signatures, otherwise it cannot.
35-
func NewProvider(mspConfigPath, mspID string, signerService SignerService) (*Provider, error) {
36-
return NewProviderWithBCCSPConfig(mspConfigPath, mspID, signerService, nil)
35+
func NewProvider(mspConfigPath, keyStorePath, mspID string, signerService SignerService) (*Provider, error) {
36+
return NewProviderWithBCCSPConfig(mspConfigPath, keyStorePath, mspID, signerService, nil)
3737
}
3838

3939
// NewProviderWithBCCSPConfig returns a new X509 provider with the passed BCCSP configuration.
4040
// If the configuration path contains the secret key,
4141
// then the provider can generate also signatures, otherwise it cannot.
42-
func NewProviderWithBCCSPConfig(mspConfigPath, mspID string, signerService SignerService, bccspConfig *config.BCCSP) (*Provider, error) {
43-
p, err := newProvider(mspConfigPath, mspID, signerService, bccspConfig)
42+
func NewProviderWithBCCSPConfig(mspConfigPath, keyStorePath, mspID string, signerService SignerService, bccspConfig *config.BCCSP) (*Provider, error) {
43+
p, err := newProvider(mspConfigPath, keyStorePath, mspID, signerService, bccspConfig)
4444
if err == nil {
4545
return p, nil
4646
}
@@ -57,8 +57,8 @@ func NewProviderWithBCCSPConfig(mspConfigPath, mspID string, signerService Signe
5757
return &Provider{id: idRaw, enrollmentID: enrollmentID}, nil
5858
}
5959

60-
func newProvider(mspConfigPath, mspID string, signerService SignerService, bccspConfig *config.BCCSP) (*Provider, error) {
61-
sID, err := GetSigningIdentity(mspConfigPath, mspID, bccspConfig)
60+
func newProvider(mspConfigPath, keyStorePath, mspID string, signerService SignerService, bccspConfig *config.BCCSP) (*Provider, error) {
61+
sID, err := GetSigningIdentity(mspConfigPath, keyStorePath, mspID, bccspConfig)
6262
if err != nil {
6363
return nil, err
6464
}

platform/fabric/core/generic/msp/x509/setup.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ const (
3131
SignCerts = "signcerts"
3232
)
3333

34-
// GetSigningIdentity retrieves a signing identity from the passed arguments
35-
func GetSigningIdentity(mspConfigPath, mspID string, bccspConfig *config.BCCSP) (driver.SigningIdentity, error) {
36-
mspInstance, err := LoadLocalMSPAt(mspConfigPath, mspID, BCCSPType, bccspConfig)
34+
// GetSigningIdentity retrieves a signing identity from the passed arguments.
35+
// If keyStorePath is empty, then it is assumed that the key is at mspConfigPath/keystore
36+
func GetSigningIdentity(mspConfigPath, keyStorePath, mspID string, bccspConfig *config.BCCSP) (driver.SigningIdentity, error) {
37+
mspInstance, err := LoadLocalMSPAt(mspConfigPath, keyStorePath, mspID, BCCSPType, bccspConfig)
3738
if err != nil {
3839
return nil, err
3940
}
@@ -48,7 +49,7 @@ func GetSigningIdentity(mspConfigPath, mspID string, bccspConfig *config.BCCSP)
4849

4950
// LoadLocalMSPAt loads an MSP whose configuration is stored at 'dir', and whose
5051
// id and type are the passed as arguments.
51-
func LoadLocalMSPAt(dir, id, mspType string, bccspConfig *config.BCCSP) (msp.MSP, error) {
52+
func LoadLocalMSPAt(dir, keyStorePath, id, mspType string, bccspConfig *config.BCCSP) (msp.MSP, error) {
5253
if mspType != BCCSPType {
5354
return nil, errors.Errorf("invalid msp type, expected 'bccsp', got %s", mspType)
5455
}
@@ -57,7 +58,7 @@ func LoadLocalMSPAt(dir, id, mspType string, bccspConfig *config.BCCSP) (msp.MSP
5758
return nil, errors.WithMessagef(err, "could not get msp config from dir [%s]", dir)
5859
}
5960

60-
cp, _, err := GetBCCSPFromConf(dir, bccspConfig)
61+
cp, _, err := GetBCCSPFromConf(dir, keyStorePath, bccspConfig)
6162
if err != nil {
6263
return nil, errors.WithMessagef(err, "failed to get bccsp from config [%v]", bccspConfig)
6364
}
@@ -89,7 +90,7 @@ func LoadVerifyingMSPAt(dir, id, mspType string) (msp.MSP, error) {
8990
return nil, errors.WithMessagef(err, "could not get msp config from dir [%s]", dir)
9091
}
9192

92-
cp, _, err := GetBCCSPFromConf(dir, nil)
93+
cp, _, err := GetBCCSPFromConf(dir, "", nil)
9394
if err != nil {
9495
return nil, errors.WithMessagef(err, "failed to get bccsp")
9596
}
@@ -121,14 +122,17 @@ func LoadLocalMSPSignerCert(dir string) ([]byte, error) {
121122

122123
// GetBCCSPFromConf returns a BCCSP instance and its relative key store from the passed configuration.
123124
// If no configuration is passed, the default one is used, namely the `SW` provider.
124-
func GetBCCSPFromConf(dir string, conf *config.BCCSP) (bccsp.BCCSP, bccsp.KeyStore, error) {
125+
func GetBCCSPFromConf(dir string, keyStorePath string, conf *config.BCCSP) (bccsp.BCCSP, bccsp.KeyStore, error) {
126+
if len(keyStorePath) == 0 {
127+
keyStorePath = filepath.Join(dir, "keystore")
128+
}
125129
if conf == nil {
126-
return GetSWBCCSP(dir)
130+
return GetSWBCCSP(keyStorePath)
127131
}
128132

129133
switch conf.Default {
130134
case "SW":
131-
return GetSWBCCSP(dir)
135+
return GetSWBCCSP(keyStorePath)
132136
case "PKCS11":
133137
return GetPKCS11BCCSP(conf)
134138
default:
@@ -172,7 +176,7 @@ func skiMapper(p11Opts config.PKCS11) func([]byte) []byte {
172176

173177
// GetSWBCCSP returns a new instance of the software-based BCCSP
174178
func GetSWBCCSP(dir string) (bccsp.BCCSP, bccsp.KeyStore, error) {
175-
ks, err := sw.NewFileBasedKeyStore(nil, filepath.Join(dir, "keystore"), true)
179+
ks, err := sw.NewFileBasedKeyStore(nil, dir, true)
176180
if err != nil {
177181
return nil, nil, err
178182
}

platform/fabric/core/generic/msp/x509/x509_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func TestDeserializer(t *testing.T) {
16-
p, err := NewProvider("./testdata/msp", "apple", nil)
16+
p, err := NewProvider("./testdata/msp", "", "apple", nil)
1717
assert.NoError(t, err)
1818
id, auditInfo, err := p.Identity(nil)
1919
assert.NoError(t, err)

0 commit comments

Comments
 (0)