diff --git a/backend/crypt/cipher.go b/backend/crypt/cipher.go index b7b6c05db..afd107df3 100644 --- a/backend/crypt/cipher.go +++ b/backend/crypt/cipher.go @@ -208,21 +208,6 @@ func (c *cipher) putBlock(buf []byte) { c.buffers.Put(buf) } -// check to see if the byte string is valid with no control characters -// from 0x00 to 0x1F and is a valid UTF-8 string -func checkValidString(buf []byte) error { - for i := range buf { - c := buf[i] - if c >= 0x00 && c < 0x20 || c == 0x7F { - return ErrorBadDecryptControlChar - } - } - if !utf8.Valid(buf) { - return ErrorBadDecryptUTF8 - } - return nil -} - // encodeFileName encodes a filename using a modified version of // standard base32 as described in RFC4648 // @@ -294,10 +279,6 @@ func (c *cipher) decryptSegment(ciphertext string) (string, error) { if err != nil { return "", err } - err = checkValidString(plaintext) - if err != nil { - return "", err - } return string(plaintext), err } diff --git a/backend/crypt/cipher_test.go b/backend/crypt/cipher_test.go index 31faccd14..b46f2c5e7 100644 --- a/backend/crypt/cipher_test.go +++ b/backend/crypt/cipher_test.go @@ -44,69 +44,6 @@ func TestNewNameEncryptionModeString(t *testing.T) { assert.Equal(t, NameEncryptionMode(3).String(), "Unknown mode #3") } -func TestValidString(t *testing.T) { - for _, test := range []struct { - in string - expected error - }{ - {"", nil}, - {"\x01", ErrorBadDecryptControlChar}, - {"a\x02", ErrorBadDecryptControlChar}, - {"abc\x03", ErrorBadDecryptControlChar}, - {"abc\x04def", ErrorBadDecryptControlChar}, - {"\x05d", ErrorBadDecryptControlChar}, - {"\x06def", ErrorBadDecryptControlChar}, - {"\x07", ErrorBadDecryptControlChar}, - {"\x08", ErrorBadDecryptControlChar}, - {"\x09", ErrorBadDecryptControlChar}, - {"\x0A", ErrorBadDecryptControlChar}, - {"\x0B", ErrorBadDecryptControlChar}, - {"\x0C", ErrorBadDecryptControlChar}, - {"\x0D", ErrorBadDecryptControlChar}, - {"\x0E", ErrorBadDecryptControlChar}, - {"\x0F", ErrorBadDecryptControlChar}, - {"\x10", ErrorBadDecryptControlChar}, - {"\x11", ErrorBadDecryptControlChar}, - {"\x12", ErrorBadDecryptControlChar}, - {"\x13", ErrorBadDecryptControlChar}, - {"\x14", ErrorBadDecryptControlChar}, - {"\x15", ErrorBadDecryptControlChar}, - {"\x16", ErrorBadDecryptControlChar}, - {"\x17", ErrorBadDecryptControlChar}, - {"\x18", ErrorBadDecryptControlChar}, - {"\x19", ErrorBadDecryptControlChar}, - {"\x1A", ErrorBadDecryptControlChar}, - {"\x1B", ErrorBadDecryptControlChar}, - {"\x1C", ErrorBadDecryptControlChar}, - {"\x1D", ErrorBadDecryptControlChar}, - {"\x1E", ErrorBadDecryptControlChar}, - {"\x1F", ErrorBadDecryptControlChar}, - {"\x20", nil}, - {"\x7E", nil}, - {"\x7F", ErrorBadDecryptControlChar}, - {"£100", nil}, - {`hello? sausage/êé/Hello, 世界/ " ' @ < > & ?/z.txt`, nil}, - {"£100", nil}, - // Following tests from https://secure.php.net/manual/en/reference.pcre.pattern.modifiers.php#54805 - {"a", nil}, // Valid ASCII - {"\xc3\xb1", nil}, // Valid 2 Octet Sequence - {"\xc3\x28", ErrorBadDecryptUTF8}, // Invalid 2 Octet Sequence - {"\xa0\xa1", ErrorBadDecryptUTF8}, // Invalid Sequence Identifier - {"\xe2\x82\xa1", nil}, // Valid 3 Octet Sequence - {"\xe2\x28\xa1", ErrorBadDecryptUTF8}, // Invalid 3 Octet Sequence (in 2nd Octet) - {"\xe2\x82\x28", ErrorBadDecryptUTF8}, // Invalid 3 Octet Sequence (in 3rd Octet) - {"\xf0\x90\x8c\xbc", nil}, // Valid 4 Octet Sequence - {"\xf0\x28\x8c\xbc", ErrorBadDecryptUTF8}, // Invalid 4 Octet Sequence (in 2nd Octet) - {"\xf0\x90\x28\xbc", ErrorBadDecryptUTF8}, // Invalid 4 Octet Sequence (in 3rd Octet) - {"\xf0\x28\x8c\x28", ErrorBadDecryptUTF8}, // Invalid 4 Octet Sequence (in 4th Octet) - {"\xf8\xa1\xa1\xa1\xa1", ErrorBadDecryptUTF8}, // Valid 5 Octet Sequence (but not Unicode!) - {"\xfc\xa1\xa1\xa1\xa1\xa1", ErrorBadDecryptUTF8}, // Valid 6 Octet Sequence (but not Unicode!) - } { - actual := checkValidString([]byte(test.in)) - assert.Equal(t, actual, test.expected, fmt.Sprintf("in=%q", test.in)) - } -} - func TestEncodeFileName(t *testing.T) { for _, test := range []struct { in string @@ -210,8 +147,6 @@ func TestDecryptSegment(t *testing.T) { {encodeFileName([]byte("a")), ErrorNotAMultipleOfBlocksize}, {encodeFileName([]byte("123456789abcdef")), ErrorNotAMultipleOfBlocksize}, {encodeFileName([]byte("123456789abcdef0")), pkcs7.ErrorPaddingTooLong}, - {c.encryptSegment("\x01"), ErrorBadDecryptControlChar}, - {c.encryptSegment("\xc3\x28"), ErrorBadDecryptUTF8}, } { actual, actualErr := c.decryptSegment(test.in) assert.Equal(t, test.expectedErr, actualErr, fmt.Sprintf("in=%q got actual=%q, err = %v %T", test.in, actual, actualErr, actualErr))