#!/usr/bin/env pwsh # ObsiGate Desktop — Windows code signing (scaffolding). # # Signe le binaire et l'installateur MSI/NSIS après un `cargo tauri build`. # Aucun certificat n'est embarqué : les identifiants sont lus depuis # l'environnement (jamais commités). Le script est un no-op explicite si # l'env n'est pas configuré — le build reste donc fonctionnel sans signature. # # Variables d'environnement : # OBSIGATE_SIGN_CERT_PFX chemin du .pfx (requis) # OBSIGATE_SIGN_CERT_PASSWORD mot de passe du .pfx (optionnel) # OBSIGATE_SIGN_TIMESTAMP_URL URL du serveur d'horodatage RFC3161 # (défaut : http://timestamp.digicert.com) # OBSIGATE_SIGN_MODE "signtool" (Windows) ou "osslsigncode" (Linux) # # Usage : # ./scripts/sign-windows.ps1 # après le build, signe les artefacts # OBSIGATE_SIGN_CERT_PFX=cert.pfx ./scripts/sign-windows.ps1 $ErrorActionPreference = 'Stop' $pfx = $env:OBSIGATE_SIGN_CERT_PFX if (-not $pfx) { Write-Host "⚠ Aucun certificat fourni (OBSIGATE_SIGN_CERT_PFX). Signature ignorée — build non signé." exit 0 } $password = $env:OBSIGATE_SIGN_CERT_PASSWORD $tsUrl = if ($env:OBSIGATE_SIGN_TIMESTAMP_URL) { $env:OBSIGATE_SIGN_TIMESTAMP_URL } else { 'http://timestamp.digicert.com' } $mode = if ($env:OBSIGATE_SIGN_MODE) { $env:OBSIGATE_SIGN_MODE } else { 'signtool' } $targets = @( 'target/release/obsigate-desktop.exe', 'target/release/bundle/msi/*.msi', 'target/release/bundle/nsis/*-setup.exe' ) | ForEach-Object { Get-Item $_ -ErrorAction SilentlyContinue } | Where-Object { $_ } if ($targets.Count -eq 0) { Write-Host "⚠ Aucun artefact à signer trouvé (lancer d'abord `cargo tauri build`)." exit 0 } foreach ($t in $targets) { Write-Host "✍ Signature de $($t.FullName) (mode: $mode)" if ($mode -eq 'osslsigncode') { $args = @('sign', '-pkcs12', $pfx, '-h', 'sha256') if ($password) { $args += @('-pass', $password) } $args += @('-ts', $tsUrl, '-in', $t.FullName, '-out', $t.FullName) & osslsigncode @args if ($LASTEXITCODE -ne 0) { throw "osslsigncode a échoué pour $($t.Name)" } } else { $args = @('sign', '/fd', 'SHA256', '/f', $pfx, '/tr', $tsUrl, '/td', 'SHA256') if ($password) { $args += @('/p', $password) } $args += $t.FullName & signtool @args if ($LASTEXITCODE -ne 0) { throw "signtool a échoué pour $($t.Name)" } } } Write-Host "✅ $($targets.Count) artefact(s) signé(s)."