2015-11-27 00:03:10 +01:00
|
|
|
package pathfs_frontend
|
|
|
|
|
2015-11-27 23:34:55 +01:00
|
|
|
// This file forwards file encryption operations to cryptfs
|
|
|
|
|
|
|
|
import (
|
2016-02-06 19:20:54 +01:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/configfile"
|
|
|
|
mylog "github.com/rfjakob/gocryptfs/internal/toggledlog"
|
2015-11-27 23:34:55 +01:00
|
|
|
)
|
2015-11-27 00:03:10 +01:00
|
|
|
|
2015-12-08 16:13:29 +01:00
|
|
|
// isFiltered - check if plaintext "path" should be forbidden
|
|
|
|
//
|
|
|
|
// Prevents name clashes with internal files when file names are not encrypted
|
|
|
|
func (fs *FS) isFiltered(path string) bool {
|
|
|
|
if !fs.args.PlaintextNames {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// gocryptfs.conf in the root directory is forbidden
|
2016-02-06 19:20:54 +01:00
|
|
|
if path == configfile.ConfDefaultName {
|
|
|
|
mylog.Info.Printf("The name /%s is reserved when -plaintextnames is used\n",
|
|
|
|
configfile.ConfDefaultName)
|
2015-12-08 16:13:29 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
// Note: gocryptfs.diriv is NOT forbidden because diriv and plaintextnames
|
|
|
|
// are exclusive
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// encryptPath - encrypt relative plaintext path
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) encryptPath(plainPath string) (string, error) {
|
2015-12-08 16:13:29 +01:00
|
|
|
if fs.args.PlaintextNames {
|
|
|
|
return plainPath, nil
|
|
|
|
}
|
2015-11-28 16:52:57 +01:00
|
|
|
if !fs.args.DirIV {
|
2016-02-06 19:20:54 +01:00
|
|
|
return fs.nameTransform.EncryptPathNoIV(plainPath), nil
|
2015-11-27 23:34:55 +01:00
|
|
|
}
|
2015-11-27 21:48:58 +01:00
|
|
|
fs.dirIVLock.RLock()
|
|
|
|
defer fs.dirIVLock.RUnlock()
|
2016-02-06 19:20:54 +01:00
|
|
|
return fs.nameTransform.EncryptPathDirIV(plainPath, fs.args.Cipherdir)
|
2015-11-27 00:03:10 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 16:13:29 +01:00
|
|
|
// decryptPath - decrypt relative ciphertext path
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) decryptPath(cipherPath string) (string, error) {
|
2015-12-08 16:13:29 +01:00
|
|
|
if fs.args.PlaintextNames {
|
|
|
|
return cipherPath, nil
|
|
|
|
}
|
2015-11-28 16:52:57 +01:00
|
|
|
if !fs.args.DirIV {
|
2016-02-06 19:20:54 +01:00
|
|
|
return fs.nameTransform.DecryptPathNoIV(cipherPath)
|
2015-11-27 23:34:55 +01:00
|
|
|
}
|
2015-11-27 21:48:58 +01:00
|
|
|
fs.dirIVLock.RLock()
|
|
|
|
defer fs.dirIVLock.RUnlock()
|
2016-02-06 19:20:54 +01:00
|
|
|
return fs.nameTransform.DecryptPathDirIV(cipherPath, fs.args.Cipherdir, fs.args.EMENames)
|
2015-11-27 00:03:10 +01:00
|
|
|
}
|