- Added SSL configuration to the backend, including self-signed certificate generation and management. - Updated `setup_myp.sh` to create SSL certificates during installation. - Enhanced `app.py` to support SSL context for secure communication. - Introduced a new SSL management menu in the setup script for easier certificate handling. - Updated frontend API calls to use HTTPS for secure data transmission. - Implemented kiosk mode features, including automatic browser launch with SSL support. - Improved documentation in `SUMMARY.md` to reflect new features and network topology changes.
160 lines
4.2 KiB
Bash
Executable File
160 lines
4.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# MYP V2 - SSL-Zertifikat-Generator
|
|
# Erstellt selbstsignierte Zertifikate für die HTTPS-Kommunikation
|
|
|
|
# Fehlerabbruch aktivieren
|
|
set -e
|
|
|
|
# Farben für bessere Lesbarkeit
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[0;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Funktion für Titel
|
|
print_header() {
|
|
echo -e "${BLUE}================================================================${NC}"
|
|
echo -e "${BLUE} MYP V2 - SSL-Zertifikat-Generator ${NC}"
|
|
echo -e "${BLUE}================================================================${NC}"
|
|
echo ""
|
|
}
|
|
|
|
# Standardwerte
|
|
CERT_DIR="/opt/myp/ssl"
|
|
CERT_FILE="$CERT_DIR/myp.crt"
|
|
KEY_FILE="$CERT_DIR/myp.key"
|
|
DAYS_VALID=3650 # 10 Jahre
|
|
HOSTNAME=$(hostname -f)
|
|
IP_ADDRESS=$(hostname -I | awk '{print $1}')
|
|
|
|
# Hilfe-Funktion
|
|
show_help() {
|
|
echo "Verwendung: $0 [Optionen]"
|
|
echo ""
|
|
echo "Optionen:"
|
|
echo " -d, --dir DIR Verzeichnis für Zertifikate (Standard: $CERT_DIR)"
|
|
echo " -c, --cert DATEI Pfad zur Zertifikatsdatei (Standard: $CERT_FILE)"
|
|
echo " -k, --key DATEI Pfad zur Schlüsseldatei (Standard: $KEY_FILE)"
|
|
echo " -h, --hostname NAME Hostname für das Zertifikat (Standard: $HOSTNAME)"
|
|
echo " -i, --ip IP IP-Adresse für das Zertifikat (Standard: $IP_ADDRESS)"
|
|
echo " -v, --valid TAGE Gültigkeitsdauer in Tagen (Standard: $DAYS_VALID)"
|
|
echo " --help Diese Hilfe anzeigen"
|
|
echo ""
|
|
}
|
|
|
|
# Argumente verarbeiten
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-d|--dir)
|
|
CERT_DIR="$2"
|
|
shift 2
|
|
;;
|
|
-c|--cert)
|
|
CERT_FILE="$2"
|
|
shift 2
|
|
;;
|
|
-k|--key)
|
|
KEY_FILE="$2"
|
|
shift 2
|
|
;;
|
|
-h|--hostname)
|
|
HOSTNAME="$2"
|
|
shift 2
|
|
;;
|
|
-i|--ip)
|
|
IP_ADDRESS="$2"
|
|
shift 2
|
|
;;
|
|
-v|--valid)
|
|
DAYS_VALID="$2"
|
|
shift 2
|
|
;;
|
|
--help)
|
|
show_help
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo -e "${RED}Unbekannte Option: $1${NC}"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Header anzeigen
|
|
print_header
|
|
|
|
# Verzeichnis erstellen, falls es nicht existiert
|
|
if [ ! -d "$CERT_DIR" ]; then
|
|
echo -e "${YELLOW}Erstelle Verzeichnis $CERT_DIR...${NC}"
|
|
mkdir -p "$CERT_DIR"
|
|
fi
|
|
|
|
# Überprüfen, ob openssl installiert ist
|
|
if ! command -v openssl &> /dev/null; then
|
|
echo -e "${RED}OpenSSL ist nicht installiert!${NC}"
|
|
echo -e "${YELLOW}Installiere OpenSSL...${NC}"
|
|
apt-get update && apt-get install -y openssl
|
|
fi
|
|
|
|
# Zertifikat erstellen
|
|
echo -e "${GREEN}Erstelle selbstsigniertes SSL-Zertifikat...${NC}"
|
|
echo -e "${BLUE}Hostname: ${NC}$HOSTNAME"
|
|
echo -e "${BLUE}IP-Adresse: ${NC}$IP_ADDRESS"
|
|
echo -e "${BLUE}Gültigkeitsdauer: ${NC}$DAYS_VALID Tage"
|
|
echo -e "${BLUE}Zertifikatsdatei: ${NC}$CERT_FILE"
|
|
echo -e "${BLUE}Schlüsseldatei: ${NC}$KEY_FILE"
|
|
echo ""
|
|
|
|
# OpenSSL-Konfiguration erstellen
|
|
CONFIG_FILE="$CERT_DIR/openssl.cnf"
|
|
cat > "$CONFIG_FILE" << EOF
|
|
[req]
|
|
default_bits = 2048
|
|
prompt = no
|
|
default_md = sha256
|
|
distinguished_name = req_distinguished_name
|
|
x509_extensions = v3_req
|
|
|
|
[req_distinguished_name]
|
|
C = DE
|
|
ST = Baden-Wuerttemberg
|
|
L = Stuttgart
|
|
O = Mercedes-Benz AG
|
|
OU = MYP Platform
|
|
CN = $HOSTNAME
|
|
|
|
[v3_req]
|
|
keyUsage = critical, digitalSignature, keyAgreement
|
|
extendedKeyUsage = serverAuth
|
|
subjectAltName = @alt_names
|
|
|
|
[alt_names]
|
|
DNS.1 = $HOSTNAME
|
|
DNS.2 = localhost
|
|
IP.1 = $IP_ADDRESS
|
|
IP.2 = 127.0.0.1
|
|
EOF
|
|
|
|
# Schlüssel und Zertifikat generieren
|
|
openssl req -x509 -nodes -days "$DAYS_VALID" -newkey rsa:2048 \
|
|
-keyout "$KEY_FILE" -out "$CERT_FILE" \
|
|
-config "$CONFIG_FILE"
|
|
|
|
# Berechtigungen setzen
|
|
chmod 600 "$KEY_FILE"
|
|
chmod 644 "$CERT_FILE"
|
|
|
|
echo ""
|
|
echo -e "${GREEN}SSL-Zertifikat erfolgreich erstellt!${NC}"
|
|
echo -e "${YELLOW}Fingerprint:${NC}"
|
|
openssl x509 -noout -fingerprint -sha256 -in "$CERT_FILE"
|
|
echo ""
|
|
echo -e "${BLUE}Um diese Zertifikate mit Flask zu verwenden:${NC}"
|
|
echo " 1. Importiere die SSL-Einstellungen in der app.py"
|
|
echo " 2. Starte Flask mit SSL-Unterstützung"
|
|
echo ""
|
|
echo -e "${YELLOW}Beispiel:${NC}"
|
|
echo " app.run(host='0.0.0.0', port=5000, ssl_context=('$CERT_FILE', '$KEY_FILE'))"
|
|
echo "" |