diff --git a/mixmessages/digesttesthelper.go b/mixmessages/digesttesthelper.go index 485abef3f2d9c510b2b9165e20fe63ede78c9ad9..435650afe155c7d00e9e8eeda78d2fecbe48c1a8 100644 --- a/mixmessages/digesttesthelper.go +++ b/mixmessages/digesttesthelper.go @@ -45,7 +45,7 @@ func checkdigest(t *testing.T, gs signature.GenericRsaSignable) { valField := r.Field(i) typeField := r.Type().Field(i) - if typeField.Name == "EccSignature" || typeField.Name == "Signature" || typeField.Name == "state" || typeField.Name == "sizeCache" || typeField.Name == "unknownFields" || strings.Contains(typeField.Name, "XXX") { + if typeField.Name == "EccSignature" || typeField.Name == "Signature" || typeField.Name == "Errors" || typeField.Name == "state" || typeField.Name == "sizeCache" || typeField.Name == "unknownFields" || strings.Contains(typeField.Name, "XXX") { fmt.Printf("Skipping field.\n") continue } @@ -79,24 +79,6 @@ func checkdigest(t *testing.T, gs signature.GenericRsaSignable) { v := reflect.ValueOf(arr) valField.Set(v) - case []*RoundError: - randNodeId := make([]byte, 33) - rand.Read(randNodeId) - rea := []*RoundError{ - { - Id: rand.Uint64(), - NodeId: randNodeId, - Error: RandStringRunes(4), - }, - { - Id: rand.Uint64(), - NodeId: randNodeId, - Error: RandStringRunes(4), - }, - } - v := reflect.ValueOf(rea) - valField.Set(v) - case []*ClientError: randClientId := make([]byte, 33) rand.Read(randClientId) diff --git a/mixmessages/roundInfo.go b/mixmessages/roundInfo.go index dd0208abe76a5c38407bf3be427366b441f7b0bc..f528b9086e404fa75b46d0aeaf27b29ba4fd84f0 100644 --- a/mixmessages/roundInfo.go +++ b/mixmessages/roundInfo.go @@ -81,13 +81,6 @@ func (m *RoundInfo) Digest(nonce []byte, h hash.Hash) []byte { h.Write(data) } - // Hash the - for _, roundErr := range m.Errors { - sha := crypto.SHA256.New() - data := roundErr.Digest(nonce, sha) - h.Write(data) - } - // Hash nonce h.Write(nonce) diff --git a/network/dataStructures/round.go b/network/dataStructures/round.go index c38dc3649b26ead3327e45186bfd08302a511ef0..165bfaec9e154d239d74214901f80846ce6d4a2a 100644 --- a/network/dataStructures/round.go +++ b/network/dataStructures/round.go @@ -68,7 +68,8 @@ func (r *Round) Get() *pb.RoundInfo { if err != nil { jww.FATAL.Panicf("Could not validate "+ "the roundInfo signature: %+v: %v", r.info, err) - } } + } + } atomic.StoreUint32(r.needsValidation, 1) } diff --git a/network/dataStructures/roundData.go b/network/dataStructures/roundData.go index 10335a21d3ad789c38fd9131bb5719b90fd49961..1fb29abf32f7d8367155695f2c86950ba06d3f87 100644 --- a/network/dataStructures/roundData.go +++ b/network/dataStructures/roundData.go @@ -44,12 +44,12 @@ func (d *Data) UpsertRound(r *Round) error { func (d *Data) GetRound(id int) (*mixmessages.RoundInfo, error) { val, err := d.rounds.GetById(id) if err != nil { - return nil, errors.Wrapf(err, "Failed to get round by id with " + + return nil, errors.Wrapf(err, "Failed to get round by id with "+ "%d", id) } if val == nil { - return nil, errors.Errorf("Failed to get round by id with %d, " + + return nil, errors.Errorf("Failed to get round by id with %d, "+ "got nil round", id) } diff --git a/network/dataStructures/roundData_test.go b/network/dataStructures/roundData_test.go index d9e44c833fc6765b7dc04ed47a85348f9a930f71..430d223bc815aa69a7e71272a871a9188e0ab197 100644 --- a/network/dataStructures/roundData_test.go +++ b/network/dataStructures/roundData_test.go @@ -104,7 +104,7 @@ func TestData_ComparisonFunc(t *testing.T) { t.Errorf("Failed to load public key: %v", err) t.FailNow() } - roundOne := NewRound(roundInfoOne, pubKey, nil ) + roundOne := NewRound(roundInfoOne, pubKey, nil) _ = d.UpsertRound(roundOne) // Construct a mock round object diff --git a/network/dataStructures/roundUpdates.go b/network/dataStructures/roundUpdates.go index ee9ea2106fc247d3bcdfeaef57e7d951a484ff4e..57749889e87d0d751c0d67d2c7d1cab7781cc920 100644 --- a/network/dataStructures/roundUpdates.go +++ b/network/dataStructures/roundUpdates.go @@ -40,12 +40,12 @@ func (u *Updates) GetUpdate(id int) (*pb.RoundInfo, error) { val, err := u.updates.GetById(id) if err != nil { - return nil, errors.Wrapf(err, "Failed to get round by update " + + return nil, errors.Wrapf(err, "Failed to get round by update "+ "ID with id %d", id) } if val == nil { - return nil, errors.Errorf("Failed to get round by update ID " + + return nil, errors.Errorf("Failed to get round by update ID "+ "with id %d, got nil round", id) } diff --git a/network/dataStructures/roundUpdates_test.go b/network/dataStructures/roundUpdates_test.go index 8f8b82546ade9e65dc1dd1e48b5f1ac1d899d199..e69cca7707e0771094158c2d50034dd75cd89c84 100644 --- a/network/dataStructures/roundUpdates_test.go +++ b/network/dataStructures/roundUpdates_test.go @@ -13,6 +13,7 @@ import ( "testing" ) +// Unit test func TestUpdates_AddRound(t *testing.T) { u := NewUpdates() // Construct a mock round object @@ -34,6 +35,7 @@ func TestUpdates_AddRound(t *testing.T) { } } +// Unit test func TestUpdates_GetUpdate(t *testing.T) { u := NewUpdates() updateID := 3 @@ -64,23 +66,31 @@ func TestUpdates_GetUpdate(t *testing.T) { } } +// Unit test func TestUpdates_GetUpdates(t *testing.T) { u := NewUpdates() + + pubKey, err := testutils.LoadPublicKeyTesting(t) + if err != nil { + t.Errorf("Failed to load public key: %v", err) + t.FailNow() + } + ecKey, _ := testutils.LoadEllipticPublicKey() + updateID := 3 // Construct a mock round object roundInfoOne := &mixmessages.RoundInfo{ ID: 0, UpdateID: uint64(updateID), } + + // Sign the round on the keys if err := testutils.SignRoundInfoRsa(roundInfoOne, t); err != nil { t.Errorf("Failed to sign mock round info: %v", err) } - pubKey, err := testutils.LoadPublicKeyTesting(t) - if err != nil { - t.Errorf("Failed to load public key: %v", err) - t.FailNow() + if err := testutils.SignRoundInfoEddsa(roundInfoOne, ecKey, t); err != nil { + t.Errorf("Failed to sign mock round info: %v", err) } - ecKey, _ := testutils.LoadEllipticPublicKey() roundOne := NewRound(roundInfoOne, pubKey, ecKey.PublicKey()) @@ -92,6 +102,9 @@ func TestUpdates_GetUpdates(t *testing.T) { if err := testutils.SignRoundInfoRsa(roundInfoTwo, t); err != nil { t.Errorf("Failed to sign mock round info: %v", err) } + if err := testutils.SignRoundInfoEddsa(roundInfoTwo, ecKey, t); err != nil { + t.Errorf("Failed to sign mock round info: %v", err) + } roundTwo := NewRound(roundInfoTwo, pubKey, ecKey.PublicKey()) diff --git a/network/dataStructures/round_test.go b/network/dataStructures/round_test.go index 42481c12939c6b3b09bb70290b0bf49ecaebbba8..8c52a4907c0c08ab7f89dfeef1f301178a9df946 100644 --- a/network/dataStructures/round_test.go +++ b/network/dataStructures/round_test.go @@ -28,7 +28,7 @@ func TestNewRound(t *testing.T) { "\n\tExpected round info: %v"+ "\n\tReceived round info: %v"+ "\n\tExpected rsa public key: %v"+ - "\n\tReceived rsa public key: %v" + + "\n\tReceived rsa public key: %v"+ "\n\tExpected EC public key: %v"+ "\n\tReceived EC public key: %v", ri, rnd.info, pubKey, rnd.rsaPubKey, ecKey, rnd.ecPubKey) diff --git a/network/instance.go b/network/instance.go index 1a1b0fd96e307edd169dfa4bd03a83dacae9b391..95859bcda503a7481b88662c4b58345c86e90709 100644 --- a/network/instance.go +++ b/network/instance.go @@ -165,7 +165,7 @@ func NewInstance(c *connect.ProtoComms, partial, full *ndf.NetworkDefinition, er cmixGroup: ds.NewGroup(), e2eGroup: ds.NewGroup(), - ipOverride: ds.NewIpOverrideList(), + ipOverride: ds.NewIpOverrideList(), useElliptic: useElliptic, } diff --git a/network/instance_test.go b/network/instance_test.go index b41eab67da7aa9776813af991e257f6a1db6c23c..b9611d3537a79b65a9f54adf9c8efb5b3196bcf3 100644 --- a/network/instance_test.go +++ b/network/instance_test.go @@ -237,7 +237,7 @@ func TestInstance_GetRoundUpdates(t *testing.T) { testutils.SignRoundInfoRsa(roundInfoOne, t) roundInfoTwo := &mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(2)} testutils.SignRoundInfoRsa(roundInfoTwo, t) - roundOne := ds.NewRound(roundInfoOne, pubKey, nil ) + roundOne := ds.NewRound(roundInfoOne, pubKey, nil) roundTwo := ds.NewRound(roundInfoTwo, pubKey, nil) _ = i.roundUpdates.AddRound(roundOne) diff --git a/testutils/utils.go b/testutils/utils.go index d2f305930972cb333fe90bc8b6f459071fb541b0..714a74cea8a33126e0bc76f01c0319aef4d55122 100644 --- a/testutils/utils.go +++ b/testutils/utils.go @@ -102,7 +102,7 @@ func SignRoundInfoRsa(ri *pb.RoundInfo, i interface{}) error { return nil } -func SignRoundInfoEddsa(ri *pb.RoundInfo,key *eddsa.PrivateKey, i interface{}) error { +func SignRoundInfoEddsa(ri *pb.RoundInfo, key *eddsa.PrivateKey, i interface{}) error { switch i.(type) { case *testing.T: break @@ -119,4 +119,4 @@ func SignRoundInfoEddsa(ri *pb.RoundInfo,key *eddsa.PrivateKey, i interface{}) e } return nil -} \ No newline at end of file +}