refactor: replace math/rand with crypto/rand for secure generation
- Updated `common.Random` and added `common.RandomInt` to use `crypto/rand` for cryptographically secure random number generation. - Added a thread-safe fallback to `math/rand` in case of system entropy failure. - Optimized `allSeq` initialization by using a rune slice literal instead of a loop in `init()`. - Refactored `util/outJson.go` to use the new `common.RandomInt`, removing the direct dependency on `math/rand`.
This commit is contained in:
+3
-2
@@ -2,7 +2,8 @@ package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
|
||||
"github.com/alireza0/s-ui/util/common"
|
||||
|
||||
"github.com/alireza0/s-ui/database/model"
|
||||
)
|
||||
@@ -108,7 +109,7 @@ func addTls(out *map[string]interface{}, tls *model.Tls) {
|
||||
realityConfig := tlsConfig["reality"].(map[string]interface{})
|
||||
realityConfig["enabled"] = true
|
||||
if shortIDs, ok := reality["short_id"].([]interface{}); ok && len(shortIDs) > 0 {
|
||||
realityConfig["short_id"] = shortIDs[rand.Intn(len(shortIDs))]
|
||||
realityConfig["short_id"] = shortIDs[common.RandomInt(len(shortIDs))]
|
||||
}
|
||||
tlsConfig["reality"] = realityConfig
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user