Skip to content

Commit 4e5db3a

Browse files
committed
Add letsencrypt-tlsa.sh
1 parent 48d24fe commit 4e5db3a

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Miscellaneous scripts for different purposes. Mostly unrelated to each other.
88
| Category | Script & Language | Purpose & Usage |
99
|:---|:---|:---|
1010
| Automation | [`find-inactive-ssh-sessions.sh`](bin/find-inactive-ssh-sessions.sh) <br> Shell (bash) | Find inactive (idle) SSH sessions or kill (`-k`) them.<br>`find-inactive-ssh-sessions.sh [-k] [-i seconds] [-s]`<br>Could be used as a [workaround](https://serverfault.com/a/1162840/274176) for OpenSSH < 9.2 that did not have the [sshd_config(5)](https://man.openbsd.org/sshd_config) keywords `ChannelTimeout` & `UnusedConnectionTimeout`.|
11+
| DNS <br> DANE | [`letsencrypt-tlsa.sh`](bin/letsencrypt-tlsa.sh) <br> Shell (bash) | Create TLSA records from the current & backup Let's Encrypt Intermediate CAs. |
1112
| Email | [`mail-prepender.sh`](bin/mail-prepender.sh) <br> Shell (bash) | Prepends (to stdin/stdout) email header strings given in as flags `i`, `I`, `a`, or `A`; after possible mbox `From` & `Return-Path` header lines. Intended as a limited `formail` replacement that ignores the nyanses of the flags and simply prepends the valid (RFC 5322, 2.2) non-empty headers keeping the other headers as is. Flags `x` & `X` are implemented. Any other flags are ignored. |
1213
| Git | [`git-find-commits-by-file-hash.sh`](bin/git-find-commits-by-file-hash.sh) <br> Shell (bash) | Search Git repository history for commits with SHA-256 checksum of a file. Answers the question "Has this version of this file ever been committed as the file on this path of this Git repository?" and shows a summary (`git show --stat`) of the matching commit(s). The `path` should be relative to the repository root. <br> `git-find-commits-by-file-hash.sh sha256sum path`|
1314
| Infosec | [`netcat-proxy.sh`](bin/netcat-proxy.sh) <br> Shell (sh) | Creates a simple persistent TCP proxy with netcat & named pipes. <br> `netcat-proxy.sh listenport targethost targetport` |

bin/letsencrypt-tlsa.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# ------------------------------------------------------------------------------
3+
# Create TLSA records from the current & backup Let's Encrypt Intermediate CAs
4+
#
5+
# Author : Esa Jokinen (oh2fih)
6+
# Home : https://github.com/oh2fih/Misc-Scripts
7+
# ------------------------------------------------------------------------------
8+
9+
SOURCE="/certificates/"
10+
BASE_URL="https://letsencrypt.org"
11+
12+
# Check for requirements. Print all unmet requirements at once.
13+
14+
required_command() {
15+
if ! command -v "$1" &> /dev/null; then
16+
if [ -z ${2+x} ]; then
17+
echo -e "\033[0;31mThis script requires ${1}!\033[0m" >&2
18+
else
19+
echo -e "\033[0;31mThis script requires ${1} ${2}!\033[0m" >&2
20+
fi
21+
((UNMET=UNMET+1))
22+
fi
23+
}
24+
25+
UNMET=0
26+
27+
required_command "openssl" "for creating TLSA records"
28+
required_command "curl" "for fetching data"
29+
required_command "grep"
30+
required_command "sed"
31+
required_command "awk"
32+
33+
if [ "$UNMET" -gt 0 ]; then
34+
exit 1
35+
fi
36+
37+
# Get URLs for the Subordinate (Intermediate) CAs, including backups
38+
39+
INTERMEDIATE_PATHS=$(
40+
curl --silent "${BASE_URL}${SOURCE}" \
41+
| sed '/subordinate-intermediate-cas/d' \
42+
| sed '/.summary.Retired..summary./q' \
43+
| grep -oE "/certs/[0-9]+/[0-9a-zA-Z]+(-cross)?.pem"
44+
)
45+
46+
if [ "$INTERMEDIATE_PATHS" = "" ]; then
47+
echo "Failed to fetch certificate list from ${BASE_URL}${SOURCE}" >&2
48+
exit 1
49+
fi
50+
51+
# Create TLSA records
52+
53+
while IFS= read -r path ; do
54+
echo "[${BASE_URL}${path}]" >&2
55+
PEM=$(curl --silent "${BASE_URL}${path}")
56+
if [[ "$PEM" =~ ^[-]+BEGIN[[:space:]]CERTIFICATE[-]+ ]]; then
57+
echo "$PEM" \
58+
| openssl x509 -outform DER \
59+
| openssl dgst -sha256 -hex \
60+
| awk '{print "le-ca TLSA 2 1 1", $NF}'
61+
fi
62+
63+
done <<< "$INTERMEDIATE_PATHS"

0 commit comments

Comments
 (0)