@@ -10,10 +10,12 @@ import (
1010 "bytes"
1111 "context"
1212 "crypto/sha256"
13+ "encoding/hex"
1314 "encoding/json"
1415 "errors"
1516 "fmt"
1617 "slices"
18+ "strconv"
1719 "strings"
1820
1921 "github.com/rs/zerolog"
@@ -393,6 +395,7 @@ func (proc *Processor) evilHackForLIDMutation(
393395 }
394396 newIndexMAC = concatAndHMAC (sha256 .New , keys .Index , indexBytes )
395397 currentKeyID := mutation .GetRecord ().GetKeyID ().GetID ()
398+ triedIndexMACs := map [string ]string {hex .EncodeToString (currentKeyID ): hex .EncodeToString (newIndexMAC )}
396399 for i := mutationNum - 1 ; i >= 0 ; i -- {
397400 newKeyID := prevMutations [i ].GetRecord ().GetKeyID ().GetID ()
398401 if ! bytes .Equal (currentKeyID , newKeyID ) {
@@ -402,6 +405,7 @@ func (proc *Processor) evilHackForLIDMutation(
402405 }
403406 currentKeyID = newKeyID
404407 newIndexMAC = concatAndHMAC (sha256 .New , keys .Index , indexBytes )
408+ triedIndexMACs [hex .EncodeToString (currentKeyID )] = hex .EncodeToString (newIndexMAC )
405409 }
406410 if bytes .Equal (prevMutations [i ].GetRecord ().GetIndex ().GetBlob (), newIndexMAC ) {
407411 if prevMutations [i ].GetOperation () == waServerSync .SyncdMutation_SET {
@@ -418,8 +422,9 @@ func (proc *Processor) evilHackForLIDMutation(
418422 if err == nil && newValueMAC == nil {
419423 var allKeys []* store.AppStateSyncKey
420424 allKeys , err = proc .Store .AppStateKeys .GetAllAppStateSyncKeys (ctx )
421- for _ , key := range allKeys {
425+ for i , key := range allKeys {
422426 altIndexMAC := concatAndHMAC (sha256 .New , expandAppStateKeys (key .Data ).Index , indexBytes )
427+ triedIndexMACs [strconv .Itoa (i )] = hex .EncodeToString (newIndexMAC )
423428 newValueMAC , err = proc .Store .AppState .GetAppStateMutationMAC (ctx , string (patchName ), altIndexMAC )
424429 if newValueMAC != nil {
425430 newIndexMAC = altIndexMAC
@@ -438,7 +443,7 @@ func (proc *Processor) evilHackForLIDMutation(
438443 Strs ("old_index" , index ).
439444 Hex ("old_index_mac" , oldIndexMAC ).
440445 Strs ("new_index" , newIndex ).
441- Hex ( "new_index_mac " , newIndexMAC ).
446+ Any ( "new_index_macs_attempted " , triedIndexMACs ).
442447 Msg ("DEBUG: No PN value MAC found for LID mutation" )
443448 } else {
444449 zerolog .Ctx (ctx ).Debug ().
@@ -448,6 +453,7 @@ func (proc *Processor) evilHackForLIDMutation(
448453 Strs ("new_index" , newIndex ).
449454 Hex ("new_index_mac" , newIndexMAC ).
450455 Hex ("value_mac" , newValueMAC ).
456+ Any ("new_index_macs_attempted" , triedIndexMACs ).
451457 Msg ("Found matching PN value MAC for new LID mutation, using it for evil hack" )
452458 }
453459 return
0 commit comments