2016-11-10 00:27:08 +01:00
|
|
|
package fusefrontend_reverse
|
|
|
|
|
|
|
|
import (
|
2016-11-10 23:32:51 +01:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2018-02-01 23:46:02 +01:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2016-11-10 00:27:08 +01:00
|
|
|
|
2020-05-09 17:36:41 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/ctlsocksrv"
|
2017-05-28 18:09:02 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/pathiv"
|
2016-11-10 00:27:08 +01:00
|
|
|
)
|
|
|
|
|
2020-05-09 17:36:41 +02:00
|
|
|
var _ ctlsocksrv.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.
|
2019-01-04 17:34:21 +01:00
|
|
|
// This is used for the control socket and for the "-exclude" logic.
|
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)
|
2018-02-01 23:46:02 +01:00
|
|
|
if rfs.args.LongNames && len(encryptedPart) > unix.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
|
|
|
}
|