diff --git a/cmd/ud.go b/cmd/ud.go index 4666cba3fec19f620b0903e191c3955b2b42439a..b213d52c32c6373bbc945a34d66a25be63685627 100644 --- a/cmd/ud.go +++ b/cmd/ud.go @@ -78,14 +78,13 @@ var udCmd = &cobra.Command{ waitUntilConnected(connected) // Make user discovery manager - stream := client.GetRng().GetStream() - defer stream.Close() + rng := client.GetRng() userToRegister := viper.GetString("register") userDiscoveryMgr, err := ud.NewManager(client.GetCmix(), client.GetE2E(), client.NetworkFollowerStatus, client.GetEventReporter(), client.GetComms(), client.GetStorage(), - stream, + rng, userToRegister, client.GetStorage().GetKV()) if err != nil { if strings.Contains(err.Error(), ud.IsRegisteredErr) { @@ -163,12 +162,15 @@ var udCmd = &cobra.Command{ } printContact(newContact) } + + stream := rng.GetStream() _, _, err = ud.Lookup(client.GetCmix(), stream, client.GetE2E().GetGroup(), udContact, cb, lookupID, single.GetDefaultRequestParams()) if err != nil { jww.WARN.Printf("Failed UD lookup: %+v", err) } + stream.Close() time.Sleep(31 * time.Second) } @@ -256,6 +258,8 @@ var udCmd = &cobra.Command{ } } + stream := rng.GetStream() + defer stream.Close() _, _, err = ud.Search(client.GetCmix(), client.GetEventReporter(), stream, client.GetE2E().GetGroup(), diff --git a/ud/addFact.go b/ud/addFact.go index 6412e94b308871e9aa7266b2176e39cb8f169376..3c2b0af5428d71c57fd5f80cc3a0b5657bc9cccc 100644 --- a/ud/addFact.go +++ b/ud/addFact.go @@ -1,7 +1,6 @@ package ud import ( - "crypto/rand" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" pb "gitlab.com/elixxir/comms/mixmessages" @@ -47,7 +46,9 @@ func (m *Manager) addFact(inFact fact.Fact, myId *id.ID, // Sign our inFact for putting into the request privKey := m.user.PortableUserInfo().ReceptionRSA - fSig, err := rsa.Sign(rand.Reader, privKey, hash.CMixHash, fHash, nil) + stream := m.rng.GetStream() + defer stream.Close() + fSig, err := rsa.Sign(stream, privKey, hash.CMixHash, fHash, nil) if err != nil { return "", err } diff --git a/ud/manager.go b/ud/manager.go index 1ce22eac8d6c24812c381fdc60753e07ba5e5e66..6b5d926eb06d1c0e7223b3f61ab89e47a93fb7cb 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -2,6 +2,7 @@ package ud import ( "fmt" + "gitlab.com/elixxir/crypto/fastRNG" "sync" "time" @@ -14,7 +15,6 @@ import ( "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/primitives/fact" "gitlab.com/xx_network/comms/connect" - "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" ) @@ -65,6 +65,8 @@ type Manager struct { // alternativeUd is an alternate User discovery service to circumvent // production. This is for testing with a separately deployed UD service. alternativeUd *alternateUd + + rng *fastRNG.StreamGenerator } // NewManager builds a new user discovery manager. @@ -73,7 +75,7 @@ type Manager struct { func NewManager(services CMix, e2e E2E, follower NetworkStatus, events event.Reporter, comms Comms, userStore UserInfo, - rng csprng.Source, username string, + rng *fastRNG.StreamGenerator, username string, kv *versioned.KV) (*Manager, error) { jww.INFO.Println("ud.NewManager()") @@ -90,6 +92,7 @@ func NewManager(services CMix, e2e E2E, comms: comms, user: userStore, kv: kv, + rng: rng, } if m.isRegistered() { @@ -111,7 +114,9 @@ func NewManager(services CMix, e2e E2E, } // Register with user discovery - err = m.register(username, rng, comms, udHost) + stream := rng.GetStream() + defer stream.Close() + err = m.register(username, stream, comms, udHost) if err != nil { return nil, errors.Errorf("Failed to register: %v", err) } @@ -132,6 +137,7 @@ func NewManager(services CMix, e2e E2E, func NewManagerFromBackup(services CMix, e2e E2E, follower NetworkStatus, events event.Reporter, comms Comms, userStore UserInfo, + rng *fastRNG.StreamGenerator, email, phone fact.Fact, kv *versioned.KV) (*Manager, error) { jww.INFO.Println("ud.NewManagerFromBackup()") if follower() != xxdk.Running { @@ -148,6 +154,7 @@ func NewManagerFromBackup(services CMix, comms: comms, user: userStore, kv: kv, + rng: rng, } // Initialize our store @@ -212,6 +219,7 @@ func InitStoreFromBackup(kv *versioned.KV, // instantiation of the manager by NewUserDiscovery. func LoadManager(services CMix, e2e E2E, events event.Reporter, comms Comms, userStore UserInfo, + rng *fastRNG.StreamGenerator, kv *versioned.KV) (*Manager, error) { m := &Manager{ @@ -220,8 +228,8 @@ func LoadManager(services CMix, e2e E2E, events: events, comms: comms, user: userStore, - - kv: kv, + rng: rng, + kv: kv, } if !m.isRegistered() { diff --git a/ud/remove.go b/ud/remove.go index 61d130ec240ad1bda693af3c39c9660f7858f597..b64a218e6d54f120de999478ef8b9fd5fb10dd0c 100644 --- a/ud/remove.go +++ b/ud/remove.go @@ -1,7 +1,6 @@ package ud import ( - "crypto/rand" "fmt" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" @@ -47,7 +46,9 @@ func (m *Manager) removeFact(f fact.Fact, // Sign our inFact for putting into the request privKey := m.user.PortableUserInfo().ReceptionRSA - fSig, err := rsa.Sign(rand.Reader, privKey, hash.CMixHash, fHash, nil) + stream := m.rng.GetStream() + defer stream.Close() + fSig, err := rsa.Sign(stream, privKey, hash.CMixHash, fHash, nil) if err != nil { return err } @@ -103,7 +104,9 @@ func (m *Manager) permanentDeleteAccount(f fact.Fact, myId *id.ID, privateKey *r fHash := factID.Fingerprint(f) // Sign our inFact for putting into the request - fsig, err := rsa.Sign(rand.Reader, privateKey, hash.CMixHash, fHash, nil) + stream := m.rng.GetStream() + defer stream.Close() + fsig, err := rsa.Sign(stream, privateKey, hash.CMixHash, fHash, nil) if err != nil { return err }