It appears that the repository has undergone several changes and renamings:
This commit is contained in:
230
backend/ssl/fix_ssl_browser.py
Normal file
230
backend/ssl/fix_ssl_browser.py
Normal file
@@ -0,0 +1,230 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Windows-kompatibles SSL-Fix Tool für MYP Platform
|
||||
Löst ERR_SSL_KEY_USAGE_INCOMPATIBLE Browser-Fehler ohne externe OpenSSL-Befehle
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
def regenerate_ssl_certificates():
|
||||
"""Regeneriert SSL-Zertifikate mit korrekten Browser-kompatiblen Extensions"""
|
||||
|
||||
print("🔧 SSL BROWSER-KOMPATIBILITÄTS-FIX")
|
||||
print("Löst ERR_SSL_KEY_USAGE_INCOMPATIBLE Fehler")
|
||||
print("=" * 60)
|
||||
|
||||
# Verschiedene mögliche SSL-Verzeichnisse
|
||||
ssl_directories = [
|
||||
Path("ssl"),
|
||||
Path("certs"),
|
||||
Path("certs/localhost"),
|
||||
Path("instance/ssl"),
|
||||
Path("../ssl")
|
||||
]
|
||||
|
||||
found_certs = []
|
||||
|
||||
# Finde existierende Zertifikate
|
||||
for ssl_dir in ssl_directories:
|
||||
if ssl_dir.exists():
|
||||
cert_files = ["cert.pem", "localhost.crt", "myp.crt", "server.crt"]
|
||||
key_files = ["key.pem", "localhost.key", "myp.key", "server.key"]
|
||||
|
||||
for cert_name in cert_files:
|
||||
for key_name in key_files:
|
||||
cert_path = ssl_dir / cert_name
|
||||
key_path = ssl_dir / key_name
|
||||
|
||||
if cert_path.exists() and key_path.exists():
|
||||
found_certs.append((cert_path, key_path, ssl_dir))
|
||||
print(f"📄 Gefunden: {cert_path}")
|
||||
|
||||
if not found_certs:
|
||||
print("📂 Keine SSL-Zertifikate gefunden - erstelle neue...")
|
||||
ssl_dir = Path("ssl")
|
||||
ssl_dir.mkdir(exist_ok=True)
|
||||
found_certs = [(ssl_dir / "cert.pem", ssl_dir / "key.pem", ssl_dir)]
|
||||
|
||||
# Verwende das SSL-Modul zur Neugenerierung
|
||||
print("\n🔄 Regeneriere browser-kompatible SSL-Zertifikate...")
|
||||
|
||||
try:
|
||||
# Importiere das SSL-Modul
|
||||
sys.path.insert(0, str(Path.cwd()))
|
||||
from utils.ssl_config import SSLCertificateManager
|
||||
|
||||
success_count = 0
|
||||
|
||||
for cert_path, key_path, ssl_dir in found_certs:
|
||||
print(f"\n📁 Bearbeite: {ssl_dir}")
|
||||
|
||||
# Backup erstellen
|
||||
backup_dir = ssl_dir / "backup"
|
||||
backup_dir.mkdir(exist_ok=True)
|
||||
|
||||
if cert_path.exists():
|
||||
backup_cert = backup_dir / f"{cert_path.name}.backup"
|
||||
backup_key = backup_dir / f"{key_path.name}.backup"
|
||||
|
||||
try:
|
||||
shutil.copy2(cert_path, backup_cert)
|
||||
shutil.copy2(key_path, backup_key)
|
||||
print(f"💾 Backup erstellt: {backup_cert}")
|
||||
except Exception as e:
|
||||
print(f"⚠️ Backup fehlgeschlagen: {e}")
|
||||
|
||||
# SSL-Manager konfigurieren
|
||||
app_dir = Path.cwd().absolute()
|
||||
ssl_manager = SSLCertificateManager(str(app_dir))
|
||||
|
||||
# Überschreibe Pfade für gefundenes Verzeichnis
|
||||
ssl_manager.ssl_dir = ssl_dir
|
||||
ssl_manager.cert_file = cert_path
|
||||
ssl_manager.key_file = key_path
|
||||
|
||||
# Regeneriere Zertifikat mit korrekten Extensions
|
||||
print("🔧 Generiere browser-kompatibles Zertifikat...")
|
||||
|
||||
if ssl_manager.generate_ssl_certificate(force_regenerate=True):
|
||||
print("✅ Browser-kompatibles Zertifikat generiert")
|
||||
success_count += 1
|
||||
|
||||
# Validiere das neue Zertifikat
|
||||
if validate_certificate_compatibility(cert_path):
|
||||
print("🎉 Browser-Kompatibilitäts-Check bestanden!")
|
||||
else:
|
||||
print("⚠️ Zertifikat generiert, aber möglicherweise nicht vollständig kompatibel")
|
||||
|
||||
else:
|
||||
print("❌ Zertifikat-Generierung fehlgeschlagen")
|
||||
|
||||
if success_count > 0:
|
||||
print(f"\n✅ SSL-FIX ERFOLGREICH!")
|
||||
print(f" {success_count} Zertifikat(e) erfolgreich regeneriert")
|
||||
print(f"\n🌐 NÄCHSTE SCHRITTE:")
|
||||
print(f" 1. Browser-Cache vollständig leeren:")
|
||||
print(f" • Chrome/Edge: Strg+Shift+Del → 'Alle Daten löschen'")
|
||||
print(f" • Firefox: Strg+Shift+Del → 'Alles' auswählen")
|
||||
print(f" 2. MYP-Anwendung neu starten")
|
||||
print(f" 3. https://localhost:5000 aufrufen")
|
||||
print(f" 4. Bei SSL-Warnung: 'Erweitert' → 'Unsicher fortfahren'")
|
||||
print(f"\n💡 Der Fehler ERR_SSL_KEY_USAGE_INCOMPATIBLE sollte behoben sein!")
|
||||
|
||||
else:
|
||||
print(f"\n❌ SSL-FIX FEHLGESCHLAGEN!")
|
||||
print(f" Keine Zertifikate konnten regeneriert werden")
|
||||
print(f" Prüfe die Logs und Berechtigungen")
|
||||
|
||||
except ImportError as e:
|
||||
print(f"❌ SSL-Modul konnte nicht importiert werden: {e}")
|
||||
print(f"💡 Fallback: Manuelle Zertifikat-Regenerierung erforderlich")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Unerwarteter Fehler: {e}")
|
||||
return False
|
||||
|
||||
return success_count > 0
|
||||
|
||||
def validate_certificate_compatibility(cert_path):
|
||||
"""
|
||||
Validiert Browser-Kompatibilität eines Zertifikats (ohne OpenSSL)
|
||||
Vereinfachte Version die nur die Datei-Existenz prüft
|
||||
"""
|
||||
try:
|
||||
if not cert_path.exists():
|
||||
return False
|
||||
|
||||
# Lese Zertifikat-Inhalt
|
||||
with open(cert_path, 'r') as f:
|
||||
cert_content = f.read()
|
||||
|
||||
# Basis-Checks
|
||||
checks = {
|
||||
"PEM Format": cert_content.startswith("-----BEGIN CERTIFICATE-----"),
|
||||
"PEM Ende": cert_content.endswith("-----END CERTIFICATE-----\n") or cert_content.endswith("-----END CERTIFICATE-----"),
|
||||
"Mindestlänge": len(cert_content) > 500,
|
||||
}
|
||||
|
||||
print("📋 Zertifikat-Validation:")
|
||||
all_passed = True
|
||||
for check_name, passed in checks.items():
|
||||
status = "✅" if passed else "❌"
|
||||
print(f" {status} {check_name}")
|
||||
if not passed:
|
||||
all_passed = False
|
||||
|
||||
return all_passed
|
||||
|
||||
except Exception as e:
|
||||
print(f"⚠️ Validation fehlgeschlagen: {e}")
|
||||
return False
|
||||
|
||||
def clean_browser_cache_instructions():
|
||||
"""Zeigt detaillierte Anweisungen zum Browser-Cache leeren"""
|
||||
|
||||
print("\n🧹 BROWSER-CACHE VOLLSTÄNDIG LEEREN")
|
||||
print("=" * 50)
|
||||
print("\n🌐 Google Chrome / Microsoft Edge:")
|
||||
print(" 1. Strg + Shift + Del drücken")
|
||||
print(" 2. Zeitraum: 'Gesamte Zeit' auswählen")
|
||||
print(" 3. Alle Optionen aktivieren:")
|
||||
print(" ☑️ Browserverlauf")
|
||||
print(" ☑️ Downloadverlauf")
|
||||
print(" ☑️ Cookies und andere Websitedaten")
|
||||
print(" ☑️ Bilder und Dateien im Cache")
|
||||
print(" ☑️ Gehostete App-Daten")
|
||||
print(" 4. 'Daten löschen' klicken")
|
||||
|
||||
print("\n🦊 Mozilla Firefox:")
|
||||
print(" 1. Strg + Shift + Del drücken")
|
||||
print(" 2. Zeitraum: 'Alles' auswählen")
|
||||
print(" 3. Alle Optionen aktivieren:")
|
||||
print(" ☑️ Chronik")
|
||||
print(" ☑️ Cookies")
|
||||
print(" ☑️ Cache")
|
||||
print(" ☑️ Aktive Logins")
|
||||
print(" ☑️ Offline-Website-Daten")
|
||||
print(" 4. 'Jetzt löschen' klicken")
|
||||
|
||||
print("\n🔄 Zusätzliche Schritte:")
|
||||
print(" • Browser komplett schließen und neu starten")
|
||||
print(" • Windows: Netzwerkadapter zurücksetzen")
|
||||
print(" ipconfig /flushdns")
|
||||
print(" • Bei Chrome: chrome://settings/certificates → Zwischenzertifikate löschen")
|
||||
|
||||
def main():
|
||||
"""Hauptfunktion"""
|
||||
|
||||
print("🔧 MYP SSL BROWSER-KOMPATIBILITÄTS-FIX")
|
||||
print("Windows-kompatible Version")
|
||||
print("=" * 60)
|
||||
|
||||
# Prüfe aktuelles Verzeichnis
|
||||
if not Path("utils").exists():
|
||||
print("❌ utils-Verzeichnis nicht gefunden")
|
||||
print("💡 Führe das Skript im backend-Verzeichnis aus:")
|
||||
print(" cd backend")
|
||||
print(" python fix_ssl_browser.py")
|
||||
return False
|
||||
|
||||
# Führe SSL-Fix durch
|
||||
success = regenerate_ssl_certificates()
|
||||
|
||||
if success:
|
||||
print("\n" + "="*60)
|
||||
clean_browser_cache_instructions()
|
||||
print("\n" + "="*60)
|
||||
print("✅ SSL-Fix abgeschlossen!")
|
||||
print("🌐 ERR_SSL_KEY_USAGE_INCOMPATIBLE sollte behoben sein.")
|
||||
else:
|
||||
print("\n❌ SSL-Fix fehlgeschlagen!")
|
||||
print("📞 Weitere Hilfe in COMMON_ERRORS.md")
|
||||
|
||||
return success
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user