Skip to content

Commit

Permalink
Use cryptographic random as RNG seed for agent ID (#32)
Browse files Browse the repository at this point in the history
* Use seeded random number generator for agent id

* Use cryptographic random as RNG seed
  • Loading branch information
Kwintenvdb authored May 17, 2023
1 parent 7809680 commit cf5407f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion core/configuration/dt_config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package configuration

import (
cryptoRand "crypto/rand"
"encoding/binary"
"errors"
"fmt"
"math/rand"
Expand Down Expand Up @@ -171,6 +173,15 @@ func validateConfiguration(config *DtConfiguration) error {
}

func generateAgentId() int64 {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
var rng *rand.Rand

var seed [8]byte
_, err := cryptoRand.Read(seed[:])
if err != nil {
rng = rand.New(rand.NewSource(time.Now().UnixNano()))
} else {
rng = rand.New(rand.NewSource(int64(binary.LittleEndian.Uint64(seed[:]))))
}

return int64(rng.Uint64())
}

0 comments on commit cf5407f

Please sign in to comment.