This commit is contained in:
torsten 2026-10-20 22:46:23 +02:00
parent ab2311587c
commit 9fcd228eb2
13 changed files with 398 additions and 14 deletions

View file

@ -70,6 +70,8 @@ def build_htaccess(creds):
"SetEnv DB_PASS " + creds["mysql_pw"],
"SetEnv DB_NEW_NAME " + creds["mysql_db"],
"SetEnv APP_URL " + APP_URL,
"SetEnv IBAN_KEY " + creds.get("iban_key", ""),
"SetEnv REMINDER_TOKEN " + creds.get("reminder_token", ""),
"",
]
)

View file

@ -21,6 +21,10 @@ services:
- MAIL_FROM_NAME=Hoschis Tippspiel
- APP_URL=http://localhost:8080
- REMINDER_TOKEN=lokal-geheim
# Schlüssel für die IBAN-Verschlüsselung (base64, 32 Byte).
# MUSS mit "iban_key" in docs/testsystem_credentials.txt übereinstimmen:
# die lokale DB wird verschlüsselt und per deploy_test.py zur Remote synct.
- IBAN_KEY=/eG0tnvUGe02AR3ABgIJyMQdujnilxK7NkXhQubd3Rw=
depends_on:
- db
- mailpit

65
tools/encrypt_ibans.php Normal file
View file

@ -0,0 +1,65 @@
<?php
// Migrations-Skript: verschlüsselt vorhandene IBAN-Klartextwerte in der
// `users`-Tabelle mit dem Schlüssel aus IBAN_KEY. Idempotent: bereits
// verschlüsselte Werte (Präfix "enc:v1:") werden übersprungen.
//
// Aufruf (im Docker-Container, IBAN_KEY muss gesetzt sein):
// docker compose exec app php encrypt_ibans.php
$host = getenv('DB_HOST') ?: '127.0.0.1';
$user = getenv('DB_USER') ?: 'root';
$pass = getenv('DB_PASS') ?: '';
$dbName = getenv('DB_NEW_NAME') ?: 'tippspiel2027';
// Crypto-Klasse laden (funktioniert im Container und direkt auf dem Host).
$cryptoCandidates = [
__DIR__ . '/../tippspiel/src/Core/Crypto.php',
__DIR__ . '/src/Core/Crypto.php',
];
$cryptoFile = null;
foreach ($cryptoCandidates as $candidate) {
if (file_exists($candidate)) {
$cryptoFile = $candidate;
break;
}
}
if ($cryptoFile === null) {
die("Fehler: Crypto.php nicht gefunden.\n");
}
require_once $cryptoFile;
use App\Core\Crypto;
try {
if (Crypto::key() === null) {
die("Fehler: IBAN_KEY ist nicht gesetzt. Bitte zuerst einen Schlüssel erzeugen "
. "(openssl rand -base64 32) und als Umgebungsvariable setzen.\n");
}
$pdo = new PDO("mysql:host=$host;dbname=$dbName;charset=utf8mb4", $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$rows = $pdo->query("SELECT id, iban FROM users WHERE iban IS NOT NULL AND iban <> ''")->fetchAll(PDO::FETCH_ASSOC);
$encrypted = 0;
$skipped = 0;
$stmt = $pdo->prepare("UPDATE users SET iban = ?, updated_at = NOW() WHERE id = ?");
foreach ($rows as $row) {
$iban = (string)$row['iban'];
if (Crypto::isEncrypted($iban)) {
$skipped++;
continue;
}
$stmt->execute([Crypto::encrypt($iban), $row['id']]);
$encrypted++;
}
echo "Fertig: {$encrypted} IBAN(s) verschlüsselt, {$skipped} bereits verschlüsselt übersprungen.\n";
} catch (PDOException $e) {
die("Datenbankfehler: " . $e->getMessage() . "\n");
} catch (\Throwable $e) {
die("Fehler: " . $e->getMessage() . "\n");
}

View file

@ -4,6 +4,24 @@
// Dieses Skript verbindet sich mit einer alten Datenbank (wo der Live-Dump importiert wurde)
// und kopiert die relevanten Daten in die neue tippspiel2027 Datenbank.
// Tote Features wie "Spieler Ligen" und "grünes Trikot" werden ignoriert.
// IBANs werden beim Import direkt verschlüsselt (sofern IBAN_KEY gesetzt ist),
// damit Klartext-IBANs gar nicht erst in der neuen DB landen.
// Crypto-Klasse laden (funktioniert im Container und direkt auf dem Host).
$cryptoCandidates = [
__DIR__ . '/../tippspiel/src/Core/Crypto.php',
__DIR__ . '/src/Core/Crypto.php',
];
$cryptoFile = null;
foreach ($cryptoCandidates as $candidate) {
if (file_exists($candidate)) {
$cryptoFile = $candidate;
break;
}
}
if ($cryptoFile !== null) {
require_once $cryptoFile;
}
$host = getenv('DB_HOST') ?: '127.0.0.1';
$user = getenv('DB_USER') ?: 'root';
@ -76,6 +94,11 @@ try {
}
}
// IBAN beim Import verschlüsseln (ohne IBAN_KEY bleibt sie Klartext)
if ($table === 'users' && $cryptoFile !== null && !empty($filteredRow['iban'])) {
$filteredRow['iban'] = \App\Core\Crypto::encrypt((string)$filteredRow['iban']);
}
if (!empty($filteredRow)) {
$cols = '`' . implode('`, `', array_keys($filteredRow)) . '`';
$vals = implode(', ', array_fill(0, count($filteredRow), '?'));

View file

@ -6,7 +6,7 @@ CREATE TABLE `users` (
`lastname` varchar(100) DEFAULT NULL,
`email` varchar(150) NOT NULL,
`password` varchar(100) NOT NULL,
`iban` varchar(128) DEFAULT NULL,
`iban` varchar(255) DEFAULT NULL,
`bankname` varchar(64) DEFAULT NULL,
`blz` varchar(20) DEFAULT NULL,
`kontonr` varchar(64) DEFAULT NULL,