Skip to content

Commit fa837ba

Browse files
committed
Add cert_status script
Displays useful informations about the existing certificates.
1 parent 0312525 commit fa837ba

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,21 @@ If you want to create test certificates that don't have the 5 certs/week/domain
168168
Every hour (3600 seconds) the certificates are checked and every certificate that will expire in the next [30 days](https://github.com/kuba/simp_le/blob/ecf4290c4f7863bb5427b50cdd78bc3a5df79176/simp_le.py#L72) (90 days / 3) are renewed.
169169

170170
##### Force certificates renewal
171-
172171
If needed, you can force a running letsencrypt-nginx-proxy-companion container to renew all certificates that are currently in use. Replace `nginx-letsencrypt` with the name of your letsencrypt-nginx-proxy-companion container in the following command:
173172

174173
```bash
175174
$ docker exec nginx-letsencrypt /app/force_renew
176175
```
177176

177+
##### Force certificates renewal
178+
To display informations about your existing certificates, use the following command:
179+
180+
```bash
181+
$ docker exec nginx-letsencrypt /app/cert_status
182+
```
183+
184+
As for the forced renewal command, replace `nginx-letsencrypt` with the name of your letsencrypt-nginx-proxy-companion container.
185+
178186
##### ACME account keys
179187
By default the container will save the first ACME account key created for each ACME API endpoint used, and will reuse it for all subsequent authorizations and issuances requests made to this endpoint. This behavior is enabled by default to avoid running into Let's Encrypt account [rate limits](https://letsencrypt.org/docs/rate-limits/).
180188

app/cert_status

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
function print_cert_info {
3+
local enddate
4+
local subject
5+
local san_str
6+
7+
# Get the wanted informations with OpenSSL.
8+
issuer="$(openssl x509 -noout -issuer -in "$1" | sed -n 's/.*CN=\(.*\)/\1/p')"
9+
enddate="$(openssl x509 -noout -enddate -in "$1" | sed -n 's/notAfter=\(.*$\)/\1/p')"
10+
subject="$(openssl x509 -noout -subject -in "$1" | sed -n 's/.*CN=\([a-z0-9.-]*\)/- \1/p')"
11+
san_str="$(openssl x509 -text -in "$1" | grep 'DNS:')"
12+
13+
echo "Certificate was issued by $issuer"
14+
echo "Certificate is valid until $enddate"
15+
echo "Subject Name:"
16+
echo "$subject"
17+
18+
# Display the SAN info only if there is more than one SAN domain.
19+
while IFS=',' read -ra SAN; do
20+
if [[ ${#SAN[@]} -gt 1 ]]; then
21+
echo "Subject Alternative Name:"
22+
for domain in "${SAN[@]}"; do
23+
echo "$domain" | sed -n 's/.*DNS:\([a-z0-9.-]*\)/- \1/p'
24+
done
25+
fi
26+
done <<< "$san_str"
27+
}
28+
29+
echo '##### Certificate status #####'
30+
for cert in /etc/nginx/certs/*/fullchain.pem; do
31+
[[ -e "$cert" ]] || continue
32+
# Verify the certificate with OpenSSL.
33+
openssl verify -CAfile "${cert%fullchain.pem}chain.pem" "$cert"
34+
35+
# Print certificate info.
36+
print_cert_info "$cert"
37+
38+
# Find the .crt files in /etc/nginx/certs which are
39+
# symlinks pointing to the current certificate.
40+
unset symlinked_domains
41+
for symlink in /etc/nginx/certs/*.crt; do
42+
[[ -e "$symlink" ]] || continue
43+
if [[ "$(readlink -f "$symlink")" == "$cert" ]]; then
44+
domain="$(echo "${symlink%.crt}" | sed 's#/etc/nginx/certs/##g')"
45+
symlinked_domains+=("$domain")
46+
fi
47+
done
48+
49+
# Display symlinks pointing to the current cert if there is any.
50+
if [[ ${#symlinked_domains[@]} -gt 0 ]]; then
51+
echo "Certificate is used by the following domain(s):"
52+
for domain in "${symlinked_domains[@]}"; do
53+
echo "- $domain"
54+
done
55+
fi
56+
57+
echo '##############################'
58+
done

0 commit comments

Comments
 (0)