Skip to content

Commit fc6eaa7

Browse files
committed
fix(token): preserve auditor signatures in Request.SetSignatures
Since #1717 action and auditor signatures share the unified Actions.Signatures slice, but SetSignatures still assigned the whole field, silently dropping auditor signatures attached beforehand via AddAuditorSignature. Endorsement then fails with 'auditor signatures missing' when auditing runs before endorsement collection. Preserve existing auditor entries when assigning action signatures, restoring the pre-#1717 order-independence of the two calls. Fixes #1897 Signed-off-by: YanYuan <yan950414@gmail.com>
1 parent 8462aef commit fc6eaa7

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

token/request.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,7 @@ func (r *Request) AddAuditorSignature(identity Identity, sigma []byte) {
11701170

11711171
// SetSignatures assigns signatures to all signers. Returns true if all signatures are present.
11721172
// This method now correctly preserves the action context by using SignerWithAction information.
1173+
// Auditor signatures already attached to the request are preserved.
11731174
func (r *Request) SetSignatures(sigmas map[string][]byte) bool {
11741175
issueSignersWithActions := r.IssueSignersWithActions()
11751176
transferSignersWithActions := r.TransferSignersWithActions()
@@ -1198,6 +1199,13 @@ func (r *Request) SetSignatures(sigmas map[string][]byte) bool {
11981199
signatures = append(signatures, signature)
11991200
}
12001201

1202+
// preserve auditor signatures attached before this call, e.g., via AddAuditorSignature
1203+
for _, signature := range r.Actions.Signatures {
1204+
if signature != nil && signature.Auditor != nil {
1205+
signatures = append(signatures, signature)
1206+
}
1207+
}
1208+
12011209
r.Actions.Signatures = signatures
12021210

12031211
return all

token/request_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,57 @@ func TestRequest_SetSignatures(t *testing.T) {
966966
assert.Nil(t, r.Actions.Signatures[1].Action.Signature)
967967
}
968968

969+
// TestRequest_SetSignatures_PreservesAuditorSignatures tests that SetSignatures
970+
// keeps auditor signatures attached before it is called
971+
func TestRequest_SetSignatures_PreservesAuditorSignatures(t *testing.T) {
972+
r := &Request{
973+
Actions: &driver.TokenRequest{
974+
Actions: []*driver.TypedAction{
975+
{Type: request.ActionType_ACTION_TYPE_ISSUE, Raw: []byte("issue1")},
976+
},
977+
},
978+
Metadata: &driver.TokenRequestMetadata{
979+
Actions: []*driver.ActionMetadataEntry{
980+
{
981+
ActionID: 0,
982+
IssueMetadata: &driver.IssueMetadata{
983+
Issuer: driver.AuditableIdentity{
984+
Identity: Identity("issuer1"),
985+
},
986+
},
987+
},
988+
},
989+
},
990+
TokenService: &ManagementService{
991+
logger: logging.MustGetLogger(),
992+
},
993+
}
994+
995+
r.AddAuditorSignature(Identity("auditor1"), []byte("auditor-sig"))
996+
997+
allPresent := r.SetSignatures(map[string][]byte{
998+
Identity("issuer1").UniqueID(): []byte("sig1"),
999+
})
1000+
assert.True(t, allPresent)
1001+
require.Len(t, r.Actions.Signatures, 2)
1002+
require.NotNil(t, r.Actions.Signatures[0].Action)
1003+
assert.Equal(t, []byte("sig1"), r.Actions.Signatures[0].Action.Signature)
1004+
require.NotNil(t, r.Actions.Signatures[1].Auditor)
1005+
assert.Equal(t, Identity("auditor1"), r.Actions.Signatures[1].Auditor.Identity)
1006+
assert.Equal(t, []byte("auditor-sig"), r.Actions.Signatures[1].Auditor.Signature)
1007+
1008+
// calling SetSignatures again must not duplicate the auditor signature
1009+
allPresent = r.SetSignatures(map[string][]byte{
1010+
Identity("issuer1").UniqueID(): []byte("sig2"),
1011+
})
1012+
assert.True(t, allPresent)
1013+
require.Len(t, r.Actions.Signatures, 2)
1014+
require.NotNil(t, r.Actions.Signatures[0].Action)
1015+
assert.Equal(t, []byte("sig2"), r.Actions.Signatures[0].Action.Signature)
1016+
require.NotNil(t, r.Actions.Signatures[1].Auditor)
1017+
assert.Equal(t, Identity("auditor1"), r.Actions.Signatures[1].Auditor.Identity)
1018+
}
1019+
9691020
// TestRequest_cleanupInputIDs tests the cleanupInputIDs utility function
9701021
func TestRequest_cleanupInputIDs(t *testing.T) {
9711022
r := &Request{}

0 commit comments

Comments
 (0)