@@ -19,12 +19,9 @@ package cauthdsl
1919import (
2020 "fmt"
2121
22- "bytes"
23-
2422 "github.com/hyperledger/fabric/msp"
2523 cb "github.com/hyperledger/fabric/protos/common"
2624 "github.com/op/go-logging"
27- "github.com/syndtr/goleveldb/leveldb/errors"
2825)
2926
3027var cauthdslLogger = logging .MustGetLogger ("cauthdsl" )
@@ -73,13 +70,16 @@ func compile(policy *cb.SignaturePolicy, identities []*cb.MSPPrincipal, deserial
7370 if used [i ] {
7471 continue
7572 }
76- // FIXME: what should I do with the error below?
77- identity , _ := deserializer .DeserializeIdentity (sd .Identity )
78- err := identity .SatisfiesPrincipal (signedByID )
73+ identity , err := deserializer .DeserializeIdentity (sd .Identity )
74+ if err != nil {
75+ cauthdslLogger .Errorf ("Principal deserialization failed: (%s) for identity %v" , err , sd .Identity )
76+ continue
77+ }
78+ err = identity .SatisfiesPrincipal (signedByID )
7979 if err == nil {
8080 err := identity .Verify (sd .Data , sd .Signature )
8181 if err == nil {
82- cauthdslLogger .Debugf ("Principal evaluation succeeds: (%s)" , t , used )
82+ cauthdslLogger .Debugf ("Principal evaluation succeeds: (%s) (used %s) " , t , used )
8383 used [i ] = true
8484 return true
8585 }
@@ -92,77 +92,3 @@ func compile(policy *cb.SignaturePolicy, identities []*cb.MSPPrincipal, deserial
9292 return nil , fmt .Errorf ("Unknown type: %T:%v" , t , t )
9393 }
9494}
95-
96- // FIXME: remove the code below as soon as we can use MSP from the policy manager code
97- var invalidSignature = []byte ("badsigned" )
98-
99- type mockIdentity struct {
100- idBytes []byte
101- }
102-
103- func (id * mockIdentity ) SatisfiesPrincipal (p * cb.MSPPrincipal ) error {
104- if bytes .Compare (id .idBytes , p .Principal ) == 0 {
105- return nil
106- } else {
107- return errors .New ("Principals do not match" )
108- }
109- }
110-
111- func (id * mockIdentity ) GetIdentifier () * msp.IdentityIdentifier {
112- return & msp.IdentityIdentifier {Mspid : "Mock" , Id : "Bob" }
113- }
114-
115- func (id * mockIdentity ) GetMSPIdentifier () string {
116- return "Mock"
117- }
118-
119- func (id * mockIdentity ) Validate () error {
120- return nil
121- }
122-
123- func (id * mockIdentity ) GetOrganizationalUnits () []string {
124- return []string {"dunno" }
125- }
126-
127- func (id * mockIdentity ) Verify (msg []byte , sig []byte ) error {
128- if bytes .Compare (sig , invalidSignature ) == 0 {
129- return errors .New ("Invalid signature" )
130- } else {
131- return nil
132- }
133- }
134-
135- func (id * mockIdentity ) VerifyOpts (msg []byte , sig []byte , opts msp.SignatureOpts ) error {
136- return nil
137- }
138-
139- func (id * mockIdentity ) VerifyAttributes (proof []byte , spec * msp.AttributeProofSpec ) error {
140- return nil
141- }
142-
143- func (id * mockIdentity ) Serialize () ([]byte , error ) {
144- return id .idBytes , nil
145- }
146-
147- func toSignedData (data [][]byte , identities [][]byte , signatures [][]byte ) ([]* cb.SignedData , []bool ) {
148- signedData := make ([]* cb.SignedData , len (data ))
149- for i := range signedData {
150- signedData [i ] = & cb.SignedData {
151- Data : data [i ],
152- Identity : identities [i ],
153- Signature : signatures [i ],
154- }
155- }
156- return signedData , make ([]bool , len (signedData ))
157- }
158-
159- type mockDeserializer struct {
160- }
161-
162- func NewMockDeserializer () msp.IdentityDeserializer {
163- return & mockDeserializer {}
164- }
165-
166- func (md * mockDeserializer ) DeserializeIdentity (serializedIdentity []byte ) (msp.Identity , error ) {
167- return & mockIdentity {idBytes : serializedIdentity }, nil
168- }
0 commit comments