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,10 +171,20 @@ func NewClient(db store.IStore) echo.HandlerFunc {
|
||||||
client.ID = guid.String()
|
client.ID = guid.String()
|
||||||
|
|
||||||
// gen Wireguard key pair
|
// gen Wireguard key pair
|
||||||
key, err := wgtypes.GeneratePrivateKey()
|
if client.PublicKey == "" {
|
||||||
if err != nil {
|
key, err := wgtypes.GeneratePrivateKey()
|
||||||
log.Error("Cannot generate wireguard key pair: ", err)
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "Cannot generate Wireguard key pair"})
|
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()
|
presharedKey, err := wgtypes.GenerateKey()
|
||||||
|
@ -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.PresharedKey = presharedKey.String()
|
||||||
client.CreatedAt = time.Now().UTC()
|
client.CreatedAt = time.Now().UTC()
|
||||||
client.UpdatedAt = client.CreatedAt
|
client.UpdatedAt = client.CreatedAt
|
||||||
|
|
|
@ -328,9 +328,12 @@
|
||||||
if ($("#enabled").is(':checked')){
|
if ($("#enabled").is(':checked')){
|
||||||
enabled = true;
|
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,
|
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({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue