Skip to content

Commit 9dea99f

Browse files
committed
netwatch-dns: support downloading / importing certificate
1 parent 3988c70 commit 9dea99f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

doc/netwatch-dns.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ Giving a specific query url for DoH is possible:
4343

4444
Note that using a name in DoH url may introduce a chicken-and-egg issue!
4545

46+
Importing a certificate automatically is possible, at least if available in
47+
the repository (see `certs` sub directory).
48+
49+
/tool/netwatch/add comment="doh, doh-cert=DigiCert TLS Hybrid ECC SHA384 2020 CA1" host=1.1.1.1;
50+
/tool/netwatch/add comment="doh, doh-cert=DigiCert TLS Hybrid ECC SHA384 2020 CA1" host=9.9.9.9;
51+
/tool/netwatch/add comment="doh, doh-cert=GTS CA 1C3" host=8.8.8.8;
52+
4653
Sometimes using just one specific (possibly internal) DNS server may be
4754
desired, with fallback in case it fails. This is possible as well:
4855

netwatch-dns

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:global GlobalFunctionsReady;
1111
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
1212

13+
:global CertificateAvailable;
1314
:global EitherOr;
1415
:global LogPrintExit2;
1516
:global ParseKeyValueStore;
@@ -58,6 +59,7 @@ $ScriptLock $0;
5859

5960
:local DohServer "";
6061
:local DohCurrent [ /ip/dns/get use-doh-server ];
62+
:local DohCert;
6163

6264
:foreach Host in=[ /tool/netwatch/find where comment~"doh" !disabled ] do={
6365
:local HostVal [ /tool/netwatch/get $Host ];
@@ -67,12 +69,19 @@ $ScriptLock $0;
6769
$HostInfo->"disabled" != true && $DohServer = "") do={
6870
:set DohServer [ $EitherOr ($HostInfo->"doh-url") \
6971
("https://" . $HostVal->"host" . "/dns-query") ];
72+
:set DohCert ($HostInfo->"doh-cert");
7073
}
7174
}
7275

7376
:if ($DohServer != "") do={
7477
:if ($DohServer != $DohCurrent) do={
7578
$LogPrintExit2 info $0 ("Updating DoH server: " . $DohServer) false;
79+
:if ([ :len $DohCert ] > 0) do={
80+
/ip/dns/set use-doh-server="";
81+
:if ([ $CertificateAvailable $DohCert ] = false) do={
82+
$LogPrintExit2 warning $0 ("Downloading certificate failed, trying without.") false;
83+
}
84+
}
7685
/ip/dns/set use-doh-server=$DohServer;
7786
/ip/dns/cache/flush;
7887
}

0 commit comments

Comments
 (0)