v0.6 + v1.0: HMAC download URLs, launcher self-update, Inno Setup installer

Three deliverables shipped together so the next deployment cycle has a
clean distribution story.

(1) Auto-update of the launcher itself
---------------------------------------
- Models: RemoteManifest gains an optional `launcher` section
  (LauncherInfo: version, minRequired, download {url,size,sha256},
   releaseNotesUrl). Server-side, sign-manifest.php passes it through
  unchanged; admins edit versions.json with the new launcher entry +
  upload PSLauncher-X.Y.Z.exe to /builds/launcher/.
- Core: ILauncherSelfUpdater compares assembly version against
  manifest.launcher.version using the existing SemVer parser, and
  reuses DownloadManager (Range/resume/sha256 already proven on the
  game ZIPs) to download the new exe into
  %LocalAppData%/PSLauncher/selfupdate/.
- New project PSLauncher.Updater (~34 MB self-contained console exe):
  spawned by the main app with --target / --source / --pid / --launch.
  Waits for the main process to exit (or for the file lock to release),
  backs up the current exe to .bak, copies the new file in place, and
  restarts. .bak survives the swap so the user can roll back manually.
- App.csproj now declares Version=0.5.0 — currently shipped baseline.
  PSLauncher.App.csproj sets a fixed AssemblyVersion so reflection-based
  comparison works deterministically.
- MainViewModel.PromptLauncherUpdate: dialog after CheckForUpdates if
  the manifest advertises a newer launcher. Download with progress in
  the existing footer, then Application.Shutdown() so the Updater can
  do its job.

(2) Inno Setup installer
------------------------
installer/PSLauncher.iss + build-installer.ps1 produce a single
PSLauncher-Setup-X.Y.Z.exe (~80 MB) that installs into
Program Files\ASTERION VR\PSLauncher\, drops both PSLauncher.exe and
PSLauncher.Updater.exe side by side (the updater MUST live next to
the target), creates Start Menu + optional Desktop shortcuts, and
registers a clean uninstall entry. The user's %LocalAppData%
(license, logs, cache) is intentionally untouched on uninstall — same
license survives a reinstall.

build-installer.ps1 chains dotnet publish for both projects and ISCC
in one command. README explains the bump-version workflow.

(3) HMAC-signed download URLs
-----------------------------
- New PHP route GET /api/download-url/{version} (Authorization: Bearer
  <licenseKey> or ?key=...). Validates the license, checks
  download_entitlement_until >= minLicenseDate of the version, and
  returns a HMAC-signed URL (path|exp|licId, hash_hmac SHA-256, valid
  1 h) + sha256 + sizeBytes for verification.
- /builds/.htaccess routes every *.zip request to gate.php. gate.php
  validates exp, lic, sig (constant-time hash_equals), then streams
  the file with Range: support so the launcher's resume keeps working.
  Audit log gets a download_url_issued entry per request.
- Client-side wired transparently: LicenseService gains
  GetSignedDownloadUrlAsync(version) that GETs the endpoint with the
  decrypted license key from DPAPI. MainViewModel calls it before
  every download; if the endpoint returns 404/401/network-error, the
  client falls back to the manifest's plain download.url (graceful
  degradation for setups that haven't deployed gate.php yet).

Note on PHP streaming for 14 GB ZIPs: gate.php uses set_time_limit(0)
+ ignore_user_abort(true) + 1 MiB chunked fread with periodic flush.
Works on OVH mutualisé but holds a PHP-FPM slot for the duration. If
parallel downloads scale past a few clients, switch to
mod_xsendfile or migrate /builds/ to Cloudflare R2 with native
S3-presigned URLs and remove the gate entirely.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-02 09:38:13 +02:00
parent b10a3fbabf
commit b7de228bc9
20 changed files with 798 additions and 2 deletions

View File

