50 lines
2.3 KiB
PHP
50 lines
2.3 KiB
PHP
<?php
|
|
// Run with the PHP version required by the pinned upstream composer.lock:
|
|
// php tests/fixtures/generate_laravel_sessions.php /path/to/upstream/vendor/autoload.php
|
|
require $argv[1] ?? __DIR__.'/../../../upstream/vendor/autoload.php';
|
|
|
|
use Illuminate\Auth\SessionGuard;
|
|
use Illuminate\Cookie\CookieValuePrefix;
|
|
use Illuminate\Encryption\Encrypter;
|
|
use Illuminate\Session\ArraySessionHandler;
|
|
use Illuminate\Session\EncryptedStore;
|
|
use Illuminate\Session\Store;
|
|
|
|
$key = '0123456789abcdef0123456789abcdef';
|
|
$cipher = new Encrypter($key, 'AES-256-CBC');
|
|
$guard = (new ReflectionClass(SessionGuard::class))->newInstanceWithoutConstructor();
|
|
(new ReflectionProperty(SessionGuard::class, 'name'))->setValue($guard, 'web-guard');
|
|
$id = str_repeat('F', 40);
|
|
$cookie = static fn ($name, $value) => rawurlencode($cipher->encryptString(CookieValuePrefix::create($name, $key).$value));
|
|
$fixtures = [];
|
|
foreach (['json', 'php'] as $serialization) {
|
|
foreach ([false, true] as $encrypted) {
|
|
$handler = new ArraySessionHandler(129600);
|
|
$store = $encrypted
|
|
? new EncryptedStore('2fauth_session', $handler, $cipher, $id, $serialization)
|
|
: new Store('2fauth_session', $handler, $id, $serialization);
|
|
$store->start();
|
|
$store->put('_token', 'real-php-csrf-🔐');
|
|
$store->put($guard->getName(), 7);
|
|
$store->put('preferences', ['language' => 'fr', 'enabled' => true]);
|
|
$store->save();
|
|
$fixtures[] = [
|
|
'php_version' => PHP_VERSION,
|
|
'framework_version' => Composer\InstalledVersions::getPrettyVersion('laravel/framework'),
|
|
'app_key' => $key,
|
|
'serialization' => $serialization,
|
|
'encrypted' => $encrypted,
|
|
'session_id' => $id,
|
|
'login_key' => $guard->getName(),
|
|
'recaller_name' => $guard->getRecallerName(),
|
|
'payload' => $handler->read($id),
|
|
'database_payload' => base64_encode($handler->read($id)),
|
|
'session_cookie' => $cookie('2fauth_session', $id),
|
|
'csrf_cookie' => $cookie('XSRF-TOKEN', $store->token()),
|
|
'recaller_cookie' => $cookie($guard->getRecallerName(), '7|remember-fixture|password-hash'),
|
|
'csrf' => $store->token(),
|
|
];
|
|
}
|
|
}
|
|
echo json_encode($fixtures, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)."\n";
|