diriv: fix readdir

It decrypted all file names using the root directory iv
This commit is contained in:
Jakob Unterwurzacher 2015-11-28 00:07:03 +01:00
parent fe7355f9ee
commit 3b2143bafc
2 changed files with 11 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import (
// readDirIV - read the "gocryptfs.diriv" file from "dir" (absolute path)
func (be *CryptFS) readDirIV(dir string) (iv []byte, err error) {
ivfile := filepath.Join(dir, DIRIV_FILENAME)
Debug.Printf("readDirIV: reading %s\n", ivfile)
iv, err = ioutil.ReadFile(ivfile)
if err != nil {
Warn.Printf("readDirIV: %v\n", err)
@ -63,6 +64,7 @@ func (be *CryptFS) DecryptPathDirIV(encryptedPath string, rootDir string) (strin
var wd = rootDir
var plainNames []string
encryptedNames := strings.Split(encryptedPath, "/")
Debug.Printf("DecryptPathDirIV: decrypting %v\n", encryptedNames)
for _, encryptedName := range encryptedNames {
iv, err := be.readDirIV(wd)
if err != nil {

View File

@ -89,7 +89,15 @@ func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, f
// silently ignore "gocryptfs.diriv" everywhere if dirIV is enabled
continue
}
name, err := fs.decryptPath(cName)
var name string
if !fs.dirIV {
name, err = fs.decryptPath(cName)
} else {
// When dirIV is enabled we need the full path to be able to decrypt it
cPath := filepath.Join(cDirName, cName)
name, err = fs.decryptPath(cPath)
name = filepath.Base(name)
}
if err != nil {
cryptfs.Warn.Printf("Invalid name \"%s\" in dir \"%s\": %s\n", cName, dirName, err)
continue