diff --git a/contrib/helm/chihaya/values.yaml b/contrib/helm/chihaya/values.yaml index d82a940..4322ba5 100644 --- a/contrib/helm/chihaya/values.yaml +++ b/contrib/helm/chihaya/values.yaml @@ -25,7 +25,6 @@ config: addr: 0.0.0.0:6881 allow_ip_spoofing: true max_clock_skew: 10s - private_key: "/K8AybyuKkob03fZJb+3Fu87eVcBNWsvVyDDxGd3wfvVGix10j6iGDEyS/ELPvQIIZvUPl2PnyfnpG6g1YJ/sw==" storage: gc_interval: 14m peer_lifetime: 15m diff --git a/frontend/udp/frontend.go b/frontend/udp/frontend.go index 2f5047d..910b3a9 100644 --- a/frontend/udp/frontend.go +++ b/frontend/udp/frontend.go @@ -6,6 +6,7 @@ import ( "bytes" "context" "encoding/binary" + "math/rand" "net" "sync" "time" @@ -18,6 +19,8 @@ import ( "github.com/chihaya/chihaya/frontend/udp/bytepool" ) +var allowedGeneratedPrivateKeyRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") + func init() { prometheus.MustRegister(promResponseDurationMilliseconds) } @@ -68,6 +71,18 @@ type Frontend struct { // NewFrontend allocates a new instance of a Frontend. func NewFrontend(logic frontend.TrackerLogic, cfg Config) *Frontend { + // Generate a private key if one isn't provided by the user. + if cfg.PrivateKey == "" { + rand.Seed(time.Now().UnixNano()) + pkeyRunes := make([]rune, 64) + for i := range pkeyRunes { + pkeyRunes[i] = allowedGeneratedPrivateKeyRunes[rand.Intn(len(allowedGeneratedPrivateKeyRunes))] + } + cfg.PrivateKey = string(pkeyRunes) + + log.Warn("UDP private key was not provided, using generated key: ", cfg.PrivateKey) + } + return &Frontend{ closing: make(chan struct{}), logic: logic,