mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-06-07 00:46:58 +03:00
add preshared key validator
This commit is contained in:
parent
24d8a4044b
commit
98edcd0d04
1 changed files with 15 additions and 8 deletions
|
@ -187,6 +187,7 @@ func NewClient(db store.IStore) echo.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
if client.PresharedKey == "" {
|
||||
presharedKey, err := wgtypes.GenerateKey()
|
||||
if err != nil {
|
||||
log.Error("Cannot generated preshared key: ", err)
|
||||
|
@ -194,8 +195,14 @@ func NewClient(db store.IStore) echo.HandlerFunc {
|
|||
false, "Cannot generate Wireguard preshared key",
|
||||
})
|
||||
}
|
||||
|
||||
client.PresharedKey = presharedKey.String()
|
||||
} else {
|
||||
_, err := wgtypes.ParseKey(client.PresharedKey)
|
||||
if err != nil {
|
||||
log.Error("Cannot verify wireguard preshared key: ", err)
|
||||
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "Cannot verify Wireguard preshared key"})
|
||||
}
|
||||
}
|
||||
client.CreatedAt = time.Now().UTC()
|
||||
client.UpdatedAt = client.CreatedAt
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue