Skip to content

Commit

Permalink
Add support for -M option for enroll/reenroll
Browse files Browse the repository at this point in the history
See https://jira.hyperledger.org/browse/FAB-2602

This change set is the 2nd and last part of FAB-2602.
In particular, it adds support for the "-M <mspDir>"
option for the "fabric-ca-client enroll" and
the "fabric-ca-client reenroll" commands.  This provides
a greater degree of integration support for fabric by
storing the needed artifacts in MSP format, where
MSP stands for Membership Service Provider.

Change-Id: Ic3c6423fe2df61573847745de6017a7d20b8b16c
Signed-off-by: Keith Smith <[email protected]>
  • Loading branch information
Keith Smith committed Mar 11, 2017
1 parent 89b0916 commit c7b482e
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 126 deletions.
4 changes: 1 addition & 3 deletions cmd/fabric-ca-client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,9 @@ func processAttributes() {

func checkForEnrollment() error {
log.Debug("Checking for enrollment")

client := lib.Client{
HomeDir: filepath.Dir(cfgFileName),
Config: clientCfg,
}

return client.Enrollment()
return client.CheckEnrollment()
}
10 changes: 7 additions & 3 deletions cmd/fabric-ca-client/enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ func runEnroll(cmd *cobra.Command) error {
return err
}

ID, err := clientCfg.Enroll(clientCfg.URL, filepath.Dir(cfgFileName))
resp, err := clientCfg.Enroll(clientCfg.URL, filepath.Dir(cfgFileName))
if err != nil {
return err
}

ID := resp.Identity

cfgFile, err := ioutil.ReadFile(cfgFileName)
if err != nil {
return err
Expand All @@ -91,8 +93,10 @@ func runEnroll(cmd *cobra.Command) error {
return fmt.Errorf("Failed to store enrollment information: %s", err)
}

log.Infof("Enrollment information was successfully stored in %s and %s",
ID.GetMyKeyFile(), ID.GetMyCertFile())
err = storeCAChain(clientCfg, &resp.ServerInfo)
if err != nil {
return err
}

return nil
}
6 changes: 3 additions & 3 deletions cmd/fabric-ca-client/getcacert.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func runGetCACert() error {
return err
}

return storeCAChain(client, si)
return storeCAChain(client.Config, si)
}

// Store the CAChain in the CACerts folder of MSP (Membership Service Provider)
func storeCAChain(client *lib.Client, si *lib.GetServerInfoResponse) error {
mspDir := client.Config.MSPDir
func storeCAChain(config *lib.ClientConfig, si *lib.GetServerInfoResponse) error {
mspDir := config.MSPDir
if !util.FileExists(mspDir) {
return fmt.Errorf("Directory does not exist: %s", mspDir)
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/fabric-ca-client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (

const (
testYaml = "../../testdata/test.yaml"
mspDir = "../../testdata/msp"
myhost = "hostname"
certfile = "ec.pem"
keyfile = "ec-key.pem"
Expand Down Expand Up @@ -135,7 +136,7 @@ func testGetCACert(t *testing.T) {
t.Log("Testing getcacert")
defYaml = util.GetDefaultConfigFile("fabric-ca-client")
os.Remove(defYaml) // Clean up any left over config file
os.RemoveAll("cacerts")
os.RemoveAll("msp")
err := RunMain([]string{cmdName, "getcacert", "-d", "-u", "http://localhost:7054"})
if err != nil {
t.Errorf("getcainfo failed: %s", err)
Expand All @@ -149,6 +150,7 @@ func testGetCACert(t *testing.T) {
t.Error("getcacert with no URL should have failed but did not")
}
os.RemoveAll("cacerts")
os.RemoveAll("msp")
os.Remove(defYaml)
}

Expand Down Expand Up @@ -451,6 +453,7 @@ func TestCleanUp(t *testing.T) {
os.Remove("../../testdata/key.pem")
os.Remove(testYaml)
os.Remove(fabricCADB)
os.RemoveAll(mspDir)
}

func TestRegisterWithoutEnroll(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletions cmd/fabric-ca-client/reenroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,20 @@ func runReenroll() error {
CSR: &clientCfg.CSR,
}

newID, err := id.Reenroll(req)
resp, err := id.Reenroll(req)
if err != nil {
return fmt.Errorf("Failed to store enrollment information: %s", err)
}

err = newID.Store()
err = resp.Identity.Store()
if err != nil {
return err
}

log.Infof("Enrollment information was successfully stored in %s and %s",
client.GetMyKeyFile(), client.GetMyCertFile())
err = storeCAChain(clientCfg, &resp.ServerInfo)
if err != nil {
return err
}

return nil
}
Loading

0 comments on commit c7b482e

Please sign in to comment.