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:
Chaosoffire
2025-12-15 21:43:33 +08:00
parent 65e51f8aea
commit 09e94c6213
2 changed files with 43 additions and 17 deletions
+3 -2
View File
@@ -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
}