Skip to content

Commit a08b311

Browse files
authored
Merge pull request #7 from jonathanio/feature/dnssec-support
Add DNSSEC Support
2 parents e5d3b52 + 8a6c55a commit a08b311

File tree

5 files changed

+107
-3
lines changed

5 files changed

+107
-3
lines changed

run-tests

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ function busctl {
6464
" Received: '${@}'"
6565
fi
6666
;;
67+
SetLinkDNSSEC)
68+
shift 2
69+
if [[ "${TEST_BUSCTL_DNSSEC}" == "" ]]; then
70+
[[ "${ip_ifindex} ${TEST_BUSCTL_DNSSEC}" == "${@}" ]] || \
71+
_fail "SetLinkDNSSEC was called and should not be: '${@}'"
72+
else
73+
[[ "${ip_ifindex} ${TEST_BUSCTL_DNSSEC}" == "${@}" ]] && \
74+
_pass "SetLinkDNSSEC was called correctly" || \
75+
_fail "SetLinkDNSSEC was not given the correct arguments:\n" \
76+
" Expected: '${ip_ifindex} ${TEST_BUSCTL_DNSSEC}'\n" \
77+
" Received: '${@}'"
78+
fi
79+
;;
6780
*)
6881
_fail "Unknown command called on busctl: ${1}"
6982
;;

tests/20_dnssec_only.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
script_type="up"
2+
dev="tun20"
3+
4+
TEST_BUSCTL_CALLED=1
5+
6+
declare -A test_options=(
7+
['default']='""'
8+
['Default']='""'
9+
['true']='yes'
10+
['True']='yes'
11+
['yes']='yes'
12+
['Yes']='yes'
13+
['false']='no'
14+
['False']='no'
15+
['no']='no'
16+
['No']='no'
17+
['allow-downgrade']='allow-downgrade'
18+
)
19+
20+
for test_option in "${!test_options[@]}"; do
21+
TEST_TITLE="DNSSEC Set to $test_option"
22+
TEST_BUSCTL_DNSSEC="${test_options["$test_option"]}"
23+
foreign_option_1="dhcp-option DNSSEC $test_option"
24+
runtest
25+
done

tests/21_dnssec_invalid_options.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
script_type="up"
2+
dev="tun21"
3+
4+
TEST_BUSCTL_CALLED=0
5+
EXPECT_FAILURE=1
6+
7+
declare -a test_invalids=(
8+
'1'
9+
'0'
10+
'DOWNGRADE'
11+
)
12+
13+
for test_option in "${test_invalids[@]}"; do
14+
TEST_TITLE="DNSSEC Set to $test_option"
15+
foreign_option_1="dhcp-option DNSSEC $test_option"
16+
runtest
17+
done
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
script_type="up"
2+
dev="tun22"
3+
foreign_option_1="dhcp-option DNS 1.23.4.56"
4+
foreign_option_2="dhcp-option DNS 1234:567:89::ab:cdef"
5+
foreign_option_3="dhcp-option DOMAIN example.com"
6+
foreign_option_4="dhcp-option DOMAIN-SEARCH example.org"
7+
foreign_option_5="dhcp-option DOMAIN-ROUTE example.net"
8+
foreign_option_6="dhcp-option DNSSEC yes"
9+
10+
TEST_TITLE="DNS, DNSSEC, Domain, Search, and Route"
11+
TEST_BUSCTL_CALLED=1
12+
TEST_BUSCTL_DOMAINS="3 example.com false example.org false example.net true"
13+
TEST_BUSCTL_DNSSEC="yes"
14+
TEST_BUSCTL_DNS="2 2 4 1 23 4 56 2 16 18 52 5 103 0 137 0 0 0 0 0 0 0 171 205 239"

update-systemd-resolved

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
# This script will parse DHCP options set via OpenVPN (dhcp-option) to update
2020
# systemd-resolved directly via DBus, instead of updating /etc/resolv.conf. To
21-
# install, set as the 'up' and 'down' script in your OpenVPN configuration file
21+
# install, set as the 'up' and 'down-pre' script in your OpenVPN configuration file
2222
# or command-line argument. For example:
2323
# up /etc/openvpn/update-systemd-resolved
24-
# down /etc/openvpn/update-systemd-resolved
24+
# down-pre /etc/openvpn/update-systemd-resolved
2525

2626
# Define what needs to be called via DBus
2727
DBUS_DEST="org.freedesktop.resolve1"
@@ -82,6 +82,7 @@ up() {
8282
# functions.
8383
local -a dns_servers=() dns_domain=() dns_search=() dns_routed=()
8484
local -i dns_server_count=0 dns_domain_count=0 dns_search_count=0 dns_routed_count=0
85+
local dns_sec=""
8586

8687
while read -r setting; do
8788
setting_type="${setting%% *}"
@@ -120,6 +121,17 @@ up() {
120121
info "SetLinkDomains(${busctl_params[*]})"
121122
busctl_call SetLinkDomains 'ia(sb)' "${busctl_params[@]}" || return $?
122123
fi
124+
125+
if [[ -n "${dns_sec}" ]]; then
126+
if [[ "${dns_sec}" == "default" ]]; then
127+
# We need to provide an empty string to use the default settings
128+
busctl_params=("$if_index" '""')
129+
else
130+
busctl_params=("$if_index" "${dns_sec}")
131+
fi
132+
info "SetLinkDNSSEC(${busctl_params[*]})"
133+
busctl_call SetLinkDNSSEC 'is' "${busctl_params[@]}" || return $?
134+
fi
123135
}
124136

125137
down() {
@@ -340,6 +352,29 @@ process_domain_route() {
340352
dns_routed+=("${domain}" true)
341353
}
342354

355+
process_dnssec() {
356+
local option="$1" setting=""
357+
shift
358+
359+
case "${option,,}" in
360+
yes|true)
361+
setting="yes" ;;
362+
no|false)
363+
setting="no" ;;
364+
default)
365+
setting="default" ;;
366+
allow-downgrade)
367+
setting="allow-downgrade" ;;
368+
*)
369+
local message="\`$option' is not a valid DNSSEC option"
370+
emerg "${message}"
371+
return 1 ;;
372+
esac
373+
374+
info "Setting DNSSEC to ${setting}"
375+
dns_sec="${setting}"
376+
}
377+
343378
main() {
344379
local script_type="$1"
345380
shift
@@ -368,5 +403,5 @@ main() {
368403
if [[ "${BASH_SOURCE[0]}" == "$0" ]] || [[ "$AUTOMATED_TESTING" == 1 ]]; then
369404
set -o nounset
370405

371-
main "$script_type" "$dev" "$@"
406+
main "${script_type:-}" "${dev:-}" "$@"
372407
fi

0 commit comments

Comments
 (0)