Skip to content

Commit 048e6f9

Browse files
Revert change to Idemix credential directory
Also some minor code tidy-up. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
1 parent 5dd92a4 commit 048e6f9

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

docs/source/deployguide/cadeploy.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ These folders are used by the Fabric CA client to:
447447
| └── 60b6a16b8b5ba3fc3113c522cce86a724d7eb92d6c3961cfd9afbd27bf11c37f_sk
448448
├── signcerts
449449
| └── cert.pem
450+
├── user
450451
├── IssuerPublicKey
451452
└── RevocationPublicKey
452453
```
@@ -504,13 +505,13 @@ The resulting folder structure is similar to the following structure. (Some fold
504505
fabric-ca-client
505506
└── tls-ca
506507
└── icaadmin
507-
├── user
508508
└── msp
509509
├── cacerts
510510
├── keystore
511511
   | └── key.pem
512512
├── signcerts
513513
|   └── cert.pem
514+
├── user
514515
├── tlscacerts
515516
├── IssuerPublicKey
516517
└── RevocationPublicKey

docs/source/operations_guide.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,16 @@ issued form the CA. You will see files such as the ones below:
233233
234234
admin
235235
├── fabric-ca-client-config.yaml
236-
├── user
237236
└── msp
238237
├── IssuerPublicKey
239238
├── RevocationPublicKey
240239
├── cacerts
241240
│ └── 0-0-0-0-7053.pem
242241
├── keystore
243242
│ └── 60b6a16b8b5ba3fc3113c522cce86a724d7eb92d6c3961cfd9afbd27bf11c37f_sk
244-
└── signcerts
245-
└── cert.pem
243+
├── signcerts
244+
│ └── cert.pem
245+
└── user
246246
247247
The ``fabric-ca-client-config.yaml`` is a file that is generated by the CA client,
248248
this file contains the configuration of the CA client. There are three other important files

lib/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type Client struct {
5353
// Denotes if the client object is already initialized
5454
initialized bool
5555
// File and directory paths
56-
keyFile, certFile, idemixCredFile, idemixCredsDir, ipkFile, caCertsDir string
56+
keyFile, certFile, idemixCredFile, ipkFile, caCertsDir string
5757
// The crypto service provider (BCCSP)
5858
csp bccsp.BCCSP
5959
// HTTP client associated with this Fabric CA client
@@ -126,12 +126,12 @@ func (c *Client) Init() error {
126126
c.ipkFile = filepath.Join(mspDir, "IssuerPublicKey")
127127

128128
// Idemix credentials directory
129-
c.idemixCredsDir = path.Join(c.HomeDir, "user")
130-
err = os.MkdirAll(c.idemixCredsDir, 0o755)
129+
idemixCredsDir := path.Join(mspDir, "user")
130+
err = os.MkdirAll(idemixCredsDir, 0o755)
131131
if err != nil {
132132
return errors.Wrap(err, "Failed to create Idemix credentials directory 'user'")
133133
}
134-
c.idemixCredFile = path.Join(c.idemixCredsDir, "SignerConfig")
134+
c.idemixCredFile = path.Join(idemixCredsDir, "SignerConfig")
135135

136136
// Initialize BCCSP (the crypto layer)
137137
c.csp, err = util.InitBCCSP(&cfg.CSP, mspDir, c.HomeDir)

lib/client/credential/idemix/credential.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,18 @@ func (cred *Credential) Store() error {
109109
EnrollmentId: caSignerConfig.EnrollmentID,
110110
CredentialRevocationInformation: caSignerConfig.CredentialRevocationInformation,
111111
}
112+
112113
signerConfigBytes, err := proto2.Marshal(mspSignerConfig)
113114
if err != nil {
114115
return errors.Wrapf(err, "Failed to marshal SignerConfig")
115116
}
116-
err = util.WriteFile(cred.signerConfigFile, signerConfigBytes, 0o644)
117-
if err != nil {
117+
118+
if err := util.WriteFile(cred.signerConfigFile, signerConfigBytes, 0o644); err != nil {
118119
return errors.WithMessage(err, "Failed to store the Idemix credential")
119120
}
121+
120122
log.Infof("Stored the Idemix credential at %s", cred.signerConfigFile)
123+
121124
return nil
122125
}
123126

@@ -131,30 +134,26 @@ func (cred *Credential) Load() error {
131134
}
132135

133136
// Load the MSP signer config
134-
var val SignerConfig
135137
mspSignerConfig := &msp.IdemixMSPSignerConfig{}
136-
err = proto2.Unmarshal(signerConfigBytes, mspSignerConfig)
137-
if err == nil {
138-
val = SignerConfig{
138+
if err := proto2.Unmarshal(signerConfigBytes, mspSignerConfig); err == nil {
139+
cred.val = &SignerConfig{
139140
Cred: mspSignerConfig.Cred,
140141
Sk: mspSignerConfig.Sk,
141142
OrganizationalUnitIdentifier: mspSignerConfig.OrganizationalUnitIdentifier,
142143
Role: int(mspSignerConfig.Role),
143144
EnrollmentID: mspSignerConfig.EnrollmentId,
144145
CredentialRevocationInformation: mspSignerConfig.CredentialRevocationInformation,
145146
}
147+
return nil
146148
}
147149

148-
if err != nil {
149-
// try to unmarshal via json
150-
val = SignerConfig{}
151-
err = json.Unmarshal(signerConfigBytes, &val)
152-
if err != nil {
153-
return errors.Wrapf(err, "Failed to unmarshal SignerConfig bytes from %s", cred.signerConfigFile)
154-
}
150+
// try to unmarshal via json
151+
val := new(SignerConfig)
152+
if err := json.Unmarshal(signerConfigBytes, val); err != nil {
153+
return errors.Wrapf(err, "Failed to unmarshal SignerConfig bytes from %s", cred.signerConfigFile)
155154
}
156155

157-
cred.val = &val
156+
cred.val = val
158157
return nil
159158
}
160159

lib/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ func TestIdemixEnroll(t *testing.T) {
209209
t.Fatalf("Failed to store identity: %s", err.Error())
210210
}
211211

212-
_, err = client.LoadIdentity("", filepath.Join(clientHome, "msp/signcerts/cert.pem"), filepath.Join(clientHome, "user/SignerConfig"))
212+
_, err = client.LoadIdentity("", filepath.Join(clientHome, "msp/signcerts/cert.pem"), filepath.Join(clientHome, "msp/user/SignerConfig"))
213213
assert.NoError(t, err, "Failed to load identity that has both X509 and Idemix credentials")
214214

215-
_, err = client.LoadIdentity("", "", filepath.Join(clientHome, "user/SignerConfig"))
215+
_, err = client.LoadIdentity("", "", filepath.Join(clientHome, "msp/user/SignerConfig"))
216216
assert.NoError(t, err, "Failed to load identity that only has Idemix credential")
217217

218218
// Error case, invalid x509 and Idemix credential

scripts/fvt/idemix_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function getIdemixCred() {
4040
$FABRIC_CA_CLIENTEXEC enroll -u "${PROTO}${USERNAME}:$USERPSWD@$CA_HOST_ADDRESS:$PROXY_PORT" -H $CA_CFG_PATH/$USERNAME --enrollment.type idemix -d $TLSOPT
4141
test $? -eq 0 || ErrorMsg "Failed to complete 'enroll' command"
4242

43-
CLIENTCERT="$CA_CFG_PATH/$USERNAME/user/SignerConfig"
43+
CLIENTCERT="$CA_CFG_PATH/$USERNAME/msp/user/SignerConfig"
4444
if [ ! -f $CLIENTCERT ]; then
4545
ErrorMsg "Idemix credential was not stored in the correct location"
4646
fi

0 commit comments

Comments
 (0)