From f80ee472c2ab8278319f2932b1851ca5ab2fc62b Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Sat, 13 Mar 2021 16:57:36 +0100 Subject: [PATCH] lib/protocol: Set invalid flag on encrypted file infos (fixes #7466) (#7467) --- lib/protocol/encryption.go | 1 + lib/protocol/encryption_test.go | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/protocol/encryption.go b/lib/protocol/encryption.go index c1485cc31..0ccac6f42 100644 --- a/lib/protocol/encryption.go +++ b/lib/protocol/encryption.go @@ -314,6 +314,7 @@ func encryptFileInfo(fi FileInfo, folderKey *[keySize]byte) FileInfo { Permissions: 0644, ModifiedS: 1234567890, // Sat Feb 14 00:31:30 CET 2009 Deleted: fi.Deleted, + RawInvalid: fi.IsInvalid(), Version: version, Sequence: fi.Sequence, RawBlockSize: fi.RawBlockSize + blockOverhead, diff --git a/lib/protocol/encryption_test.go b/lib/protocol/encryption_test.go index 56806c6c1..b6fc2b555 100644 --- a/lib/protocol/encryption_test.go +++ b/lib/protocol/encryption_test.go @@ -113,9 +113,8 @@ func TestEnDecryptBytes(t *testing.T) { } } -func TestEnDecryptFileInfo(t *testing.T) { - var key [32]byte - fi := FileInfo{ +func encFileInfo() FileInfo { + return FileInfo{ Name: "hello", Size: 45, Permissions: 0755, @@ -133,6 +132,11 @@ func TestEnDecryptFileInfo(t *testing.T) { }, }, } +} + +func TestEnDecryptFileInfo(t *testing.T) { + var key [32]byte + fi := encFileInfo() enc := encryptFileInfo(fi, &key) if bytes.Equal(enc.Blocks[0].Hash, enc.Blocks[1].Hash) { @@ -155,6 +159,21 @@ func TestEnDecryptFileInfo(t *testing.T) { } } +func TestEncryptedFileInfoConsistency(t *testing.T) { + var key [32]byte + files := []FileInfo{ + encFileInfo(), + encFileInfo(), + } + files[1].SetIgnored() + for i, f := range files { + enc := encryptFileInfo(f, &key) + if err := checkFileInfoConsistency(enc); err != nil { + t.Errorf("%v: %v", i, err) + } + } +} + func TestIsEncryptedParent(t *testing.T) { comp := rand.String(maxPathComponent) cases := []struct {