mysql_mit_ssl_verschluesselten_verbindungen
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | |||
| mysql_mit_ssl_verschluesselten_verbindungen [2024-04-11 09:47:22] – manfred | mysql_mit_ssl_verschluesselten_verbindungen [2026-03-02 15:58:52] (aktuell) – manfred | ||
|---|---|---|---|
| Zeile 232: | Zeile 232: | ||
| | sys | | | sys | | ||
| +------------------------------------+ | +------------------------------------+ | ||
| + | |||
| + | |||
| + | ===== MySQL sein SSL-Zertifikat prüfen ===== | ||
| + | |||
| + | <code bash / | ||
| + | #!/bin/bash | ||
| + | |||
| + | # diese Methode ist universell und funktioniert bei MySQL und bei MariaDB; | ||
| + | |||
| + | # der Pfad zum Zertifikat wird aus der DB ausgelesen; | ||
| + | # die Informationen werden dann direkt aus der PEM-Datei gelesen; | ||
| + | |||
| + | MYSQL_LOGIN=" | ||
| + | # | ||
| + | |||
| + | ( | ||
| + | cd $(echo " | ||
| + | # | ||
| + | SSL_ZERTIFIKAT=" | ||
| + | |||
| + | BIS=" | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | openssl x509 -noout -subject -issuer -in " | ||
| + | ) | tr -s ' | ||
| + | echo | ||
| + | </ | ||
| + | |||
| + | <code py / | ||
| + | # | ||
| + | |||
| + | import glob | ||
| + | import subprocess | ||
| + | import datetime | ||
| + | import os | ||
| + | |||
| + | WARN_DAYS = 30 | ||
| + | CRIT_DAYS = 10 | ||
| + | |||
| + | now = datetime.datetime.now() | ||
| + | |||
| + | sockets = sorted(glob.glob("/ | ||
| + | |||
| + | for sock in sockets: | ||
| + | if not os.path.exists(sock): | ||
| + | continue | ||
| + | try: | ||
| + | ssl_cert = subprocess.check_output( | ||
| + | [" | ||
| + | input=" | ||
| + | text=True, | ||
| + | stderr=subprocess.DEVNULL | ||
| + | ).strip() | ||
| + | |||
| + | ssl_ca = subprocess.check_output( | ||
| + | [" | ||
| + | input=" | ||
| + | text=True, | ||
| + | stderr=subprocess.DEVNULL | ||
| + | ).strip() | ||
| + | |||
| + | if not ssl_cert.startswith("/" | ||
| + | datadir = subprocess.check_output( | ||
| + | [" | ||
| + | input=" | ||
| + | text=True, | ||
| + | stderr=subprocess.DEVNULL | ||
| + | ).strip() | ||
| + | |||
| + | cert_path = datadir + ssl_cert | ||
| + | else: | ||
| + | cert_path = ssl_cert | ||
| + | |||
| + | except Exception: | ||
| + | print(f" | ||
| + | continue | ||
| + | |||
| + | try: | ||
| + | out = subprocess.check_output( | ||
| + | [" | ||
| + | " | ||
| + | text=True, | ||
| + | stderr=subprocess.DEVNULL | ||
| + | ) | ||
| + | except Exception: | ||
| + | print(f" | ||
| + | continue | ||
| + | |||
| + | expiry = None | ||
| + | subject = "" | ||
| + | issuer = "" | ||
| + | |||
| + | for line in out.splitlines(): | ||
| + | if line.startswith(" | ||
| + | raw = line.split(" | ||
| + | expiry = datetime.datetime.strptime(raw, | ||
| + | |||
| + | elif line.startswith(" | ||
| + | subject = line.replace(" | ||
| + | |||
| + | elif line.startswith(" | ||
| + | issuer = line.replace(" | ||
| + | |||
| + | if not expiry: | ||
| + | print(f" | ||
| + | continue | ||
| + | |||
| + | # ----------- days_left -------------- | ||
| + | days_left = (expiry - now).days | ||
| + | |||
| + | if days_left < CRIT_DAYS: | ||
| + | status = 2 | ||
| + | elif days_left < WARN_DAYS: | ||
| + | status = 1 | ||
| + | else: | ||
| + | status = 0 | ||
| + | |||
| + | expiry_str = expiry.strftime(" | ||
| + | |||
| + | svc = f" | ||
| + | |||
| + | summary = f" | ||
| + | |||
| + | if subject: | ||
| + | summary += f" {subject};" | ||
| + | if issuer: | ||
| + | summary += f" {issuer};" | ||
| + | |||
| + | print(f" | ||
| + | </ | ||
/home/http/wiki/data/attic/mysql_mit_ssl_verschluesselten_verbindungen.1712828842.txt · Zuletzt geändert: von manfred
