WireGuard: Improve config error handling; Prevent panic in case of errors during server initialization (#4566)

https://github.com/XTLS/Xray-core/pull/4566#issuecomment-2764779273
This commit is contained in:
Ilya Gulya 2025-03-31 03:50:25 +05:00 committed by RPRX
parent 52a2c63682
commit 17207fc5e4
4 changed files with 83 additions and 28 deletions

View file

@ -67,7 +67,7 @@ func (c *WireGuardConfig) Build() (proto.Message, error) {
var err error
config.SecretKey, err = ParseWireGuardKey(c.SecretKey)
if err != nil {
return nil, err
return nil, errors.New("invalid WireGuard secret key: %w", err)
}
if c.Address == nil {
@ -126,6 +126,10 @@ func (c *WireGuardConfig) Build() (proto.Message, error) {
func ParseWireGuardKey(str string) (string, error) {
var err error
if str == "" {
return "", errors.New("key must not be empty")
}
if len(str)%2 == 0 {
_, err = hex.DecodeString(str)
if err == nil {