@@ -60,6 +60,14 @@ if ($method === 'POST' && $route === 'license/validate') {
return;
}
if ($method === 'GET' && preg_match('#^download-url/([0-9]+\.[0-9]+\.[0-9]+)$#', $route, $m)) {
require __DIR__ . '/lib/Db.php';
require __DIR__ . '/lib/Crypto.php';
require __DIR__ . '/routes/DownloadUrl.php';
\PSLauncher\Routes\DownloadUrl::handle($config, $m[1]);
return;
}
if ($method === 'GET' && $route === 'health') {
Response::json([
'status' => 'ok',

View File

@@ -0,0 +1,111 @@
<?php
declare(strict_types=1);
namespace PSLauncher\Routes;
use PSLauncher\Crypto;
use PSLauncher\Db;
use PSLauncher\Response;
/**
* GET /api/download-url/{version}
* Header : Authorization: Bearer <licenseKey>
*
* Vérifie la license, vérifie qu'elle autorise cette version (date d'entitlement
* >= minLicenseDate), puis renvoie une URL HMAC-signée valide 1 h vers le ZIP
* dans /builds/.
*/
final class DownloadUrl
{
public static function handle(array $config, string $version): void
{
if (!preg_match('/^[0-9]+\.[0-9]+\.[0-9]+$/', $version)) {
Response::error('invalid_version', 'Version invalide', 400);
}
// Auth via Authorization: Bearer <licenseKey>
$authHeader = $_SERVER['HTTP_AUTHORIZATION'] ?? '';
if (!preg_match('/^Bearer\s+(.+)$/i', $authHeader, $m)) {
// Fallback : certains hébergements masquent Authorization. On accepte aussi ?key=
$licenseKey = trim((string)($_GET['key'] ?? ''));
if ($licenseKey === '') {
Response::error('unauthorized', 'License key requise (Authorization: Bearer ... ou ?key=...)', 401);
}
} else {
$licenseKey = trim($m[1]);
}
$db = Db::get($config);
$stmt = $db->prepare(
'SELECT id, owner_name, download_entitlement_until, revoked_at
FROM licenses WHERE license_key = ? LIMIT 1'
);
$stmt->execute([$licenseKey]);
$lic = $stmt->fetch();
if (!$lic) {
Response::error('invalid', 'License inconnue', 401);
}
if ($lic['revoked_at'] !== null) {
Response::error('revoked', 'License révoquée', 403);
}
// Charge le manifest pour récupérer minLicenseDate de cette version
$manifestPath = dirname(__DIR__, 2) . '/manifest/versions.json';
if (!is_file($manifestPath)) {
Response::error('manifest_missing', 'Manifest absent côté serveur', 500);
}
$manifest = json_decode(file_get_contents($manifestPath), true);
$entry = null;
foreach ($manifest['versions'] ?? [] as $v) {
if (($v['version'] ?? '') === $version) { $entry = $v; break; }
}
if (!$entry) {
Response::error('version_not_found', "Version {$version} absente du manifest", 404);
}
// Vérif droits téléchargement
$entUntil = strtotime($lic['download_entitlement_until']);
$minDate = isset($entry['minLicenseDate']) ? strtotime($entry['minLicenseDate']) : 0;
if ($minDate > 0 && $entUntil < $minDate) {
Response::error('entitlement_expired',
'Cette license n\'autorise pas cette version (date d\'expiration trop ancienne)',
403,
[
'entitlementUntil' => date(\DateTimeInterface::ATOM, $entUntil),
'minLicenseDate' => date(\DateTimeInterface::ATOM, $minDate),
]);
}
// Génère l'URL HMAC-signée
$baseUrl = rtrim($config['base_url'], '/');
$relPath = '/builds/proserve-' . $version . '.zip';
$exp = time() + 3600; // 1 h
$secret = $config['hmac_secret'] ?? '';
if ($secret === '') {
Response::error('config_error', 'hmac_secret non configuré', 500);
}
$sigInput = $relPath . '|' . $exp . '|' . $lic['id'];
$sig = Crypto::hmacHex($sigInput, $secret);
$signedUrl = $baseUrl . $relPath . '?exp=' . $exp . '&lic=' . $lic['id'] . '&sig=' . $sig;
// Audit
try {
$db->prepare(
'INSERT INTO audit_log (ts, license_id, ip, event, detail) VALUES (NOW(), ?, ?, ?, ?)'
)->execute([
$lic['id'],
$_SERVER['REMOTE_ADDR'] ?? null,
'download_url_issued',
json_encode(['version' => $version], JSON_UNESCAPED_UNICODE),
]);
} catch (\Throwable) { /* best-effort */ }
Response::json([
'url' => $signedUrl,
'expiresAt' => date(\DateTimeInterface::ATOM, $exp),
'sizeBytes' => $entry['download']['sizeBytes'] ?? 0,
'sha256' => $entry['download']['sha256'] ?? '',
]);
}
}