Skip to content

Commit 27338cc

Browse files
authored
Auditor signatures should be verified when len(pp.Auditor) != 0 #1223 (#1235)
1 parent c06712c commit 27338cc

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

token/core/common/validator_auditing.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,24 @@ import (
1414
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
1515
)
1616

17+
var (
18+
ErrAuditorSignaturesMissing = errors.New("auditor signatures missing")
19+
ErrAuditorSignaturesPresent = errors.New("auditor signatures present")
20+
)
21+
1722
func AuditingSignaturesValidate[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](c context.Context, ctx *Context[P, T, TA, IA, DS]) error {
1823
if len(ctx.PP.Auditors()) == 0 {
1924
// enforce no auditor signatures are attached
2025
if len(ctx.TokenRequest.AuditorSignatures) != 0 {
21-
return errors.New("auditor signatures are not empty")
26+
return ErrAuditorSignaturesPresent
2227
}
2328
return nil
2429
}
2530

31+
if len(ctx.TokenRequest.AuditorSignatures) == 0 {
32+
return ErrAuditorSignaturesMissing
33+
}
34+
2635
auditors := ctx.PP.Auditors()
2736
for _, auditorSignature := range ctx.TokenRequest.AuditorSignatures {
2837
auditor := auditorSignature.Identity

token/core/common/validator_auditing_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestAuditingSignaturesValidate(t *testing.T) {
3131
{
3232
name: "No auditors but token requests with auditor signatures",
3333
err: true,
34-
errMsg: "auditor signatures are not empty",
34+
errMsg: ErrAuditorSignaturesPresent.Error(),
3535
context: func() (*TestContext, TestCheck) {
3636
pp := &mock.PublicParameters{}
3737
pp.AuditorsReturns(nil)
@@ -104,6 +104,30 @@ func TestAuditingSignaturesValidate(t *testing.T) {
104104
}, nil
105105
},
106106
},
107+
{
108+
name: "it is an auditor but no signatures to verify",
109+
err: true,
110+
errMsg: ErrAuditorSignaturesMissing.Error(),
111+
context: func() (*TestContext, TestCheck) {
112+
auditor := driver.Identity("auditor")
113+
pp := &mock.PublicParameters{}
114+
pp.AuditorsReturns([]identity.Identity{auditor})
115+
ver := &mock.Verifier{}
116+
ver.VerifyReturns(errors.New("signature is not valid"))
117+
des := &mock.Deserializer{}
118+
des.GetAuditorVerifierReturns(ver, nil)
119+
sp := &mock.SignatureProvider{}
120+
sp.HasBeenSignedByReturns(nil, errors.New("signature is not valid"))
121+
return &TestContext{
122+
PP: pp,
123+
TokenRequest: &driver.TokenRequest{
124+
AuditorSignatures: nil,
125+
},
126+
Deserializer: des,
127+
SignatureProvider: sp,
128+
}, nil
129+
},
130+
},
107131
{
108132
name: "it is an auditor but I cannot verify its signature",
109133
err: true,

0 commit comments

Comments
 (0)