mirror of
https://github.com/max-moser/network-manager-wireguard.git
synced 2026-11-23 01:35:39 +03:00
Fix issue with PSK and add checks for Base64 keys
Write PresharedKey to [Peer] section instead of [Interface] on export, as it should be. Change ConnectionEditor UI accordingly to reflect this change. Add check for proper length and Base64 encoding of keys (public, private, PSK).
This commit is contained in:
1 parent
dce4fd41dd
commit
2470f6ad1f
5 files changed
+121
-71
No files matched your search
+15
-14
@@ -892,17 +892,6 @@ do_import (const char *path, const char *contents, gsize contents_len, GError **
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NM_IN_STRSET (params[0], NMV_WG_TAG_PRESHARED_KEY)){
|
||||
char *psk = NULL;
|
||||
if(!parse_preshared_key(params, &psk, &line_error)){
|
||||
goto handle_line_error;
|
||||
}
|
||||
|
||||
setting_vpn_add_data_item(s_vpn, NM_WG_KEY_PRESHARED_KEY, psk);
|
||||
printf("%s = %s\n", NMV_WG_TAG_PRESHARED_KEY, psk);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NM_IN_STRSET (params[0], NMV_WG_TAG_PRE_UP)){
|
||||
char *script = NULL;
|
||||
if(!parse_script(params, &script, &line_error)){
|
||||
@@ -1006,6 +995,17 @@ do_import (const char *path, const char *contents, gsize contents_len, GError **
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NM_IN_STRSET (params[0], NMV_WG_TAG_PRESHARED_KEY)){
|
||||
char *psk = NULL;
|
||||
if(!parse_preshared_key(params, &psk, &line_error)){
|
||||
goto handle_line_error;
|
||||
}
|
||||
|
||||
setting_vpn_add_data_item(s_vpn, NM_WG_KEY_PRESHARED_KEY, psk);
|
||||
printf("%s = %s\n", NMV_WG_TAG_PRESHARED_KEY, psk);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* currently we ignore any unknown options and skip over them. */
|
||||
continue;
|
||||
|
||||
@@ -1208,9 +1208,6 @@ create_config_string (NMConnection *connection, GError **error)
|
||||
|
||||
args_write_line(f, NMV_WG_TAG_LISTEN_PORT, "=", listen_port);
|
||||
|
||||
if(psk){
|
||||
args_write_line(f, NMV_WG_TAG_PRESHARED_KEY, "=", psk);
|
||||
}
|
||||
if(post_up){
|
||||
args_write_line(f, NMV_WG_TAG_POST_UP, "=", post_up);
|
||||
}
|
||||
@@ -1233,6 +1230,10 @@ create_config_string (NMConnection *connection, GError **error)
|
||||
g_strfreev (ip_list);
|
||||
g_array_free(ips, TRUE);
|
||||
|
||||
if(psk){
|
||||
args_write_line(f, NMV_WG_TAG_PRESHARED_KEY, "=", psk);
|
||||
}
|
||||
|
||||
return g_steal_pointer (&f);
|
||||
}
|
||||
|
||||
|
||||
@@ -544,4 +544,38 @@ gboolean is_fqdn(char *addr)
|
||||
fqdn_end:
|
||||
g_strfreev(parts);
|
||||
return success;
|
||||
}
|
||||
|
||||
gboolean is_base64(char *str)
|
||||
{
|
||||
char *ptr = str;
|
||||
int padding = 0;
|
||||
|
||||
// Base64 only allows for alphanumeric characters along with
|
||||
// '+', '/' (and '=' as trailing padding)
|
||||
for(; ptr && *ptr; ptr++){
|
||||
if(*ptr == '='){
|
||||
padding++;
|
||||
}
|
||||
|
||||
if(padding <= 0){
|
||||
if(!g_ascii_isalnum(*ptr) &&
|
||||
(*ptr != '+') &&
|
||||
(*ptr != '/')){
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}else{
|
||||
if(*ptr != '='){
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we have more than 3x '=', there's too much padding
|
||||
if(padding > 3){
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -104,6 +104,8 @@ gboolean is_ip6 (char *addr);
|
||||
|
||||
gboolean is_fqdn(char *addr);
|
||||
|
||||
gboolean is_base64(char *str);
|
||||
|
||||
#define NMOVPN_PROTCOL_TYPES \
|
||||
"udp", \
|
||||
"udp4", \
|
||||
|
||||
Reference in new issue
Block a user