aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorDerDonut2020-05-19 13:34:58 +0200
committerJakob Unterwurzacher2020-06-06 12:20:31 +0200
commita8230d271f394e130a8190d554eef2a86bc962d7 (patch)
treebabb6d3c4d9d76bd2d5363a1a83728a4c063c4f7 /internal
parenta56e7cc5ac3ede528aaa05f912c865b09e942de4 (diff)
Added auto decryption of invalid file names
Changed invalid file decoding and decryption. Function DecryptName now shortens the filename until the filename is decodable and decryptable. Will work with valid **and** invalid Base64URL delimiter (valid delimiter [0-9a-zA-z_\\-]. If the filename is not decryptable at all, it returns the original cipher name with flag suffix Changed cli tests to generate decryptable and undecryptable file names with correct encrypted content. Replacing #474, extends #393
Diffstat (limited to 'internal')
-rw-r--r--internal/nametransform/names.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/nametransform/names.go b/internal/nametransform/names.go
index e9f9346..675ed34 100644
--- a/internal/nametransform/names.go
+++ b/internal/nametransform/names.go
@@ -61,7 +61,14 @@ func (n *NameTransform) DecryptName(cipherName string, iv []byte) (string, error
for _, pattern := range n.BadnamePatterns {
match, err := filepath.Match(pattern, cipherName)
if err == nil && match { // Pattern should have been validated already
- return "GOCRYPTFS_BAD_NAME " + cipherName, nil
+ //find longest decryptable substring
+ for charpos := len(cipherName) - 1; charpos > 0; charpos-- {
+ res, err = n.decryptName(cipherName[:charpos], iv)
+ if err == nil {
+ return res + cipherName[charpos:] + " GOCRYPTFS_BAD_NAME", nil
+ }
+ }
+ return cipherName + " GOCRYPTFS_BAD_NAME", nil
}
}
}