@@ -20,17 +20,38 @@ import (
20
20
"github.com/pkg/errors"
21
21
)
22
22
23
+ const (
24
+ // AttributeIndexOU contains the index of the OU attribute in the idemix credential attributes
25
+ AttributeIndexOU = iota
26
+
27
+ // AttributeIndexRole contains the index of the Role attribute in the idemix credential attributes
28
+ AttributeIndexRole
29
+
30
+ // AttributeIndexEnrollmentId contains the index of the Enrollment ID attribute in the idemix credential attributes
31
+ AttributeIndexEnrollmentId
32
+
33
+ // AttributeIndexRevocationHandle contains the index of the Revocation Handle attribute in the idemix credential attributes
34
+ AttributeIndexRevocationHandle
35
+ )
36
+
23
37
const (
24
38
// AttributeNameOU is the attribute name of the Organization Unit attribute
25
39
AttributeNameOU = "OU"
26
40
27
41
// AttributeNameRole is the attribute name of the Role attribute
28
42
AttributeNameRole = "Role"
43
+
44
+ // AttributeNameEnrollmentId is the attribute name of the Enrollment ID attribute
45
+ AttributeNameEnrollmentId = "EnrollmentID"
46
+
47
+ // AttributeNameRevocationHandle is the attribute name of the revocation handle attribute
48
+ AttributeNameRevocationHandle = "RevocationHandle"
29
49
)
30
50
31
51
// discloseFlags will be passed to the idemix signing and verification routines.
32
- // It informs idemix to disclose both attributes (OU and Role) when signing.
33
- var discloseFlags = []byte {1 , 1 }
52
+ // It informs idemix to disclose both attributes (OU and Role) when signing,
53
+ // while hiding attributes EnrollmentID and RevocationHandle.
54
+ var discloseFlags = []byte {1 , 1 , 0 , 0 }
34
55
35
56
type idemixmsp struct {
36
57
ipk * idemix.IssuerPublicKey
@@ -77,8 +98,12 @@ func (msp *idemixmsp) Setup(conf1 *m.MSPConfig) error {
77
98
return errors .WithMessage (err , "setting the hash of the issuer public key failed" )
78
99
}
79
100
80
- if len (ipk .AttributeNames ) < 2 || ipk .AttributeNames [0 ] != AttributeNameOU || ipk .AttributeNames [1 ] != AttributeNameRole {
81
- return errors .Errorf ("ipk must have have attributes OU and Role" )
101
+ if len (ipk .AttributeNames ) < 4 ||
102
+ ipk .AttributeNames [AttributeIndexOU ] != AttributeNameOU ||
103
+ ipk .AttributeNames [AttributeIndexRole ] != AttributeNameRole ||
104
+ ipk .AttributeNames [AttributeIndexEnrollmentId ] != AttributeNameEnrollmentId ||
105
+ ipk .AttributeNames [AttributeIndexRevocationHandle ] != AttributeNameRevocationHandle {
106
+ return errors .Errorf ("issuer public key must have have attributes OU, Role, EnrollmentId, and RevocationHandle" )
82
107
}
83
108
84
109
err = ipk .Check ()
@@ -124,22 +149,29 @@ func (msp *idemixmsp) Setup(conf1 *m.MSPConfig) error {
124
149
CertifiersIdentifier : ipk .Hash ,
125
150
}
126
151
127
- // Check if credential contains the right amount of attribute values (Role and OU)
128
- if len (cred .Attrs ) != 2 {
129
- return errors .Errorf ("Credential contains %d attribute values, but expected 2" , len (cred .Attrs ))
152
+ enrollmentId := conf .Signer .EnrollmentId
153
+
154
+ // Check if credential contains the right amount of attribute values (Role, OU, EnrollmentId, RevocationHandle)
155
+ if len (cred .Attrs ) != 4 {
156
+ return errors .Errorf ("Credential contains %d attribute values, but expected 4" , len (cred .Attrs ))
130
157
}
131
158
132
159
// Check if credential contains the correct OU attribute value
133
160
ouBytes := []byte (conf .Signer .OrganizationalUnitIdentifier )
134
- if ! bytes .Equal (idemix .BigToBytes (idemix .HashModOrder (ouBytes )), cred .Attrs [0 ]) {
161
+ if ! bytes .Equal (idemix .BigToBytes (idemix .HashModOrder (ouBytes )), cred .Attrs [AttributeIndexOU ]) {
135
162
return errors .New ("Credential does not contain the correct OU attribute value" )
136
163
}
137
164
138
- // Check if credential contains the correct OU attribute value
139
- if ! bytes .Equal (idemix .BigToBytes (FP256BN .NewBIGint (int (role .Role ))), cred .Attrs [1 ]) {
165
+ // Check if credential contains the correct Role attribute value
166
+ if ! bytes .Equal (idemix .BigToBytes (FP256BN .NewBIGint (int (role .Role ))), cred .Attrs [AttributeIndexRole ]) {
140
167
return errors .New ("Credential does not contain the correct Role attribute value" )
141
168
}
142
169
170
+ // Check if credential contains the correct Enrollment ID attribute value
171
+ if ! bytes .Equal (idemix .BigToBytes (idemix .HashModOrder ([]byte (enrollmentId ))), cred .Attrs [AttributeIndexEnrollmentId ]) {
172
+ return errors .New ("Credential does not contain the correct enrollment id attribute value" )
173
+ }
174
+
143
175
// Verify that the credential is cryptographically valid
144
176
err = cred .Ver (sk , msp .ipk )
145
177
if err != nil {
@@ -153,7 +185,7 @@ func (msp *idemixmsp) Setup(conf1 *m.MSPConfig) error {
153
185
}
154
186
155
187
// Set up default signer
156
- msp .signer = & idemixSigningIdentity {newIdemixIdentity (msp , Nym , role , ou , proof ), rng , cred , sk , RandNym }
188
+ msp .signer = & idemixSigningIdentity {newIdemixIdentity (msp , Nym , role , ou , proof ), rng , cred , sk , RandNym , enrollmentId }
157
189
158
190
return nil
159
191
}
@@ -295,8 +327,8 @@ func (msp *idemixmsp) SatisfiesPrincipal(id Identity, principal *m.MSPPrincipal)
295
327
default :
296
328
return errors .Errorf ("invalid MSP role type %d" , int32 (mspRole .Role ))
297
329
}
298
- // in this case we have to serialize this instance
299
- // and compare it byte-by-byte with Principal
330
+ // in this case we have to serialize this instance
331
+ // and compare it byte-by-byte with Principal
300
332
case m .MSPPrincipal_IDENTITY :
301
333
mspLogger .Debugf ("Checking if identity satisfies IDENTITY principal" )
302
334
idBytes , err := id .Serialize ()
@@ -473,10 +505,11 @@ func (id *idemixidentity) Serialize() ([]byte, error) {
473
505
474
506
type idemixSigningIdentity struct {
475
507
* idemixidentity
476
- rng * amcl.RAND
477
- Cred * idemix.Credential
478
- Sk * FP256BN.BIG
479
- RandNym * FP256BN.BIG
508
+ rng * amcl.RAND
509
+ Cred * idemix.Credential
510
+ Sk * FP256BN.BIG
511
+ RandNym * FP256BN.BIG
512
+ enrollmentId string
480
513
}
481
514
482
515
func (id * idemixSigningIdentity ) Sign (msg []byte ) ([]byte , error ) {
0 commit comments