aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend/ctlsock_interface.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-05-07 21:01:39 +0200
committerJakob Unterwurzacher2017-05-07 21:01:39 +0200
commitad7942f434fea567f24458e67a0919291b5ec8dd (patch)
tree463dac4ecb99970973ae662bdd50d05c1b71ced2 /internal/fusefrontend/ctlsock_interface.go
parent26881538e1753e613b4143b28fa339812a9a6d16 (diff)
fusefrontend: implement path decryption via ctlsock
Closes https://github.com/rfjakob/gocryptfs/issues/84 .
Diffstat (limited to 'internal/fusefrontend/ctlsock_interface.go')
-rw-r--r--internal/fusefrontend/ctlsock_interface.go35
1 files changed, 33 insertions, 2 deletions
diff --git a/internal/fusefrontend/ctlsock_interface.go b/internal/fusefrontend/ctlsock_interface.go
index 8d8b096..964775b 100644
--- a/internal/fusefrontend/ctlsock_interface.go
+++ b/internal/fusefrontend/ctlsock_interface.go
@@ -1,9 +1,12 @@
package fusefrontend
import (
- "errors"
+ "fmt"
+ "path"
+ "strings"
"github.com/rfjakob/gocryptfs/internal/ctlsock"
+ "github.com/rfjakob/gocryptfs/internal/nametransform"
)
var _ ctlsock.Interface = &FS{} // Verify that interface is implemented.
@@ -15,5 +18,33 @@ func (fs *FS) EncryptPath(plainPath string) (string, error) {
// DecryptPath implements ctlsock.Backend
func (fs *FS) DecryptPath(cipherPath string) (string, error) {
- return "", errors.New("Forward mode does not have path decryption implemented")
+ if fs.args.PlaintextNames || cipherPath == "" {
+ return cipherPath, nil
+ }
+ plainPath := ""
+ parts := strings.Split(cipherPath, "/")
+ wd := fs.args.Cipherdir
+ for _, part := range parts {
+ dirIV, err := nametransform.ReadDirIV(wd)
+ if err != nil {
+ fmt.Printf("ReadDirIV: %v\n", err)
+ return "", err
+ }
+ longPart := part
+ if nametransform.IsLongContent(part) {
+ longPart, err = nametransform.ReadLongName(wd + "/" + part)
+ if err != nil {
+ fmt.Printf("ReadLongName: %v\n", err)
+ return "", err
+ }
+ }
+ name, err := fs.nameTransform.DecryptName(longPart, dirIV)
+ if err != nil {
+ fmt.Printf("DecryptName: %v\n", err)
+ return "", err
+ }
+ plainPath = path.Join(plainPath, name)
+ wd = path.Join(wd, part)
+ }
+ return plainPath, nil
}