diff options
author | DerDonut | 2021-06-17 08:11:33 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2021-06-20 18:09:21 +0200 |
commit | a611810ff46ed0899d677f24c330a994ad125bfb (patch) | |
tree | 6f0abcf6c505374beef416c664b91e6e885e5263 /internal/nametransform/names.go | |
parent | cdddd1d711c3398aa1093090296139aa3d331859 (diff) |
Badname file content access
This proposal is the counterpart of the modifications from the `-badname`
parameter. It modifies the plain -> cipher mapping for filenames when using
`-badname` parameter. The new function `EncryptAndHashBadName` tries to find a
cipher filename for the given plain name with the following steps:
1. If `badname` is disabled or direct mapping is successful: Map directly
(default and current behaviour)
2. If a file with badname flag has a valid cipher file, this is returned
(=File just ends with the badname flag)
3. If a file with a badname flag exists where only the badname flag was added,
this is returned (=File cipher name could not be decrypted by function
`DecryptName` and just the badname flag was added)
4. Search for all files which cipher file name extists when cropping more and
more characters from the end. If only 1 file is found, return this
5. Return an error otherwise
This allows file access in the file browsers but most important it allows that
you rename files with undecryptable cipher names in the plain directories.
Renaming those files will then generate a proper cipher filename One
backdraft: When mounting the cipher dir with -badname parameter, you can never
create (or rename to) files whose file name ends with the badname file flag
(at the moment this is " GOCRYPTFS_BAD_NAME"). This will cause an error.
I modified the CLI test function to cover additional test cases. Test [Case
7](https://github.com/DerDonut/gocryptfs/blob/badnamecontent/tests/cli/cli_test.go#L712)
cannot be performed since the cli tests are executed in panic mode. The
testing is stopped on error. Since the function`DecryptName` produces internal
errors when hitting non-decryptable file names, this test was omitted.
This implementation is a proposal where I tried to change the minimum amount
of existing code. Another possibility would be instead of creating the new
function `EncryptAndHashBadName` to modify the signature of the existing
function `EncryptAndHashName(name string, iv []byte)` to
`EncryptAndHashName(name string, iv []byte, dirfd int)` and integrate the
functionality into this function directly. You may allow calling with dirfd=-1
or other invalid values an then performing the current functionality.
Diffstat (limited to 'internal/nametransform/names.go')
-rw-r--r-- | internal/nametransform/names.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/internal/nametransform/names.go b/internal/nametransform/names.go index ca28230..f730184 100644 --- a/internal/nametransform/names.go +++ b/internal/nametransform/names.go @@ -15,6 +15,8 @@ import ( const ( // Like ext4, we allow at most 255 bytes for a file name. NameMax = 255 + //BadNameFlag is appended to filenames in plain mode if a ciphername is inavlid but is shown + BadNameFlag = " GOCRYPTFS_BAD_NAME" ) // NameTransformer is an interface used to transform filenames. @@ -22,11 +24,13 @@ type NameTransformer interface { DecryptName(cipherName string, iv []byte) (string, error) EncryptName(plainName string, iv []byte) (string, error) EncryptAndHashName(name string, iv []byte) (string, error) + EncryptAndHashBadName(name string, iv []byte, dirfd int) (string, error) // HashLongName - take the hash of a long string "name" and return // "gocryptfs.longname.[sha256]" // // This function does not do any I/O. HashLongName(name string) string + HaveBadnamePatterns() bool WriteLongNameAt(dirfd int, hashName string, plainName string) error B64EncodeToString(src []byte) string B64DecodeString(s string) ([]byte, error) @@ -70,10 +74,10 @@ func (n *NameTransform) DecryptName(cipherName string, iv []byte) (string, error for charpos := len(cipherName) - 1; charpos >= nameMin; charpos-- { res, err = n.decryptName(cipherName[:charpos], iv) if err == nil { - return res + cipherName[charpos:] + " GOCRYPTFS_BAD_NAME", nil + return res + cipherName[charpos:] + BadNameFlag, nil } } - return cipherName + " GOCRYPTFS_BAD_NAME", nil + return cipherName + BadNameFlag, nil } } } @@ -135,3 +139,8 @@ func (n *NameTransform) B64EncodeToString(src []byte) string { func (n *NameTransform) B64DecodeString(s string) ([]byte, error) { return n.B64.DecodeString(s) } + +// HaveBadnamePatterns returns true if BadName patterns were provided +func (n *NameTransform) HaveBadnamePatterns() bool { + return len(n.BadnamePatterns) > 0 +} |