Skip to content

Commit d8713bf

Browse files
committed
certificates: fixes and improvements
- Fixed wrong DANE record creation in dane-set-record script - Added DANE status in the cert-status script To update your server, run the following playbook: --- ROLE=certificates apb -i ../config/hosts.yml -v -t facts,scripts install.yml ---
1 parent 45b1635 commit d8713bf

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

roles/certificates/files/cert-status.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ ca_system="/etc/ssl/certs/ca-certificates.crt"
1515
# Create the temporary output
1616
temp_file=$(mktemp)
1717

18+
19+
1820
# Remove temporary files on exit
1921
trap cleanup 1 2 3 6
2022
cleanup()
@@ -38,6 +40,19 @@ for ca_file in $cert_files; do
3840
# Get the key type
3941
key_type=$(sed -En 's/.*BEGIN (EC|RSA) PRIVATE KEY.*/\1/p' "$key_file")
4042

43+
# Check the ports used by TLS records if any
44+
dane_ports=$(pdnsutil list-zone "$domain" | sed -En "s/^_([0-9]+)\\._(tcp|udp)\\.$subdomain\\.$domain.*TLSA.*/\\1/p")
45+
46+
dane_status=""
47+
for port in $dane_ports; do
48+
valid=$(danetool --port $port --check "$subdomain.$domain" 2>&1 | grep -c 'Certificate matches')
49+
if [ "$valid" = "0" ]; then
50+
dane_status="Error"
51+
break
52+
fi
53+
dane_status="OK"
54+
done
55+
4156
# Check modulus
4257
key_modulus=""
4358
crt_modulus=""
@@ -77,22 +92,22 @@ for ca_file in $cert_files; do
7792
bar=$(printf "%02d [%-10s]" "$valid_days" "$bar")
7893

7994
if [ "$key_modulus" != "$crt_modulus" ]; then
80-
printf "%s|%s|%s|%s|%s|%s|%s|%s|Mismatch!\n" \
81-
"$subdomain" "$from_short" "$till_short" "$bar" "$issuer" "$sans" "$key_type" "$status">>"$temp_file"
95+
printf "%s|%s|%s|%s|%s|%s|%s|%s|%s|Mismatch!\n" \
96+
"$subdomain" "$from_short" "$till_short" "$bar" "$issuer" "$sans" "$key_type" "$dane_status" "$status">>"$temp_file"
8297
elif openssl verify -trusted "$ca_system" -trusted "$ca_file" "$cert_file" >/dev/null 2>&1; then
83-
printf "%s|%s|%s|%s|%s|%s|%s|%s|OK\n" \
84-
"$subdomain" "$from_short" "$till_short" "$bar" "$issuer" "$sans" "$key_type" "$status">>"$temp_file"
98+
printf "%s|%s|%s|%s|%s|%s|%s|%s|%s|OK\n" \
99+
"$subdomain" "$from_short" "$till_short" "$bar" "$issuer" "$sans" "$key_type" "$dane_status" "$status">>"$temp_file"
85100
else
86101
error=$(openssl verify -trusted "$ca_system" -trusted "$ca_file" "$cert_file" 2>&1 | sed -En 's/.*: //p')
87102
error=$(echo "$error" | tr '\n' ',' | sed 's/,$//' | sed 's/,/, /g')
88-
printf "%s|%s|%s|%s|%s|%s|%s|%s|$error\n" \
89-
"$subdomain" "$from_short" "$till_short" "$bar" "$issuer" "$sans" "$key_type" "$status">>"$temp_file"
103+
printf "%s|%s|%s|%s|%s|%s|%s|%s|%s|$error\n" \
104+
"$subdomain" "$from_short" "$till_short" "$bar" "$issuer" "$sans" "$key_type" "$dane_status" "$status">>"$temp_file"
90105
fi
91106

92107
done
93108

94109
# Display the output table formatted
95-
columns='Domain,Valid from,Valid until,Days left,Issuer,Full domains list,Type,Status,Details'
110+
columns='Domain,Valid from,Valid until,Days left,Issuer,Full domains list,Type,DANE,Status,Details'
96111
column -t -s '|' -o ' | ' -N "$columns" -W Status "$temp_file"
97112

98113
# Remove temporary files

roles/certificates/files/dane-set-record.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ if [ "$sub_domain" = "@" ]; then
5656
else
5757
fqdn="$sub_domain.$domain"
5858
crt_file="$crt_root/$sub_domain.$domain.crt"
59-
record_name="_$port._tcp.$sub_domain.$domain"
59+
record_name="_$port._tcp.$sub_domain"
6060
fi
6161

6262
if [ ! -r "$crt_file" ]; then
@@ -80,8 +80,11 @@ if danetool --quiet --check="$fqdn" --port="$port" >/dev/null 2>&1; then
8080
exit $SUCCESS
8181
fi
8282

83+
# User feedback
84+
echo "Replacing record '$record_name'" 1>&2
85+
8386
# Delete old record of exists
84-
if ! pdnsutil delete-rrset "$domain" "$record_name" TLSA; then
87+
if ! pdnsutil delete-rrset "$domain" "$record_name" TLSA; then
8588
echo "No old record to delete" 1>&2
8689
fi
8790

0 commit comments

Comments
 (0)