wg-quick: allow for tabs in keys
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
		
							parent
							
								
									d8ad40da25
								
							
						
					
					
						commit
						e0775354bd
					
				
					 2 changed files with 20 additions and 20 deletions
				
			
		| 
						 | 
					@ -10,30 +10,30 @@ CONFIG_FILE="$1"
 | 
				
			||||||
INTERFACE="${BASH_REMATCH[1]}"
 | 
					INTERFACE="${BASH_REMATCH[1]}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
process_peer() {
 | 
					process_peer() {
 | 
				
			||||||
        [[ $PEER_SECTION -ne 1 || -z $PUBLIC_KEY || -z $ENDPOINT ]] && return 0
 | 
						[[ $PEER_SECTION -ne 1 || -z $PUBLIC_KEY || -z $ENDPOINT ]] && return 0
 | 
				
			||||||
        [[ $(wg show "$INTERFACE" latest-handshakes) =~ ^${PUBLIC_KEY//+/\\+}\  ([0-9]+)$ ]] || return 0
 | 
						[[ $(wg show "$INTERFACE" latest-handshakes) =~ ^${PUBLIC_KEY//+/\\+}\	([0-9]+)$ ]] || return 0
 | 
				
			||||||
        (( ($(date +%s) - ${BASH_REMATCH[1]}) > 135 )) || return 0
 | 
						(( ($(date +%s) - ${BASH_REMATCH[1]}) > 135 )) || return 0
 | 
				
			||||||
        wg set "$INTERFACE" peer "$PUBLIC_KEY" endpoint "$ENDPOINT"
 | 
						wg set "$INTERFACE" peer "$PUBLIC_KEY" endpoint "$ENDPOINT"
 | 
				
			||||||
        reset_peer_section
 | 
						reset_peer_section
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
reset_peer_section() {
 | 
					reset_peer_section() {
 | 
				
			||||||
        PEER_SECTION=0
 | 
						PEER_SECTION=0
 | 
				
			||||||
        PUBLIC_KEY=""
 | 
						PUBLIC_KEY=""
 | 
				
			||||||
        ENDPOINT=""
 | 
						ENDPOINT=""
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
reset_peer_section
 | 
					reset_peer_section
 | 
				
			||||||
while read -r line || [[ -n $line ]]; do
 | 
					while read -r line || [[ -n $line ]]; do
 | 
				
			||||||
        key="${line%%=*}"; key="${key##*( )}"; key="${key%%*( )}"
 | 
						key="${line%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
 | 
				
			||||||
        value="${line#*=}"; value="${value##*( )}"; value="${value%%*( )}"
 | 
						value="${line#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
 | 
				
			||||||
        [[ $key == "["* ]] && { process_peer; reset_peer_section; }
 | 
						[[ $key == "["* ]] && { process_peer; reset_peer_section; }
 | 
				
			||||||
        [[ $key == "[Peer]" ]] && PEER_SECTION=1
 | 
						[[ $key == "[Peer]" ]] && PEER_SECTION=1
 | 
				
			||||||
        if [[ $PEER_SECTION -eq 1 ]]; then
 | 
						if [[ $PEER_SECTION -eq 1 ]]; then
 | 
				
			||||||
                case "$key" in
 | 
							case "$key" in
 | 
				
			||||||
                PublicKey) PUBLIC_KEY="$value"; continue ;;
 | 
							PublicKey) PUBLIC_KEY="$value"; continue ;;
 | 
				
			||||||
                Endpoint) ENDPOINT="$value"; continue ;;
 | 
							Endpoint) ENDPOINT="$value"; continue ;;
 | 
				
			||||||
                esac
 | 
							esac
 | 
				
			||||||
        fi
 | 
						fi
 | 
				
			||||||
done < "$CONFIG_FILE"
 | 
					done < "$CONFIG_FILE"
 | 
				
			||||||
process_peer
 | 
					process_peer
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,8 +35,8 @@ parse_options() {
 | 
				
			||||||
	INTERFACE="${BASH_REMATCH[1]}"
 | 
						INTERFACE="${BASH_REMATCH[1]}"
 | 
				
			||||||
	shopt -s nocasematch
 | 
						shopt -s nocasematch
 | 
				
			||||||
	while read -r line || [[ -n $line ]]; do
 | 
						while read -r line || [[ -n $line ]]; do
 | 
				
			||||||
		key="${line%%=*}"; key="${key##*( )}"; key="${key%%*( )}"
 | 
							key="${line%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
 | 
				
			||||||
		value="${line#*=}"; value="${value##*( )}"; value="${value%%*( )}"
 | 
							value="${line#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
 | 
				
			||||||
		[[ $key == "["* ]] && interface_section=0
 | 
							[[ $key == "["* ]] && interface_section=0
 | 
				
			||||||
		[[ $key == "[Interface]" ]] && interface_section=1
 | 
							[[ $key == "[Interface]" ]] && interface_section=1
 | 
				
			||||||
		if [[ $interface_section -eq 1 ]]; then
 | 
							if [[ $interface_section -eq 1 ]]; then
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue