fix: Geräte-Pairing - Schlüssel-Code stimmte nie mit dem angezeigten Code überein
SnapshotService.CreateAndUploadAsync lädt in zwei Schritten hoch: Schritt 1 holt einen Code vom Server, Schritt 2 verschlüsselt den Sync-Schlüssel mit diesem Code und lädt erneut hoch. SnapshotStore.Store() vergab bei jedem Aufruf bedingungslos einen neuen Zufallscode - der dem Nutzer am Ende angezeigte Code war dadurch nie derselbe, mit dem der Schlüssel tatsächlich verschlüsselt wurde. Jede Kopplung musste deterministisch an der Schlüssel-Entschlüsselung scheitern. SnapshotUploadRequest bekommt ein optionales Code-Feld; Store() aktualisiert bei vorhandenem, passendem Code denselben Eintrag statt einen neuen mit neuem Code anzulegen. Betrifft LehrerApp.Api - der Server muss neu deployt werden. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -69,6 +69,10 @@ public class SnapshotUploadRequest
|
||||
public string EncryptedPayload { get; init; } = "";
|
||||
public string EncryptedSyncKey { get; init; } = "";
|
||||
public DeviceType DeviceType { get; init; }
|
||||
/// Gesetzt beim zweiten Upload-Schritt (Schlüssel nachreichen, siehe SnapshotService.
|
||||
/// CreateAndUploadAsync) — muss dem im ersten Schritt vom Server vergebenen Code entsprechen,
|
||||
/// damit derselbe Eintrag aktualisiert statt ein neuer (mit neuem Code) angelegt wird.
|
||||
public string? Code { get; init; }
|
||||
}
|
||||
public class SnapshotUploadResponse
|
||||
{
|
||||
|
||||
@@ -39,7 +39,8 @@ public class SnapshotService(
|
||||
var encKey = SyncCrypto.EncryptKeyWithCode(syncKey, init.Code);
|
||||
var r2 = await http.PostAsJsonAsync("/api/snapshot/upload",
|
||||
new SnapshotUploadRequest { EncryptedPayload = encPayload,
|
||||
EncryptedSyncKey = encKey, DeviceType = deviceType }, ct);
|
||||
EncryptedSyncKey = encKey, DeviceType = deviceType,
|
||||
Code = init.Code }, ct);
|
||||
r2.EnsureSuccessStatusCode();
|
||||
var result = await r2.Content.ReadFromJsonAsync<SnapshotUploadResponse>(ct)
|
||||
?? throw new InvalidOperationException("Leere Server-Antwort.");
|
||||
|
||||
Reference in New Issue
Block a user