netwatch-dns: support multiple certificates

Some services use certificates issued by differnt CA certificates,
depending on geolocation. One example is dns.google, which may require
either of 'GTS Root R1' or 'GTS Root R4'.

    /tool/netwatch/add comment="doh, dns, name=google-dns-ipv4, doh-cert=GTS Root R1:GTS Root R4" host=8.8.8.8 type=simple;
This commit is contained in:
Christian Hesse 2026-01-16 13:51:37 +01:00
parent 330a616406
commit 0fffb5198e

View file

@ -17,6 +17,7 @@
:local ScriptName [ :jobname ]; :local ScriptName [ :jobname ];
:global CertificateAvailable; :global CertificateAvailable;
:global CharacterReplace;
:global EitherOr; :global EitherOr;
:global IsDNSResolving; :global IsDNSResolving;
:global LogPrint; :global LogPrint;
@ -103,10 +104,12 @@
} }
:foreach DohServer in=$DohServers do={ :foreach DohServer in=$DohServers do={
:if ([ :len ($DohServer->"doh-cert") ] > 0) do={ :foreach DohCert in=[ :toarray [ $CharacterReplace ($DohServer->"doh-cert") ":" "," ] ] do={
:if ([ $CertificateAvailable ($DohServer->"doh-cert") "fetch" ] = false || \ :if ([ :len $DohCert ] > 0) do={
[ $CertificateAvailable ($DohServer->"doh-cert") "dns" ] = false) do={ :if ([ $CertificateAvailable $DohCert "fetch" ] = false || \
$LogPrint warning $ScriptName ("Downloading certificate failed, trying without."); [ $CertificateAvailable $DohCert "dns" ] = false) do={
$LogPrint warning $ScriptName ("Downloading certificate '" . $DohCert . "' failed, trying without.");
}
} }
} }