hyperledger / hyperledger/fabric-ca

Idemix "Role" is shadowed by marshalled interface

Open
#455 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
453
Forks
714
Avg merge
7h 23m
Merged PRs (30d)
3

Description

Role is supposed to be an int:

https://github.com/hyperledger/fabric-ca/blob/b3ae5fc317baf5306aa690bbab4113c78e606e3d/lib/client.go#L517

However, probably due to the marshalling of the attrMap (map[string]interface{}), the role becomes a float64 ([/golang reddit discussion](https://www.reddit.com/r/golang/comments/zyep2s/why_does_an_interface_of_an_int_value_becomes/))

https://github.com/hyperledger/fabric-ca/blob/b3ae5fc317baf5306aa690bbab4113c78e606e3d/lib/server/idemix/enroll.go#L156-L160

## Possible solutions

1) Cast to float64 before converting to int
```golang
roleFloat, _ := result.Attrs["Role"].(float64) // marshalling interface makes number float64
role := int(roleFloat)
```

2) Plus: test for errors
```golang
roleFloat, ok := result.Attrs["Role"].(float64) // marshalling interface makes number float64
if !ok {
return nil, errors.New("Failed to convert role to float64")
}
role := int(roleFloat)
```

## Replicate

1) Add log messages:
```golang
// Create SignerConfig object with credential bytes from the response
// and secret key
role, _ := result.Attrs["Role"].(int)
ou, _ := result.Attrs["OU"].(string)
enrollmentID, _ := result.Attrs["EnrollmentID"].(string)
revocationHandle := result.Attrs[sidemix.AttrRevocationHandle].(string)
signerConfig := &idemixcred.SignerConfig{
CurveID: cidemix.Curves.ByID(c.curveID),
Cred: credBytes,
Sk: sk.Bytes(),
Role: role,
OrganizationalUnitIdentifier: ou,
EnrollmentID: enrollmentID,
CredentialRevocationInformation: criBytes,
RevocationHandle: revocationHandle,
}

kind := reflect.TypeOf(result.Attrs["Role"]).Kind()
log.Infof("kind: %s", kind)
log.Infof("Attrs: %v", result.Attrs)
log.Infof("Attrs in signer config: %d", signerConfig.Role)
```

2) Register and enroll with role 1:
```bash
fabric-ca-client register -u http://localhost:27054 --id.name alice --id.secret password --id.type client --enrollment.type idemix --id.attrs 'role=1' --id.affiliation "org1.department1"
fabric-ca-client enroll -u http://alice:password@localhost:27054 -M "$(pwd)/keys/owner1/wallet/alice/msp" --enrollment.type idemix

```

3) Verify that the saved SignerConfig has no "role" attribute:
```json
{
"Cred": "CkQKIC6o6Uz33XosEntANagpoJQdyfpbnacbk/dsW4z3JKqxEiCvo//GIXRKgIi4yt6x3RxwpEXzECXo4mVdqb2DGnYgfxJECiCX+RCJq4l7A75be2pgs0La/ZV6cXpeEHaJlDMkscSVnRIg42VQR/OGpuMOCD2la7VhcBW6BQnPZO0UWtlvER3rCW4aIBWUPW8xgTNI/RTZey6UrfJDd2dExig1hxaO9uS0cRrcIiDEW8biruxGd6vGW97CeznZd1wU0fmxyTv14cXnXBiX2CogO9JiNVuB+erB4v8Cf7ch+8j/aCf59RgcDd5f662qAcUqIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABKiAr2AbJfw4ArxofwzKPp2OpJpcjyNuPrE+Tr3HbGG1ukCoga4ayc/80/OGda4BO/1o/V0etpOqiLx1JwB5S3beHW0s=",
"Sk": "mcT93zqYeXq+pUgQUZd9E7ryQbUPI/u4DIUkPvgSSb4=",
"organizational_unit_identifier": "org1.department1",
"enrollment_id": "alice",
"credential_revocation_information": "CAESiAEKIP4MM1C0yWwgKFYPV3wokTrOHFOaEr+EPNImFraJwJ77EiBOpmBXc4rAVNta4cY32BO5JN144ofQNYnSae00o35qKxogcCBG58VCo7N2dw11Ek4+Ue/LJHWNYVhI6Qm0gb7cJ/8iIAVU47zTiMKQQu6mSSl+sp+LTL6AghqYs+ASgRFKrQSbGmcwZQIxAJm8eXfyNWdShXp0p1VDLiI+B2Z9sey/udSO51VsCBeYJ8yU0yT48urhM4QuRX01dQIwCm7cbPuN4v60kRpCIYZ0+0ZTLbUo1PJGZAEGbRKx5jSiMalDjlrWDQ641KBpAYT4",
"curveID": "amcl.Fp256bn",
"revocation_handle": "1"
}
```

## Context

I was trying to generate testing credentials for the implementation of idemix on fabric-gateway: https://github.com/hyperledger/fabric-gateway/issues/242

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.