refactor(deployment): Remove WireGuard VPN dependency and restore public service access
Remove WireGuard integration from production deployment to simplify infrastructure: - Remove docker-compose-direct-access.yml (VPN-bound services) - Remove VPN-only middlewares from Grafana, Prometheus, Portainer - Remove WireGuard middleware definitions from Traefik - Remove WireGuard IPs (10.8.0.0/24) from Traefik forwarded headers All monitoring services now publicly accessible via subdomains: - grafana.michaelschiemer.de (with Grafana native auth) - prometheus.michaelschiemer.de (with Basic Auth) - portainer.michaelschiemer.de (with Portainer native auth) All services use Let's Encrypt SSL certificates via Traefik.
This commit is contained in:
165
tests/debug/test-data-placement-masking.php
Normal file
165
tests/debug/test-data-placement-masking.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use App\Framework\QrCode\QrCodeGenerator;
|
||||
use App\Framework\QrCode\ValueObjects\ErrorCorrectionLevel;
|
||||
use App\Framework\QrCode\ValueObjects\QrCodeConfig;
|
||||
use App\Framework\QrCode\ValueObjects\QrCodeVersion;
|
||||
use App\Framework\QrCode\ValueObjects\EncodingMode;
|
||||
|
||||
echo "=== Data Placement and Masking Test ===\n\n";
|
||||
|
||||
$testData = 'HELLO WORLD';
|
||||
$config = new QrCodeConfig(
|
||||
version: QrCodeVersion::fromNumber(1),
|
||||
errorCorrectionLevel: ErrorCorrectionLevel::M,
|
||||
encodingMode: EncodingMode::BYTE
|
||||
);
|
||||
|
||||
$matrix = QrCodeGenerator::generate($testData, $config);
|
||||
|
||||
// Decode format to get mask pattern
|
||||
$formatCols = [0, 1, 2, 3, 4, 5, 7, 8, 20, 19, 18, 17, 16, 15, 14];
|
||||
$formatH = '';
|
||||
foreach ($formatCols as $col) {
|
||||
$formatH .= $matrix->getModuleAt(8, $col)->isDark() ? '1' : '0';
|
||||
}
|
||||
|
||||
$xorMask = "101010000010010";
|
||||
$unmasked = '';
|
||||
for ($i = 0; $i < 15; $i++) {
|
||||
$unmasked .= (int)$formatH[$i] ^ (int)$xorMask[$i];
|
||||
}
|
||||
|
||||
$maskBits = substr($unmasked, 2, 3);
|
||||
$maskPattern = bindec($maskBits);
|
||||
|
||||
echo "Mask Pattern: {$maskPattern}\n";
|
||||
echo "EC Level: M\n\n";
|
||||
|
||||
// Check if we can decode the data by reading it back
|
||||
echo "=== Attempting to Decode Data ===\n";
|
||||
|
||||
// Read data bits in placement order (zig-zag, column pairs)
|
||||
$size = $matrix->getSize();
|
||||
$dataBits = '';
|
||||
$bitCount = 0;
|
||||
$maxBits = 26 * 8; // 26 codewords * 8 bits
|
||||
|
||||
// Remove mask first (unmask data area)
|
||||
$unmaskedMatrix = $matrix;
|
||||
for ($row = 0; $row < $size; $row++) {
|
||||
for ($col = 0; $col < $size; $col++) {
|
||||
// Skip function patterns
|
||||
if (
|
||||
($row <= 8 && $col <= 8) ||
|
||||
($row <= 7 && $col >= $size - 8) ||
|
||||
($row >= $size - 8 && $col <= 7) ||
|
||||
$row === 6 || $col === 6 ||
|
||||
($row === 8 && ($col <= 8 || $col >= $size - 8)) ||
|
||||
($col === 8 && ($row <= 7 || $row >= 9)) ||
|
||||
($row === 13 && $col === 8)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Unmask using pattern 3: (row + column) % 3 == 0
|
||||
if (($row + $col) % 3 === 0) {
|
||||
$currentModule = $matrix->getModuleAt($row, $col);
|
||||
$invertedModule = $currentModule->isDark()
|
||||
? \App\Framework\QrCode\ValueObjects\Module::light()
|
||||
: \App\Framework\QrCode\ValueObjects\Module::dark();
|
||||
$unmaskedMatrix = $unmaskedMatrix->setModuleAt($row, $col, $invertedModule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now read data bits in placement order
|
||||
// ISO/IEC 18004 Section 7.7.3: Column pairs, right-to-left, zig-zag
|
||||
for ($col = $size - 1; $col >= 1; $col -= 2) {
|
||||
if ($col === 6) {
|
||||
$col--;
|
||||
}
|
||||
|
||||
$upward = ((int) (($size - 1 - $col) / 2) % 2) === 0;
|
||||
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$row = $upward ? ($size - 1 - $i) : $i;
|
||||
|
||||
for ($c = 0; $c < 2; $c++) {
|
||||
$currentCol = $col - $c;
|
||||
|
||||
// Skip function patterns
|
||||
if (
|
||||
($row <= 8 && $currentCol <= 8) ||
|
||||
($row <= 7 && $currentCol >= $size - 8) ||
|
||||
($row >= $size - 8 && $currentCol <= 7) ||
|
||||
$row === 6 || $currentCol === 6 ||
|
||||
($row === 8 && ($currentCol <= 8 || $currentCol >= $size - 8)) ||
|
||||
($currentCol === 8 && ($row <= 7 || $row >= 9)) ||
|
||||
($row === 13 && $currentCol === 8)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($bitCount < $maxBits) {
|
||||
$isDark = $unmaskedMatrix->getModuleAt($row, $currentCol)->isDark();
|
||||
$dataBits .= $isDark ? '1' : '0';
|
||||
$bitCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "Read {$bitCount} bits from matrix\n";
|
||||
echo "Expected: {$maxBits} bits\n\n";
|
||||
|
||||
if ($bitCount < $maxBits) {
|
||||
echo "⚠️ Not enough bits read - data placement might be wrong\n";
|
||||
} else {
|
||||
echo "✅ Read all expected bits\n";
|
||||
}
|
||||
|
||||
// Try to decode first few bits
|
||||
echo "First 20 bits: " . substr($dataBits, 0, 20) . "\n";
|
||||
|
||||
// Mode indicator should be 0100 (Byte mode)
|
||||
$modeBits = substr($dataBits, 0, 4);
|
||||
echo "Mode indicator (first 4 bits): {$modeBits}\n";
|
||||
if ($modeBits === '0100') {
|
||||
echo "✅ Correct (Byte mode)\n";
|
||||
} else {
|
||||
echo "❌ Wrong! Expected 0100, got {$modeBits}\n";
|
||||
}
|
||||
|
||||
// Character count should be 11 (00001011)
|
||||
$countBits = substr($dataBits, 4, 8);
|
||||
$count = bindec($countBits);
|
||||
echo "Character count (bits 4-11): {$countBits} = {$count}\n";
|
||||
if ($count === 11) {
|
||||
echo "✅ Correct (11 characters)\n";
|
||||
} else {
|
||||
echo "❌ Wrong! Expected 11, got {$count}\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
|
||||
// Check if data can be partially decoded
|
||||
if (strlen($dataBits) >= 12) {
|
||||
echo "=== Partial Data Decode ===\n";
|
||||
$mode = bindec(substr($dataBits, 0, 4));
|
||||
$charCount = bindec(substr($dataBits, 4, 8));
|
||||
|
||||
echo "Mode: {$mode}\n";
|
||||
echo "Character count: {$charCount}\n";
|
||||
|
||||
if ($charCount === strlen($testData)) {
|
||||
echo "✅ Character count matches!\n";
|
||||
} else {
|
||||
echo "❌ Character count mismatch!\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user