mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
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:
parent
52a2c63682
commit
17207fc5e4
4 changed files with 83 additions and 28 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue