1
0
mirror of https://github.com/rclone/rclone.git synced 2025-01-13 20:38:12 +02:00

crypt: Fix obfuscate filename encryption method

Fix issue #1315 where filenames calculated with a base distance of zero
(ie the characters add up to 0(mod 256) aren't de-obfuscated on reading.
This was due to overloading of "0" to also mean "invalid UTF8; no rotation",
so we remove that double meaning
This commit is contained in:
Stephen Harris 2017-04-14 08:30:18 -04:00 committed by Nick Craig-Wood
parent bc25190fc7
commit e1647a5a08
2 changed files with 5 additions and 4 deletions

View File

@ -298,9 +298,9 @@ func (c *cipher) obfuscateSegment(plaintext string) string {
} }
// If the string isn't valid UTF8 then don't rotate; just // If the string isn't valid UTF8 then don't rotate; just
// prepend a 0. // prepend a !.
if !utf8.ValidString(plaintext) { if !utf8.ValidString(plaintext) {
return "0." + plaintext return "!." + plaintext
} }
// Calculate a simple rotation based on the filename and // Calculate a simple rotation based on the filename and
@ -388,7 +388,7 @@ func (c *cipher) deobfuscateSegment(ciphertext string) (string, error) {
return "", ErrorNotAnEncryptedFile return "", ErrorNotAnEncryptedFile
} // No . } // No .
num := ciphertext[:pos] num := ciphertext[:pos]
if num == "0" { if num == "!" {
// No rotation; probably original was not valid unicode // No rotation; probably original was not valid unicode
return ciphertext[pos+1:], nil return ciphertext[pos+1:], nil
} }

View File

@ -243,7 +243,7 @@ func TestDecryptFileName(t *testing.T) {
{NameEncryptionOff, "1/12/123.bin", "1/12/123", nil}, {NameEncryptionOff, "1/12/123.bin", "1/12/123", nil},
{NameEncryptionOff, "1/12/123.bix", "", ErrorNotAnEncryptedFile}, {NameEncryptionOff, "1/12/123.bix", "", ErrorNotAnEncryptedFile},
{NameEncryptionOff, ".bin", "", ErrorNotAnEncryptedFile}, {NameEncryptionOff, ".bin", "", ErrorNotAnEncryptedFile},
{NameEncryptionObfuscated, "0.hello", "hello", nil}, {NameEncryptionObfuscated, "!.hello", "hello", nil},
{NameEncryptionObfuscated, "hello", "", ErrorNotAnEncryptedFile}, {NameEncryptionObfuscated, "hello", "", ErrorNotAnEncryptedFile},
{NameEncryptionObfuscated, "161.\u00e4", "\u00a1", nil}, {NameEncryptionObfuscated, "161.\u00e4", "\u00a1", nil},
{NameEncryptionObfuscated, "160.\u03c2", "\u03a0", nil}, {NameEncryptionObfuscated, "160.\u03c2", "\u03a0", nil},
@ -264,6 +264,7 @@ func TestEncDecMatches(t *testing.T) {
{NameEncryptionStandard, "1/2/3/4"}, {NameEncryptionStandard, "1/2/3/4"},
{NameEncryptionOff, "1/2/3/4"}, {NameEncryptionOff, "1/2/3/4"},
{NameEncryptionObfuscated, "1/2/3/4/!hello\u03a0"}, {NameEncryptionObfuscated, "1/2/3/4/!hello\u03a0"},
{NameEncryptionObfuscated, "Avatar The Last Airbender"},
} { } {
c, _ := newCipher(test.mode, "", "") c, _ := newCipher(test.mode, "", "")
out, err := c.DecryptFileName(c.EncryptFileName(test.in)) out, err := c.DecryptFileName(c.EncryptFileName(test.in))