Skip to content

Commit 9404c2b

Browse files
author
Jason Yellick
committed
[FAB-4830] cauthdsl signature verify err unlogged
We have seen in a number of bug reports, such as FAB-4827 that the output provided by cauthdsl in the logs is cryptic, and hard to debug from. Additionally, the error returned by the signature verification is not actually logged, which makes conclusive debugging nearly impossible. This CR reworks the logging messages to be more uniform, less cryptic, and logs the particular err which was ignored. Change-Id: I229ee62be881d5d136a4532174990386d644853e Signed-off-by: Jason Yellick <[email protected]>
1 parent 012f721 commit 9404c2b

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

common/cauthdsl/cauthdsl.go

+28-18
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ package cauthdsl
1818

1919
import (
2020
"fmt"
21+
"time"
2122

2223
"github.com/hyperledger/fabric/common/flogging"
2324
"github.com/hyperledger/fabric/msp"
2425
cb "github.com/hyperledger/fabric/protos/common"
2526
mb "github.com/hyperledger/fabric/protos/msp"
27+
28+
"github.com/op/go-logging"
2629
)
2730

2831
var cauthdslLogger = flogging.MustGetLogger("cauthdsl")
@@ -45,7 +48,8 @@ func compile(policy *cb.SignaturePolicy, identities []*mb.MSPPrincipal, deserial
4548

4649
}
4750
return func(signedData []*cb.SignedData, used []bool) bool {
48-
cauthdslLogger.Debugf("Gate evaluation starts: (%v)", t)
51+
grepKey := time.Now().UnixNano()
52+
cauthdslLogger.Debugf("%p gate %d evaluation starts", signedData, grepKey)
4953
verified := int32(0)
5054
_used := make([]bool, len(used))
5155
for _, policy := range policies {
@@ -57,44 +61,50 @@ func compile(policy *cb.SignaturePolicy, identities []*mb.MSPPrincipal, deserial
5761
}
5862

5963
if verified >= t.NOutOf.N {
60-
cauthdslLogger.Debugf("Gate evaluation succeeds: (%v)", t)
64+
cauthdslLogger.Debugf("%p gate %d evaluation succeeds", signedData, grepKey)
6165
} else {
62-
cauthdslLogger.Debugf("Gate evaluation fails: (%v)", t)
66+
cauthdslLogger.Debugf("%p gate %d evaluation fails", signedData, grepKey)
6367
}
6468

6569
return verified >= t.NOutOf.N
6670
}, nil
6771
case *cb.SignaturePolicy_SignedBy:
6872
if t.SignedBy < 0 || t.SignedBy >= int32(len(identities)) {
69-
return nil, fmt.Errorf("Identity index out of range, requested %v, but identies length is %d", t.SignedBy, len(identities))
73+
return nil, fmt.Errorf("identity index out of range, requested %v, but identies length is %d", t.SignedBy, len(identities))
7074
}
7175
signedByID := identities[t.SignedBy]
7276
return func(signedData []*cb.SignedData, used []bool) bool {
73-
cauthdslLogger.Debugf("Principal evaluation starts: (%v) (used %v)", t, used)
77+
cauthdslLogger.Debugf("%p signed by %d principal evaluation starts (used %v)", signedData, t.SignedBy, used)
7478
for i, sd := range signedData {
7579
if used[i] {
80+
cauthdslLogger.Debugf("%p skipping identity %d because it has already been used", signedData, i)
7681
continue
7782
}
83+
if cauthdslLogger.IsEnabledFor(logging.DEBUG) {
84+
// Unlike most places, this is a huge print statement, and worth checking log level before create garbage
85+
cauthdslLogger.Debugf("%p processing identity %d with bytes of %x", signedData, i, sd.Identity)
86+
}
7887
identity, err := deserializer.DeserializeIdentity(sd.Identity)
7988
if err != nil {
80-
cauthdslLogger.Errorf("Principal deserialization failed: (%s) for identity %v", err, sd.Identity)
89+
cauthdslLogger.Errorf("Principal deserialization failure (%s) for identity %x", err, sd.Identity)
8190
continue
8291
}
8392
err = identity.SatisfiesPrincipal(signedByID)
84-
if err == nil {
85-
cauthdslLogger.Debugf("Principal matched by identity: (%v) for %v", t, sd.Identity)
86-
err = identity.Verify(sd.Data, sd.Signature)
87-
if err == nil {
88-
used[i] = true
89-
cauthdslLogger.Debugf("Principal evaluation succeeds: (%v) (used %v)", t, used)
90-
return true
91-
}
92-
cauthdslLogger.Debugf("Invalid signature for identity: (%v)", t)
93-
} else {
94-
cauthdslLogger.Debugf("Identity (%v) does not satisfy principal: %s", sd.Identity, err)
93+
if err != nil {
94+
cauthdslLogger.Debugf("%p identity %d does not satisfy principal: %s", signedData, i, err)
95+
continue
96+
}
97+
cauthdslLogger.Debugf("%p principal matched by identity %d", signedData, i)
98+
err = identity.Verify(sd.Data, sd.Signature)
99+
if err != nil {
100+
cauthdslLogger.Debugf("%p signature for identity %d is invalid: %s", signedData, i, err)
101+
continue
95102
}
103+
cauthdslLogger.Debugf("%p principal evaluation succeeds for identity %d", signedData, i)
104+
used[i] = true
105+
return true
96106
}
97-
cauthdslLogger.Debugf("Principal evaluation fails: (%v) %v", t, used)
107+
cauthdslLogger.Debugf("%p principal evaluation fails", signedData)
98108
return false
99109
}, nil
100110
default:

common/cauthdsl/cauthdsl_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ import (
2626
mb "github.com/hyperledger/fabric/protos/msp"
2727

2828
"github.com/golang/protobuf/proto"
29+
logging "github.com/op/go-logging"
2930
"github.com/stretchr/testify/assert"
3031
)
3132

33+
func init() {
34+
logging.SetLevel(logging.DEBUG, "")
35+
}
36+
3237
var invalidSignature = []byte("badsigned")
3338

3439
type mockIdentity struct {

0 commit comments

Comments
 (0)