Skip to content

Commit 3fce5c4

Browse files
committed
Terminate danectl when idna in subprocess requires idn2 but fails to find it
1 parent 2713de5 commit 3fce5c4

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

danectl

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ fetch_dns()
778778
{
779779
dns_type="$1"
780780
dns_name="`idna $2`"
781+
idna_check "$dns_name"
781782

782783
if [ $HAVE_HOST = 1 ]
783784
then
@@ -825,6 +826,7 @@ add_tlsa()
825826
{
826827
certname="$1"; shift
827828
shcertname="`shcertname $certname`"
829+
idna_check "$shcertname"
828830
eval tlsa="\$tlsa_$shcertname"
829831
set_rc tlsa_"$shcertname" "$tlsa $@"
830832
}
@@ -835,6 +837,7 @@ del_tlsa()
835837
{
836838
certname="$1"; shift
837839
shcertname="`shcertname $certname`"
840+
idna_check "$shcertname"
838841
eval tlsa="\$tlsa_$shcertname"
839842
for t in "$@"
840843
do
@@ -849,6 +852,7 @@ show_tlsa()
849852
{
850853
certname="$1"; shift
851854
shcertname="`shcertname $certname`"
855+
idna_check "$shcertname"
852856
eval tlsa="\$tlsa_$shcertname"
853857
echo "$tlsa"
854858
}
@@ -862,14 +866,17 @@ tlsa_role()
862866
label="$3"
863867
prefix="$4"
864868
shcertname="`shcertname $certname`"
869+
idna_check "$shcertname"
865870
eval tlsa="\$tlsa_$shcertname"
866871
[ -z "$tlsa" ] && die "No TLSA records have been configured yet for $certname"
867872
hash="`tlsa_hash $role $certname`"
868873
echo "$prefix; $certname $label"
869874
for t in $tlsa
870875
do
871876
domain="`case \"$t\" in *.) echo $t;; *) echo $t.$certname.;; esac`"
872-
printf "$prefix`idna $domain`\tIN\tTLSA\t3 1 1 $hash\n"
877+
idna_domain="`idna $domain`"
878+
idna_check "$idna_domain"
879+
printf "$prefix$idna_domain\tIN\tTLSA\t3 1 1 $hash\n"
873880
done
874881
}
875882

@@ -898,6 +905,7 @@ tlsa_check()
898905
{
899906
certname="$1"
900907
shcertname="`shcertname $certname`"
908+
idna_check "$shcertname"
901909
eval tlsa="\$tlsa_$shcertname"
902910
[ -z "$tlsa" ] && die "No TLSA records have been configured yet for $certname"
903911
hash_current="`tlsa_hash current $certname`"
@@ -912,7 +920,9 @@ tlsa_check()
912920
else
913921
[ "$missing" = 0 ] && echo "; Missing $certname current (must be published)"
914922
missing=1
915-
printf "`idna $domain`\tIN\tTLSA\t3 1 1 $hash_current\n"
923+
idna_domain="`idna $domain`"
924+
idna_check "$idna_domain"
925+
printf "$idna_domain\tIN\tTLSA\t3 1 1 $hash_current\n"
916926
fi
917927
done
918928
missing=0
@@ -925,7 +935,9 @@ tlsa_check()
925935
else
926936
[ "$missing" = 0 ] && echo "; Missing $certname next (must be published)"
927937
missing=1
928-
printf "`idna $domain`\tIN\tTLSA\t3 1 1 $hash_next\n"
938+
idna_domain="`idna $domain`"
939+
idna_check "$idna_domain"
940+
printf "$idna_domain\tIN\tTLSA\t3 1 1 $hash_next\n"
929941
fi
930942
done
931943
superfluous=0
@@ -948,6 +960,7 @@ add_reload()
948960
{
949961
certname="$1"; shift
950962
shcertname="`shcertname $certname`"
963+
idna_check "$shcertname"
951964
eval reload="\$reload_$shcertname"
952965
set_rc reload_"$shcertname" "$reload $@"
953966
}
@@ -958,6 +971,7 @@ del_reload()
958971
{
959972
certname="$1"; shift
960973
shcertname="`shcertname $certname`"
974+
idna_check "$shcertname"
961975
eval reload="\$reload_$shcertname"
962976
for t in "$@"
963977
do
@@ -972,6 +986,7 @@ show_reload()
972986
{
973987
certname="$1"; shift
974988
shcertname="`shcertname $certname`"
989+
idna_check "$shcertname"
975990
eval reload="\$reload_$shcertname"
976991
echo "$reload"
977992
}
@@ -983,6 +998,7 @@ reload()
983998
certname="$1"
984999
CERTNAME="$certname"; export CERTNAME
9851000
shcertname="`shcertname $certname`"
1001+
idna_check "$shcertname"
9861002
eval reload="\$reload_$shcertname"
9871003
for service in $reload
9881004
do
@@ -1178,12 +1194,25 @@ idna()
11781194
fi
11791195
}
11801196

1197+
# Terminate if $1 is empty. Used to check the output of `idna` in a subprocess.
1198+
# If idn2 was required but not available, this terminates danectl the first
1199+
# time its absence is noticed. idna() itself emits the error message.
1200+
# This lazy requirements check means that idn2 is only required when there
1201+
# are actually non-ASCII domains in use.
1202+
1203+
idna_check()
1204+
{
1205+
[ "x$1" = x ] && exit 1
1206+
}
1207+
11811208
# Output a form of certname that is suitable for use in a shell variable identifier
11821209

11831210
shcertname()
11841211
{
11851212
certname="$1"
1186-
idna "$certname" | LANG=C sed 's/[^a-zA-Z0-9]/_/g'
1213+
idna_certname="`idna $certname`"
1214+
idna_check "$idna_certname"
1215+
echo "$idna_certname" | LANG=C sed 's/[^a-zA-Z0-9]/_/g'
11871216
}
11881217

11891218
# Check for host or drill
@@ -1288,6 +1317,7 @@ check_sshfp_prerequisites()
12881317
sshfp()
12891318
{
12901319
hostname="`idna $1`"
1320+
idna_check "$hostname"
12911321
ssh-keygen -r "$hostname" | sed -e 's/ /. /' -e 's/ / /' -e 's/ / /'
12921322
}
12931323

@@ -1296,6 +1326,7 @@ sshfp()
12961326
sshfp_check()
12971327
{
12981328
hostname="`idna $1`"
1329+
idna_check "$hostname"
12991330
perl -e '
13001331
use strict;
13011332
use warnings;
@@ -1354,6 +1385,7 @@ openpgpkey()
13541385
my $domain = shift;
13551386
return $domain if $domain =~ /^[a-zA-Z0-9.-]+$/;
13561387
chop($domain = `idn2 -l -- $domain`);
1388+
die "'$name': Failed to find idn2\n" unless length $domain;
13571389
return $domain;
13581390
}
13591391
my $origin;
@@ -1405,6 +1437,7 @@ openpgpkey_check()
14051437
my $domain = shift;
14061438
return $domain if $domain =~ /^[a-zA-Z0-9.-]+$/;
14071439
chop($domain = `idn2 -l -- $domain`);
1440+
die "'$name': Failed to find idn2\n" unless length $domain;
14081441
return $domain;
14091442
}
14101443
my $origin;
@@ -1499,6 +1532,7 @@ smimea()
14991532
my $domain = shift;
15001533
return $domain if $domain =~ /^[a-zA-Z0-9.-]+$/;
15011534
chop($domain = `idn2 -l -- $domain`);
1535+
die "'$name': Failed to find idn2\n" unless length $domain;
15021536
return $domain;
15031537
}
15041538
my $cert = unpack("H*", <STDIN>);
@@ -1552,6 +1586,7 @@ smimea_check()
15521586
my $domain = shift;
15531587
return $domain if $domain =~ /^[a-zA-Z0-9.-]+$/;
15541588
chop($domain = `idn2 -l -- $domain`);
1589+
die "'$name': Failed to find idn2\n" unless length $domain;
15551590
return $domain;
15561591
}
15571592
my $cert = unpack("H*", <STDIN>);

0 commit comments

Comments
 (0)