From 95d21bfcb979b00e4bff2a2af41afc824d869ff7 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 10 Jul 2024 14:11:13 +0200 Subject: [PATCH] ADD trust-cert script to add cert to cert store --- bin/trust-cert | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 bin/trust-cert diff --git a/bin/trust-cert b/bin/trust-cert new file mode 100755 index 0000000..63af884 --- /dev/null +++ b/bin/trust-cert @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euf -o pipefail + +# Check if at least one domain is provided as an argument +if [ "$#" -eq 0 ]; then + echo "Usage: $0 domain1 [domain2 ... domainN]" + exit 1 +fi + +# Iterate over each provided domain +for domain in "$@"; do + echo "Retrieving certificate for $domain..." + + # Use openssl to retrieve the certificate and save it to the appropriate directory + openssl s_client -showcerts -connect "$domain:443" < /dev/null | \ + sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > "/usr/local/share/ca-certificates/${domain}.crt" +done + +# Update the system's certificate store +update-ca-certificates + +echo "Certificates updated successfully." + +# Example usage: +# ./trust-cert example.com example.org example.net