Skip to content

Commit

Permalink
[FAB-3503] Wrong MSP keystore directory location
Browse files Browse the repository at this point in the history
See [FAB-3503].
The keystore location is in the wrong location.
It is being created in the current working directory, but should
be in the client's HOME/msp directory.

Change-Id: I15d7714a2c7be128cded74d288d062b8d7b96b8a
Signed-off-by: Keith Smith <[email protected]>
  • Loading branch information
Keith Smith committed Apr 28, 2017
1 parent 4b58d5c commit 50c540e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/fabric-ca-client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bccsp:
security: 256
filekeystore:
# The directory used for the software file-based keystore
keystore: keystore
keystore: msp/keystore
`
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/fabric-ca-server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ func TestClean(t *testing.T) {
os.Remove(unsupportedFileType)
os.Remove("ca-key.pem")
os.Remove("ca-cert.pem")
os.Remove("ca-cert.pem")
os.Remove("fabric-ca-server.db")
os.RemoveAll("msp")
os.RemoveAll("keystore")
os.RemoveAll("../../testdata/keystore")
os.Remove("../../testdata/fabric-ca-server.db")
os.Remove("../../testdata/ca-cert.pem")
}
Expand Down
3 changes: 1 addition & 2 deletions lib/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ func (ca *CA) init(renew bool) (err error) {
return err
}
// Initialize the crypto layer (BCCSP) for this CA
defaultKeyStoreDir := path.Join(ca.HomeDir, "msp", "keystore")
ca.csp, err = csp.InitBCCSP(&ca.Config.CSP, defaultKeyStoreDir)
ca.csp, err = csp.InitBCCSP(&ca.Config.CSP, ca.HomeDir)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions lib/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (c *Client) Init() error {
return fmt.Errorf("Failed to create cacerts directory: %s", err)
}
// Initialize BCCSP (the crypto layer)
keyStoreDir := path.Join(mspDir, "keystore")
c.csp, err = csp.InitBCCSP(&cfg.CSP, keyStoreDir)
c.csp, err = csp.InitBCCSP(&cfg.CSP, c.HomeDir)
if err != nil {
return err
}
Expand Down
29 changes: 26 additions & 3 deletions lib/csp/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"errors"
"fmt"
"io/ioutil"
"path"
"path/filepath"
"strings"
_ "time" // for ocspSignerFromConfig

Expand All @@ -47,9 +49,10 @@ func GetDefaultBCCSP() bccsp.BCCSP {
}

// InitBCCSP initializes BCCSP
func InitBCCSP(optsPtr **factory.FactoryOpts, keyStoreDir string) (bccsp.BCCSP, error) {
func InitBCCSP(optsPtr **factory.FactoryOpts, homeDir string) (bccsp.BCCSP, error) {
// Initialize the config, setting defaults as needed
var opts *factory.FactoryOpts
var err error
if optsPtr != nil {
opts = *optsPtr
}
Expand All @@ -64,11 +67,16 @@ func InitBCCSP(optsPtr **factory.FactoryOpts, keyStoreDir string) (bccsp.BCCSP,
if opts.SwOpts.FileKeystore == nil ||
opts.SwOpts.FileKeystore.KeyStorePath == "" {
opts.SwOpts.Ephemeral = false
opts.SwOpts.FileKeystore = &factory.FileKeystoreOpts{KeyStorePath: keyStoreDir}
opts.SwOpts.FileKeystore = &factory.FileKeystoreOpts{KeyStorePath: path.Join("msp", "keystore")}
}
opts.SwOpts.FileKeystore.KeyStorePath, err = makeFileAbs(opts.SwOpts.FileKeystore.KeyStorePath, homeDir)
if err != nil {
return nil, fmt.Errorf("Failed to initialize BCCSP: %s", err)
}
log.Debugf("Software key file store directory: %s", opts.SwOpts.FileKeystore.KeyStorePath)
}
// Init the BCCSP factories
err := factory.InitFactories(opts)
err = factory.InitFactories(opts)
if err != nil {
return nil, fmt.Errorf("Failed to initialize BCCSP Factories: %s", err)
}
Expand Down Expand Up @@ -236,3 +244,18 @@ func ImportBCCSPKeyFromPEM(keyFile string, myCSP bccsp.BCCSP, temporary bool) (b
return nil, fmt.Errorf("Failed to import key from %s: invalid secret key type", keyFile)
}
}

// makeFileAbs makes 'file' absolute relative to 'dir' if not already absolute
func makeFileAbs(file, dir string) (string, error) {
if file == "" {
return "", nil
}
if filepath.IsAbs(file) {
return file, nil
}
path, err := filepath.Abs(filepath.Join(dir, file))
if err != nil {
return "", fmt.Errorf("Failed making '%s' absolute based on '%s'", file, dir)
}
return path, nil
}
1 change: 1 addition & 0 deletions lib/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ func TestEnd(t *testing.T) {
os.RemoveAll(rootDir)
os.RemoveAll(intermediateDir)
os.RemoveAll("multica")
os.RemoveAll(serversDir)
cleanMultiCADir()
}

Expand Down

0 comments on commit 50c540e

Please sign in to comment.