Skip to content

Commit

Permalink
Auth notifications for unknown peers
Browse files Browse the repository at this point in the history
  • Loading branch information
leninalive committed Sep 6, 2024
1 parent 7815aca commit bd6261a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions contrib/peer-approver/accounts.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Public Key,Allowed Ips,PSK
/Ca5004uiLJVBqSPaBUKg5zBszO9qbzEUCWmVkelkjY=,"10.8.1.10/32",E37VXqGtGvwftop/uFsbZcIO76Ox1kMmB6Sz/JoIw2I=
20 changes: 18 additions & 2 deletions contrib/peer-approver/approve.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env bash

echo "came with arguments: "
echo $*
ACCOUNTS_FILE=$1
INTERFACE_NAME=$2
PUBLIC_KEY=$3
ENDPOINT=$4
ADVANCED_SECURITY=$5

ACCOUNT_STR=`grep "${PUBLIC_KEY}" "${ACCOUNTS_FILE}"`

if [ "${ACCOUNT_STR}" == "" ]; then
echo "Public key not found in accounts file!"
exit 255
fi

ACCOUNT=(${ACCOUNT_STR//,/ })
ALLOWED_IPS=$(echo ${ACCOUNT[1]}|tr -d '"')
PSK=$(echo ${ACCOUNT[2]}|tr -d '"')

awg set "${INTERFACE_NAME}" peer "${PUBLIC_KEY}" allowed-ips "${ALLOWED_IPS}" endpoint "${ENDPOINT}" allowed-ips "${ALLOWED_IPS}" preshared-key "${PSK}" advanced-security "${ADVANCED_SECURITY}"
exit $?
8 changes: 1 addition & 7 deletions contrib/peer-approver/notification-listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
static struct nl_sock *sk = NULL;
static char **cb_argv;
static int cb_argc;
//static bool running_cb = false;

static int cleanup_and_exit(int ret)
{
Expand All @@ -35,8 +34,7 @@ static int cleanup_and_exit(int ret)

static void signal_handler(int sig)
{
//if (!running_cb)
cleanup_and_exit(EXIT_SUCCESS);
cleanup_and_exit(EXIT_SUCCESS);
}

static inline void encode_base64(char dest[static 4], const uint8_t src[static 3])
Expand Down Expand Up @@ -132,8 +130,6 @@ static int run_callback(char *ifname, char *pubkey, char *endpoint_ip, bool adva
new_argv[cb_argc - 1] = (advanced_security ? "on\0" : "off\0");
new_argv[cb_argc] = NULL;

//running_cb = true;

int child_pid = fork(), ret;
if (child_pid < 0) {
prerr("failed to spawn child process: %d\n", child_pid);
Expand All @@ -145,8 +141,6 @@ static int run_callback(char *ifname, char *pubkey, char *endpoint_ip, bool adva
waitpid(child_pid, &ret, 0);
}

//running_cb = false;

free(new_argv);
return ret;
}
Expand Down

0 comments on commit bd6261a

Please sign in to comment.