summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-11-09 14:12:06 +0900
committerJason A. Donenfeld <Jason@zx2c4.com>2017-11-10 16:20:09 +0900
commit23f553e44e929392d78b4d628a7bdad10c5397cb (patch)
treec859d4182fa5204bd2a10779fbe90e648aaaf61a
parentnetlink: make sure we reserve space for NLMSG_DONE (diff)
downloadwireguard-monolithic-historical-23f553e44e929392d78b4d628a7bdad10c5397cb.tar.xz
wireguard-monolithic-historical-23f553e44e929392d78b4d628a7bdad10c5397cb.zip
wg-quick: allow for tabs in keys
-rwxr-xr-xcontrib/examples/reresolve-dns/reresolve-dns.sh36
-rwxr-xr-xsrc/tools/wg-quick.bash4
2 files changed, 20 insertions, 20 deletions
diff --git a/contrib/examples/reresolve-dns/reresolve-dns.sh b/contrib/examples/reresolve-dns/reresolve-dns.sh
index d63f5fa..abd5cbf 100755
--- a/contrib/examples/reresolve-dns/reresolve-dns.sh
+++ b/contrib/examples/reresolve-dns/reresolve-dns.sh
@@ -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
diff --git a/src/tools/wg-quick.bash b/src/tools/wg-quick.bash
index f69061a..42bf265 100755
--- a/src/tools/wg-quick.bash
+++ b/src/tools/wg-quick.bash
@@ -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