2016-11-10 00:27:08 +01:00
|
|
|
package fusefrontend_reverse
|
|
|
|
|
|
|
|
import (
|
2016-11-10 23:32:51 +01:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"syscall"
|
2016-11-10 00:27:08 +01:00
|
|
|
|
|
|
|
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
2017-05-28 18:09:02 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/pathiv"
|
2016-11-10 00:27:08 +01:00
|
|
|
)
|
|
|
|
|
2016-11-10 00:38:01 +01:00
|
|
|
var _ ctlsock.Interface = &ReverseFS{} // Verify that interface is implemented.
|
2016-11-10 00:27:08 +01:00
|
|
|
|
2016-11-10 23:32:51 +01:00
|
|
|
// EncryptPath implements ctlsock.Backend.
|
|
|
|
// This is actually not used inside reverse mode, but we implement it because
|
|
|
|
// third-party tools want to encrypt paths through the control socket.
|
2016-11-10 00:38:01 +01:00
|
|
|
func (rfs *ReverseFS) EncryptPath(plainPath string) (string, error) {
|
2016-11-10 23:32:51 +01:00
|
|
|
if rfs.args.PlaintextNames || plainPath == "" {
|
|
|
|
return plainPath, nil
|
|
|
|
}
|
|
|
|
cipherPath := ""
|
|
|
|
parts := strings.Split(plainPath, "/")
|
|
|
|
for _, part := range parts {
|
2017-05-28 18:09:02 +02:00
|
|
|
dirIV := pathiv.Derive(cipherPath, pathiv.PurposeDirIV)
|
2016-11-10 23:32:51 +01:00
|
|
|
encryptedPart := rfs.nameTransform.EncryptName(part, dirIV)
|
|
|
|
if rfs.args.LongNames && len(encryptedPart) > syscall.NAME_MAX {
|
2017-03-05 22:25:41 +01:00
|
|
|
encryptedPart = rfs.nameTransform.HashLongName(encryptedPart)
|
2016-11-10 23:32:51 +01:00
|
|
|
}
|
|
|
|
cipherPath = filepath.Join(cipherPath, encryptedPart)
|
|
|
|
}
|
|
|
|
return cipherPath, nil
|
2016-11-10 00:27:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// DecryptPath implements ctlsock.Backend
|
2016-11-10 23:32:51 +01:00
|
|
|
func (rfs *ReverseFS) DecryptPath(cipherPath string) (string, error) {
|
|
|
|
p, err := rfs.decryptPath(cipherPath)
|
|
|
|
return p, err
|
2016-11-10 00:27:08 +01:00
|
|
|
}
|