mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-06-07 00:46:58 +03:00
add validation layer for public key
This commit is contained in:
parent
0caa8d6e32
commit
24d8a4044b
2 changed files with 18 additions and 7 deletions
|
@ -171,11 +171,21 @@ func NewClient(db store.IStore) echo.HandlerFunc {
|
|||
client.ID = guid.String()
|
||||
|
||||
// gen Wireguard key pair
|
||||
if client.PublicKey == "" {
|
||||
key, err := wgtypes.GeneratePrivateKey()
|
||||
if err != nil {
|
||||
log.Error("Cannot generate wireguard key pair: ", err)
|
||||
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "Cannot generate Wireguard key pair"})
|
||||
}
|
||||
client.PrivateKey = key.String()
|
||||
client.PublicKey = key.PublicKey().String()
|
||||
} else {
|
||||
_, err := wgtypes.ParseKey(client.PublicKey)
|
||||
if err != nil {
|
||||
log.Error("Cannot verify wireguard public key: ", err)
|
||||
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "Cannot verify Wireguard public key"})
|
||||
}
|
||||
}
|
||||
|
||||
presharedKey, err := wgtypes.GenerateKey()
|
||||
if err != nil {
|
||||
|
@ -185,8 +195,6 @@ func NewClient(db store.IStore) echo.HandlerFunc {
|
|||
})
|
||||
}
|
||||
|
||||
client.PrivateKey = key.String()
|
||||
client.PublicKey = key.PublicKey().String()
|
||||
client.PresharedKey = presharedKey.String()
|
||||
client.CreatedAt = time.Now().UTC()
|
||||
client.UpdatedAt = client.CreatedAt
|
||||
|
|
|
@ -328,9 +328,12 @@
|
|||
if ($("#enabled").is(':checked')){
|
||||
enabled = true;
|
||||
}
|
||||
const public_key = $("#client_public_key").val();
|
||||
const preshared_key = $("#client_preshared_key").val();
|
||||
|
||||
const data = {"name": name, "email": email, "allocated_ips": allocated_ips, "allowed_ips": allowed_ips,
|
||||
"extra_allowed_ips": extra_allowed_ips, "use_server_dns": use_server_dns, "enabled": enabled};
|
||||
"extra_allowed_ips": extra_allowed_ips, "use_server_dns": use_server_dns, "enabled": enabled,
|
||||
"public_key": public_key, "preshared_key": preshared_key};
|
||||
|
||||
$.ajax({
|
||||
cache: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue