From eda46adc302b33083d273f885f00d845dd4da2a4 Mon Sep 17 00:00:00 2001 From: josh <josh@elixxir.io> Date: Fri, 20 Aug 2021 11:00:45 -0700 Subject: [PATCH] Add fact signature to RemoveFact Also fixed formatting --- api/client.go | 1 - bindings/ud.go | 2 +- cmd/init.go | 4 +- go.mod | 2 +- go.sum | 2 + network/gateway/hostPool.go | 6 +-- network/rounds/remoteFilters_test.go | 62 ++++++++++++++-------------- ud/remove.go | 18 +++++++- ud/remove_test.go | 2 +- ud/search.go | 2 +- 10 files changed, 57 insertions(+), 44 deletions(-) diff --git a/api/client.go b/api/client.go index a4d144f4c..6cb478653 100644 --- a/api/client.go +++ b/api/client.go @@ -246,7 +246,6 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie // initialize the auth tracker c.auth = auth.NewManager(c.switchboard, c.storage, c.network) - // Add all processes to the followerServices err = c.registerFollower() if err != nil { diff --git a/bindings/ud.go b/bindings/ud.go index 3cef1cf5a..5fdb2cd0e 100644 --- a/bindings/ud.go +++ b/bindings/ud.go @@ -33,7 +33,7 @@ type UserDiscovery struct { // This must be called while start network follower is running. func NewUserDiscovery(client *Client) (*UserDiscovery, error) { single, err := client.getSingle() - if err!=nil{ + if err != nil { return nil, errors.WithMessage(err, "Failed to create User Discovery Manager") } m, err := ud.NewManager(&client.api, single) diff --git a/cmd/init.go b/cmd/init.go index b00f21547..9a10595e5 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -11,8 +11,8 @@ package cmd import ( "fmt" "github.com/spf13/cobra" - "github.com/spf13/viper" jww "github.com/spf13/jwalterweatherman" + "github.com/spf13/viper" ) // initCmd creates a new user object with the given NDF @@ -31,7 +31,7 @@ var initCmd = &cobra.Command{ func init() { initCmd.Flags().StringP("userid-prefix", "", "", - "Desired prefix of userID to brute force when running init command. Prepend (?i) for case-insensitive. Only Base64 characters are valid.") + "Desired prefix of userID to brute force when running init command. Prepend (?i) for case-insensitive. Only Base64 characters are valid.") _ = viper.BindPFlag("userid-prefix", initCmd.Flags().Lookup("userid-prefix")) rootCmd.AddCommand(initCmd) diff --git a/go.mod b/go.mod index 98be3827b..5c8f4b490 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/viper v1.7.1 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 - gitlab.com/elixxir/comms v0.0.4-0.20210820163054-c177e37ef3d1 + gitlab.com/elixxir/comms v0.0.4-0.20210820174341-535c11488dd0 gitlab.com/elixxir/crypto v0.0.7-0.20210803232056-ba3ff44cc618 gitlab.com/elixxir/ekv v0.1.5 gitlab.com/elixxir/primitives v0.0.3-0.20210803231939-7b924f78eaac diff --git a/go.sum b/go.sum index ffaa8f3a0..d8c577234 100644 --- a/go.sum +++ b/go.sum @@ -253,6 +253,8 @@ gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= gitlab.com/elixxir/comms v0.0.4-0.20210820163054-c177e37ef3d1 h1:NthGhjTb+oEy4KR0Lmbk8Oq12/Xeai9UvvDEHyQy4+Y= gitlab.com/elixxir/comms v0.0.4-0.20210820163054-c177e37ef3d1/go.mod h1:1fHnPjj5Sv2qfnQplu8+BKlehQy54vtgM7khp5axXMU= +gitlab.com/elixxir/comms v0.0.4-0.20210820174341-535c11488dd0 h1:gapAJ4Fi8jRDwkpgsb6r2hpi0xXMMRYBv5Jf1B8kwM4= +gitlab.com/elixxir/comms v0.0.4-0.20210820174341-535c11488dd0/go.mod h1:1fHnPjj5Sv2qfnQplu8+BKlehQy54vtgM7khp5axXMU= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.7-0.20210803232056-ba3ff44cc618 h1:Z1SI2a8mXP4Zf2xfhURT1Hbmtq3tufTdebNLgCdlufg= diff --git a/network/gateway/hostPool.go b/network/gateway/hostPool.go index c5ecac1b1..faf07cad6 100644 --- a/network/gateway/hostPool.go +++ b/network/gateway/hostPool.go @@ -43,9 +43,9 @@ type HostManager interface { // Filter filters out IDs from the provided map based on criteria in the NDF. // The passed in map is a map of the NDF for easier acesss. The map is ID -> index in the NDF -// There is no multithreading, the filter function can either edit the passed map or make a new one -// and return it. The general pattern is to loop through the map, then look up data about the node -// in the ndf to make a filtering decision, then add them to a new map if they are accepted. +// There is no multithreading, the filter function can either edit the passed map or make a new one +// and return it. The general pattern is to loop through the map, then look up data about the node +// in the ndf to make a filtering decision, then add them to a new map if they are accepted. type Filter func(map[id.ID]int, *ndf.NetworkDefinition) map[id.ID]int // HostPool Handles providing hosts to the Client diff --git a/network/rounds/remoteFilters_test.go b/network/rounds/remoteFilters_test.go index 5a5e381e0..73ce8476b 100644 --- a/network/rounds/remoteFilters_test.go +++ b/network/rounds/remoteFilters_test.go @@ -40,13 +40,13 @@ func TestRemoteFilter_GetFilter(t *testing.T) { testFilter, err := bloom.InitByParameters(interfaces.BloomFilterSize, interfaces.BloomFilterHashes) if err != nil { - t.Fatalf("GetFilter error: " + + t.Fatalf("GetFilter error: "+ "Cannot initialize bloom filter for setup: %v", err) } data, err := testFilter.MarshalBinary() if err != nil { - t.Fatalf("GetFilter error: " + + t.Fatalf("GetFilter error: "+ "Cannot marshal filter for setup: %v", err) } @@ -59,8 +59,8 @@ func TestRemoteFilter_GetFilter(t *testing.T) { rf := NewRemoteFilter(bloomFilter) retrievedFilter := rf.GetFilter() if !reflect.DeepEqual(retrievedFilter, testFilter) { - t.Fatalf("GetFilter error: " + - "Did not retrieve expected filter." + + t.Fatalf("GetFilter error: "+ + "Did not retrieve expected filter."+ "\n\tExpected: %v\n\tReceived: %v", testFilter, retrievedFilter) } } @@ -79,17 +79,17 @@ func TestRemoteFilter_FirstLastRound(t *testing.T) { // Test FirstRound receivedFirstRound := rf.FirstRound() if receivedFirstRound != id.Round(firstRound) { - t.Fatalf("FirstRound error: " + - "Did not receive expected round." + + t.Fatalf("FirstRound error: "+ + "Did not receive expected round."+ "\n\tExpected: %v\n\tReceived: %v", firstRound, receivedFirstRound) } // Test LastRound receivedLastRound := rf.LastRound() - if receivedLastRound != id.Round(firstRound + uint64(roundRange)) { - t.Fatalf("LastRound error: " + - "Did not receive expected round." + - "\n\tExpected: %v\n\tReceived: %v", receivedLastRound, firstRound + uint64(roundRange)) + if receivedLastRound != id.Round(firstRound+uint64(roundRange)) { + t.Fatalf("LastRound error: "+ + "Did not receive expected round."+ + "\n\tExpected: %v\n\tReceived: %v", receivedLastRound, firstRound+uint64(roundRange)) } } @@ -101,13 +101,13 @@ func TestValidFilterRange(t *testing.T) { testFilter, err := bloom.InitByParameters(interfaces.BloomFilterSize, interfaces.BloomFilterHashes) if err != nil { - t.Fatalf("GetFilter error: " + + t.Fatalf("GetFilter error: "+ "Cannot initialize bloom filter for setup: %v", err) } data, err := testFilter.MarshalBinary() if err != nil { - t.Fatalf("GetFilter error: " + + t.Fatalf("GetFilter error: "+ "Cannot marshal filter for setup: %v", err) } @@ -116,14 +116,13 @@ func TestValidFilterRange(t *testing.T) { requestGateway := id.NewIdFromString(ReturningGateway, id.Gateway, t) iu := reception.IdentityUse{ Identity: reception.Identity{ - EphId: expectedEphID, - Source: requestGateway, - StartValid: time.Now().Add(12*time.Hour), - EndValid: time.Now().Add(24*time.Hour), + EphId: expectedEphID, + Source: requestGateway, + StartValid: time.Now().Add(12 * time.Hour), + EndValid: time.Now().Add(24 * time.Hour), }, } - bloomFilter := &mixmessages.ClientBloom{ Filter: data, FirstRound: firstRound, @@ -131,9 +130,9 @@ func TestValidFilterRange(t *testing.T) { } msg := &mixmessages.ClientBlooms{ - Period: int64(12 * time.Hour ), + Period: int64(12 * time.Hour), FirstTimestamp: time.Now().UnixNano(), - Filters: []*mixmessages.ClientBloom{bloomFilter}, + Filters: []*mixmessages.ClientBloom{bloomFilter}, } start, end, outOfBounds := ValidFilterRange(iu, msg) @@ -143,9 +142,9 @@ func TestValidFilterRange(t *testing.T) { } if start != 0 && end != 1 { - t.Errorf("ValidFilterRange error: " + - "Unexpected indices returned. " + - "\n\tExpected start: %v\n\tReceived start: %v" + + t.Errorf("ValidFilterRange error: "+ + "Unexpected indices returned. "+ + "\n\tExpected start: %v\n\tReceived start: %v"+ "\n\tExpected end: %v\n\tReceived end: %v", 0, start, 1, end) } @@ -158,13 +157,13 @@ func TestValidFilterRange_OutBounds(t *testing.T) { testFilter, err := bloom.InitByParameters(interfaces.BloomFilterSize, interfaces.BloomFilterHashes) if err != nil { - t.Fatalf("GetFilter error: " + + t.Fatalf("GetFilter error: "+ "Cannot initialize bloom filter for setup: %v", err) } data, err := testFilter.MarshalBinary() if err != nil { - t.Fatalf("GetFilter error: " + + t.Fatalf("GetFilter error: "+ "Cannot marshal filter for setup: %v", err) } @@ -173,14 +172,13 @@ func TestValidFilterRange_OutBounds(t *testing.T) { requestGateway := id.NewIdFromString(ReturningGateway, id.Gateway, t) iu := reception.IdentityUse{ Identity: reception.Identity{ - EphId: expectedEphID, - Source: requestGateway, - StartValid: time.Now().Add(-24*time.Hour), - EndValid: time.Now().Add(-36*time.Hour), + EphId: expectedEphID, + Source: requestGateway, + StartValid: time.Now().Add(-24 * time.Hour), + EndValid: time.Now().Add(-36 * time.Hour), }, } - bloomFilter := &mixmessages.ClientBloom{ Filter: data, FirstRound: firstRound, @@ -188,9 +186,9 @@ func TestValidFilterRange_OutBounds(t *testing.T) { } msg := &mixmessages.ClientBlooms{ - Period: int64(12 * time.Hour ), + Period: int64(12 * time.Hour), FirstTimestamp: time.Now().UnixNano(), - Filters: []*mixmessages.ClientBloom{bloomFilter}, + Filters: []*mixmessages.ClientBloom{bloomFilter}, } _, _, outOfBounds := ValidFilterRange(iu, msg) @@ -199,4 +197,4 @@ func TestValidFilterRange_OutBounds(t *testing.T) { "Range should be out of bounds") } -} \ No newline at end of file +} diff --git a/ud/remove.go b/ud/remove.go index 28fd0ebf2..69514a579 100644 --- a/ud/remove.go +++ b/ud/remove.go @@ -1,16 +1,20 @@ package ud import ( + "crypto/rand" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/comms/mixmessages" + "gitlab.com/elixxir/crypto/factID" + "gitlab.com/elixxir/crypto/hash" "gitlab.com/elixxir/primitives/fact" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/messages" + "gitlab.com/xx_network/crypto/signature/rsa" ) type removeFactComms interface { - SendDeleteMessage(host *connect.Host, message *mixmessages.FactRemovalRequest) (*messages.Ack, error) + SendRemoveFact(host *connect.Host, message *mixmessages.FactRemovalRequest) (*messages.Ack, error) } // Removes a previously confirmed fact. Will fail if the fact is not @@ -33,14 +37,24 @@ func (m *Manager) removeFact(fact fact.Fact, rFC removeFactComms) error { FactType: uint32(fact.T), } + // Create a hash of our fact + fhash := factID.Fingerprint(fact) + + // Sign our inFact for putting into the request + fsig, err := rsa.Sign(rand.Reader, m.privKey, hash.CMixHash, fhash, nil) + if err != nil { + return err + } + // Create our Fact Removal Request message data remFactMsg := mixmessages.FactRemovalRequest{ UID: m.myID.Marshal(), RemovalData: &mmFact, + FactSig: fsig, } // Send the message - _, err := rFC.SendDeleteMessage(m.host, &remFactMsg) + _, err = rFC.SendRemoveFact(m.host, &remFactMsg) // Return the error return err diff --git a/ud/remove_test.go b/ud/remove_test.go index bfe30a77d..2adf4c976 100644 --- a/ud/remove_test.go +++ b/ud/remove_test.go @@ -13,7 +13,7 @@ import ( type testRFC struct{} -func (rFC *testRFC) SendDeleteMessage(host *connect.Host, message *pb.FactRemovalRequest) (*messages.Ack, error) { +func (rFC *testRFC) SendRemoveFact(host *connect.Host, message *pb.FactRemovalRequest) (*messages.Ack, error) { return &messages.Ack{}, nil } diff --git a/ud/search.go b/ud/search.go index 8c95c0866..b51c7e1b8 100644 --- a/ud/search.go +++ b/ud/search.go @@ -74,7 +74,7 @@ func (m *Manager) searchResponseHandler(factMap map[string]fact.Fact, } //return an error if no facts are found - if len(searchResponse.Contacts)==0{ + if len(searchResponse.Contacts) == 0 { go callback(nil, errors.New("No contacts found in search")) } -- GitLab