SSL-Zertifikat-Generierung und Hostnamen-Konfiguration hinzugefügt
This commit is contained in:
parent
7ce1ee5df6
commit
f7953296f4
124
generate_ssl_certs_copy.ps1
Normal file
124
generate_ssl_certs_copy.ps1
Normal file
@ -0,0 +1,124 @@
|
||||
# MYP - SSL-Zertifikat-Generator für Windows
|
||||
# Erstellt selbstsignierte Zertifikate für die HTTPS-Kommunikation
|
||||
|
||||
# Überprüfen, ob das Skript als Administrator ausgeführt wird
|
||||
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
if (-not $isAdmin) {
|
||||
Write-Host "Dieses Skript muss mit Administrator-Rechten ausgeführt werden." -ForegroundColor Red
|
||||
Write-Host "Bitte starten Sie PowerShell als Administrator und führen Sie das Skript erneut aus." -ForegroundColor Yellow
|
||||
Exit 1
|
||||
}
|
||||
|
||||
# Header anzeigen
|
||||
Write-Host "================================================================" -ForegroundColor Blue
|
||||
Write-Host " MYP - SSL-Zertifikat-Generator " -ForegroundColor Blue
|
||||
Write-Host "================================================================" -ForegroundColor Blue
|
||||
Write-Host ""
|
||||
|
||||
# Parameter definieren
|
||||
$certDir = "./backend/instance/ssl"
|
||||
$backendCertFile = "$certDir/myp.crt"
|
||||
$backendKeyFile = "$certDir/myp.key"
|
||||
$frontendCertFile = "$certDir/frontend.crt"
|
||||
$frontendKeyFile = "$certDir/frontend.key"
|
||||
$backendHostname = "raspberrypi"
|
||||
$frontendHostname = "m040tbaraspi001.de040.corpintra.net"
|
||||
$validityDays = 3650 # 10 Jahre
|
||||
|
||||
# Verzeichnis erstellen, falls es nicht existiert
|
||||
if (!(Test-Path $certDir)) {
|
||||
Write-Host "Erstelle Verzeichnis $certDir..." -ForegroundColor Yellow
|
||||
New-Item -ItemType Directory -Path $certDir -Force | Out-Null
|
||||
}
|
||||
|
||||
# Prüfen, ob OpenSSL installiert ist
|
||||
$openSSLInstalled = $null
|
||||
try {
|
||||
$openSSLInstalled = Get-Command openssl -ErrorAction SilentlyContinue
|
||||
} catch {}
|
||||
|
||||
if ($null -eq $openSSLInstalled) {
|
||||
Write-Host "OpenSSL konnte nicht gefunden werden!" -ForegroundColor Red
|
||||
Write-Host "Bitte installieren Sie OpenSSL für Windows und stellen Sie sicher, dass es im PATH verfügbar ist." -ForegroundColor Yellow
|
||||
Write-Host "Sie können OpenSSL von https://slproweb.com/products/Win32OpenSSL.html herunterladen." -ForegroundColor Yellow
|
||||
Exit 1
|
||||
}
|
||||
|
||||
# Funktion zum Erstellen eines selbstsignierten Zertifikats
|
||||
function Create-SelfSignedCert {
|
||||
param(
|
||||
[string]$CertFile,
|
||||
[string]$KeyFile,
|
||||
[string]$Hostname,
|
||||
[int]$Days
|
||||
)
|
||||
|
||||
Write-Host "Erstelle selbstsigniertes SSL-Zertifikat für $Hostname..." -ForegroundColor Green
|
||||
|
||||
# OpenSSL-Konfiguration erstellen
|
||||
$configFile = "$certDir/openssl_$($Hostname.Split('.')[0]).cnf"
|
||||
|
||||
$configContent = @"
|
||||
[req]
|
||||
default_bits = 2048
|
||||
prompt = no
|
||||
default_md = sha256
|
||||
distinguished_name = req_distinguished_name
|
||||
x509_extensions = v3_req
|
||||
|
||||
[req_distinguished_name]
|
||||
C = DE
|
||||
ST = Berlin
|
||||
L = Berlin
|
||||
O = Mercedes-Benz AG
|
||||
OU = Werk 040 Berlin
|
||||
CN = $Hostname
|
||||
|
||||
[v3_req]
|
||||
keyUsage = critical, digitalSignature, keyAgreement
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = @alt_names
|
||||
|
||||
[alt_names]
|
||||
DNS.1 = $Hostname
|
||||
DNS.2 = localhost
|
||||
IP.1 = 127.0.0.1
|
||||
"@
|
||||
|
||||
$configContent | Out-File -FilePath $configFile -Encoding ASCII
|
||||
|
||||
# Zertifikat erstellen
|
||||
openssl req -x509 -nodes -days $Days -newkey rsa:2048 -keyout $KeyFile -out $CertFile -config $configFile
|
||||
|
||||
# Berechtigungen setzen
|
||||
if (Test-Path $KeyFile) {
|
||||
# Schlüsseldatei auf 'Nur-Lesen' setzen
|
||||
Set-ItemProperty -Path $KeyFile -Name IsReadOnly -Value $true
|
||||
}
|
||||
|
||||
# Fingerprint anzeigen
|
||||
$fingerprint = openssl x509 -noout -fingerprint -sha256 -in $CertFile
|
||||
Write-Host "Zertifikat erstellt: $CertFile" -ForegroundColor Green
|
||||
Write-Host "Fingerprint: $fingerprint" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
# Backend-Zertifikat erstellen
|
||||
Create-SelfSignedCert -CertFile $backendCertFile -KeyFile $backendKeyFile -Hostname $backendHostname -Days $validityDays
|
||||
|
||||
# Frontend-Zertifikat erstellen
|
||||
Create-SelfSignedCert -CertFile $frontendCertFile -KeyFile $frontendKeyFile -Hostname $frontendHostname -Days $validityDays
|
||||
|
||||
# Bestätigung und Hinweise
|
||||
Write-Host "SSL-Zertifikate wurden erfolgreich erstellt!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Backend-Zertifikat: $backendCertFile" -ForegroundColor Cyan
|
||||
Write-Host "Frontend-Zertifikat: $frontendCertFile" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "Hinweise zur Verwendung:" -ForegroundColor Yellow
|
||||
Write-Host "1. Stellen Sie sicher, dass die Zertifikatpfade in den Konfigurationsdateien korrekt sind." -ForegroundColor White
|
||||
Write-Host "2. Beim ersten Zugriff auf die Anwendung müssen Sie das Zertifikat im Browser akzeptieren." -ForegroundColor White
|
||||
Write-Host "3. In einer Produktionsumgebung sollten Sie offiziell signierte Zertifikate verwenden." -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "Starten Sie die Anwendung mit:" -ForegroundColor Blue
|
||||
Write-Host "docker-compose up -d" -ForegroundColor White
|
73
setup_hosts_copy.ps1
Normal file
73
setup_hosts_copy.ps1
Normal file
@ -0,0 +1,73 @@
|
||||
# MYP - Einrichtung der Hostnamen für die SSL-Konfiguration (Windows PowerShell Version)
|
||||
|
||||
# Überprüfen, ob das Skript als Administrator ausgeführt wird
|
||||
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
if (-not $isAdmin) {
|
||||
Write-Host "Dieses Skript muss mit Administrator-Rechten ausgeführt werden." -ForegroundColor Red
|
||||
Write-Host "Bitte starten Sie PowerShell als Administrator und führen Sie das Skript erneut aus." -ForegroundColor Yellow
|
||||
Exit 1
|
||||
}
|
||||
|
||||
# Header anzeigen
|
||||
Write-Host "=================================================" -ForegroundColor Blue
|
||||
Write-Host " MYP - Hostnamen-Konfiguration für SSL" -ForegroundColor Blue
|
||||
Write-Host "=================================================" -ForegroundColor Blue
|
||||
Write-Host ""
|
||||
|
||||
# Lokale IP-Adresse ermitteln
|
||||
$localIP = (Get-NetIPAddress | Where-Object { $_.AddressFamily -eq "IPv4" -and $_.PrefixOrigin -ne "WellKnown" } | Select-Object -First 1).IPAddress
|
||||
if (-not $localIP) {
|
||||
$localIP = "127.0.0.1"
|
||||
Write-Host "Konnte lokale IP-Adresse nicht ermitteln, verwende $localIP" -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host "Lokale IP-Adresse: $localIP" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Pfad zur Hosts-Datei
|
||||
$hostsFile = "$env:windir\System32\drivers\etc\hosts"
|
||||
Write-Host "Hosts-Datei: $hostsFile" -ForegroundColor Cyan
|
||||
|
||||
# Prüfen, ob die Einträge bereits existieren
|
||||
$frontendEntry = Select-String -Path $hostsFile -Pattern "m040tbaraspi001.de040.corpintra.net" -Quiet
|
||||
$backendEntry = Select-String -Path $hostsFile -Pattern "raspberrypi" -Quiet
|
||||
|
||||
# Einträge in die Hosts-Datei schreiben
|
||||
Write-Host "Aktualisiere Hosts-Datei..." -ForegroundColor Blue
|
||||
|
||||
$hostsContent = Get-Content -Path $hostsFile
|
||||
|
||||
if (-not $frontendEntry) {
|
||||
$hostsContent += ""
|
||||
$hostsContent += "# MYP Frontend Host"
|
||||
$hostsContent += "$localIP m040tbaraspi001.de040.corpintra.net m040tbaraspi001"
|
||||
Write-Host "Frontend-Hostname hinzugefügt" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Frontend-Hostname ist bereits konfiguriert" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
if (-not $backendEntry) {
|
||||
$hostsContent += ""
|
||||
$hostsContent += "# MYP Backend Host"
|
||||
$hostsContent += "$localIP raspberrypi"
|
||||
Write-Host "Backend-Hostname hinzugefügt" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Backend-Hostname ist bereits konfiguriert" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Speichern der aktualisierten Hosts-Datei
|
||||
try {
|
||||
$hostsContent | Set-Content -Path $hostsFile -Force
|
||||
Write-Host ""
|
||||
Write-Host "Konfiguration abgeschlossen!" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "Fehler beim Schreiben der Hosts-Datei: $_" -ForegroundColor Red
|
||||
Exit 1
|
||||
}
|
||||
|
||||
Write-Host "Folgende Hostnamen sind jetzt konfiguriert:" -ForegroundColor Blue
|
||||
Write-Host " - Frontend: m040tbaraspi001.de040.corpintra.net" -ForegroundColor Yellow
|
||||
Write-Host " - Backend: raspberrypi" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
Write-Host "Sie können nun die Anwendung mit folgendem Befehl starten:" -ForegroundColor Blue
|
||||
Write-Host "docker-compose up -d" -ForegroundColor Yellow
|
||||
Write-Host ""
|
Loading…
x
Reference in New Issue
Block a user