lib/protocol: Test to lock down encryption key derivation

So that we don't inadvertently change how these things work.
This commit is contained in:
Jakob Borg 2021-10-04 14:36:26 +02:00
parent b75d083035
commit 92eaf52c21
1 changed files with 20 additions and 0 deletions

View File

@ -71,6 +71,26 @@ func TestEnDecryptName(t *testing.T) {
}
}
func TestKeyDerivation(t *testing.T) {
folderKey := KeyFromPassword("my folder", "my password")
encryptedName := encryptDeterministic([]byte("filename.txt"), folderKey, nil)
if base32Hex.EncodeToString(encryptedName) != "3T5957I4IOA20VEIEER6JSQG0PEPIRV862II3K7LOF75Q" {
t.Error("encrypted name mismatch")
}
fileKey := FileKey("filename.txt", folderKey)
// fmt.Println(base32Hex.EncodeToString(encryptBytes([]byte("hello world"), fileKey))) => A1IPD...
const encrypted = `A1IPD28ISL7VNPRSSSQM2L31L3IJPC08283RO89J5UG0TI9P38DO9RFGK12DK0KD7PKQP6U51UL2B6H96O`
bs, _ := base32Hex.DecodeString(encrypted)
dec, err := DecryptBytes(bs, fileKey)
if err != nil {
t.Error(err)
}
if string(dec) != "hello world" {
t.Error("decryption mismatch")
}
}
func TestDecryptNameInvalid(t *testing.T) {
key := new([32]byte)
for _, c := range []string{