Skip to content

Commit

Permalink
olricd, olric-cli: Use seed: Boiler-plate to securely seed Go's rando…
Browse files Browse the repository at this point in the history
…m number generator (if possible).
  • Loading branch information
buraksezer committed Mar 15, 2019
1 parent c5d240c commit af99194
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions cmd/olric-cli/main.go
Expand Up @@ -18,13 +18,12 @@ import (
"flag"
"fmt"
"io/ioutil"
"math/rand"
"os"
"runtime"
"time"

"github.com/buraksezer/olric"
"github.com/buraksezer/olric/cmd/olric-cli/cli"
"github.com/sean-/seed"
)

const (
Expand Down Expand Up @@ -69,7 +68,11 @@ var (
)

func init() {
rand.Seed(time.Now().UnixNano())
// MustInit provides guaranteed secure seeding. If `/dev/urandom` is not
// available, MustInit will panic() with an error indicating why reading from
// `/dev/urandom` failed. MustInit() will upgrade the seed if for some reason a
// call to Init() failed in the past.
seed.MustInit()
}

func main() {
Expand Down
9 changes: 6 additions & 3 deletions cmd/olricd/main.go
Expand Up @@ -19,13 +19,12 @@ import (
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
"runtime"
"time"

"github.com/buraksezer/olric"
"github.com/buraksezer/olric/cmd/olricd/server"
"github.com/sean-/seed"
)

var usage = `olricd is the default standalone server for Olric
Expand Down Expand Up @@ -54,7 +53,11 @@ var (
)

func init() {
rand.Seed(time.Now().UnixNano())
// MustInit provides guaranteed secure seeding. If `/dev/urandom` is not
// available, MustInit will panic() with an error indicating why reading from
// `/dev/urandom` failed. MustInit() will upgrade the seed if for some reason a
// call to Init() failed in the past.
seed.MustInit()
}

func main() {
Expand Down

0 comments on commit af99194

Please sign in to comment.