]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg-quick: allow for tabs in keys
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 9 Nov 2017 05:12:06 +0000 (14:12 +0900)
committerJason A. Donenfeld <Jason@zx2c4.com>
Fri, 10 Nov 2017 07:20:09 +0000 (16:20 +0900)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
contrib/reresolve-dns/reresolve-dns.sh
src/wg-quick.bash

index d63f5fa907042d534f8a7379417d1ee2f6f14839..abd5cbfde007ff39dea138b4dc6c0c2907b4fdb5 100755 (executable)
@@ -10,30 +10,30 @@ CONFIG_FILE="$1"
 INTERFACE="${BASH_REMATCH[1]}"
 
 process_peer() {
-        [[ $PEER_SECTION -ne 1 || -z $PUBLIC_KEY || -z $ENDPOINT ]] && return 0
-        [[ $(wg show "$INTERFACE" latest-handshakes) =~ ^${PUBLIC_KEY//+/\\+}\  ([0-9]+)$ ]] || return 0
-        (( ($(date +%s) - ${BASH_REMATCH[1]}) > 135 )) || return 0
-        wg set "$INTERFACE" peer "$PUBLIC_KEY" endpoint "$ENDPOINT"
-        reset_peer_section
+       [[ $PEER_SECTION -ne 1 || -z $PUBLIC_KEY || -z $ENDPOINT ]] && return 0
+       [[ $(wg show "$INTERFACE" latest-handshakes) =~ ^${PUBLIC_KEY//+/\\+}\  ([0-9]+)$ ]] || return 0
+       (( ($(date +%s) - ${BASH_REMATCH[1]}) > 135 )) || return 0
+       wg set "$INTERFACE" peer "$PUBLIC_KEY" endpoint "$ENDPOINT"
+       reset_peer_section
 }
 
 reset_peer_section() {
-        PEER_SECTION=0
-        PUBLIC_KEY=""
-        ENDPOINT=""
+       PEER_SECTION=0
+       PUBLIC_KEY=""
+       ENDPOINT=""
 }
 
 reset_peer_section
 while read -r line || [[ -n $line ]]; do
-        key="${line%%=*}"; key="${key##*( )}"; key="${key%%*( )}"
-        value="${line#*=}"; value="${value##*( )}"; value="${value%%*( )}"
-        [[ $key == "["* ]] && { process_peer; reset_peer_section; }
-        [[ $key == "[Peer]" ]] && PEER_SECTION=1
-        if [[ $PEER_SECTION -eq 1 ]]; then
-                case "$key" in
-                PublicKey) PUBLIC_KEY="$value"; continue ;;
-                Endpoint) ENDPOINT="$value"; continue ;;
-                esac
-        fi
+       key="${line%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
+       value="${line#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
+       [[ $key == "["* ]] && { process_peer; reset_peer_section; }
+       [[ $key == "[Peer]" ]] && PEER_SECTION=1
+       if [[ $PEER_SECTION -eq 1 ]]; then
+               case "$key" in
+               PublicKey) PUBLIC_KEY="$value"; continue ;;
+               Endpoint) ENDPOINT="$value"; continue ;;
+               esac
+       fi
 done < "$CONFIG_FILE"
 process_peer
index f69061ac9c6ddca29667b0637b5e4df09d594550..42bf26514315cb55c752b8437484a3b8e96ee18d 100755 (executable)
@@ -35,8 +35,8 @@ parse_options() {
        INTERFACE="${BASH_REMATCH[1]}"
        shopt -s nocasematch
        while read -r line || [[ -n $line ]]; do
-               key="${line%%=*}"; key="${key##*( )}"; key="${key%%*( )}"
-               value="${line#*=}"; value="${value##*( )}"; value="${value%%*( )}"
+               key="${line%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
+               value="${line#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
                [[ $key == "["* ]] && interface_section=0
                [[ $key == "[Interface]" ]] && interface_section=1
                if [[ $interface_section -eq 1 ]]; then