nametransform: fix Raw64 not affecting longnames

HashLongName() incorrectly hardcoded the call to base64.URLEncoding.
This commit is contained in:
Jakob Unterwurzacher 2017-03-05 22:25:41 +01:00
parent d0bc7970f7
commit 5b54577d2e
5 changed files with 7 additions and 9 deletions

View File

@ -6,7 +6,6 @@ import (
"syscall"
"github.com/rfjakob/gocryptfs/internal/ctlsock"
"github.com/rfjakob/gocryptfs/internal/nametransform"
)
var _ ctlsock.Interface = &ReverseFS{} // Verify that interface is implemented.
@ -24,7 +23,7 @@ func (rfs *ReverseFS) EncryptPath(plainPath string) (string, error) {
dirIV := derivePathIV(cipherPath, ivPurposeDirIV)
encryptedPart := rfs.nameTransform.EncryptName(part, dirIV)
if rfs.args.LongNames && len(encryptedPart) > syscall.NAME_MAX {
encryptedPart = nametransform.HashLongName(encryptedPart)
encryptedPart = rfs.nameTransform.HashLongName(encryptedPart)
}
cipherPath = filepath.Join(cipherPath, encryptedPart)
}

View File

@ -68,7 +68,7 @@ func (rfs *ReverseFS) findLongnameParent(dir string, dirIV []byte, longname stri
if len(cName) <= syscall.NAME_MAX {
log.Panic("logic error or wrong shortNameMax constant?")
}
hName := nametransform.HashLongName(cName)
hName := rfs.nameTransform.HashLongName(cName)
longnameParentCache[hName] = plaintextName
if longname == hName {
hit = plaintextName

View File

@ -319,7 +319,7 @@ func (rfs *ReverseFS) OpenDir(cipherPath string, context *fuse.Context) ([]fuse.
} else {
cName = rfs.nameTransform.EncryptName(entries[i].Name, dirIV)
if len(cName) > syscall.NAME_MAX {
cName = nametransform.HashLongName(cName)
cName = rfs.nameTransform.HashLongName(cName)
dotNameFile := fuse.DirEntry{
Mode: syscall.S_IFREG | 0600,
Name: cName + nametransform.LongNameSuffix,

View File

@ -97,7 +97,7 @@ func (be *NameTransform) EncryptPathDirIV(plainPath string, rootDir string) (cip
if iv != nil {
cBaseName := be.EncryptName(baseName, iv)
if be.longNames && len(cBaseName) > syscall.NAME_MAX {
cBaseName = HashLongName(cBaseName)
cBaseName = be.HashLongName(cBaseName)
}
cipherPath = filepath.Join(cParentDir, cBaseName)
return cipherPath, nil
@ -113,7 +113,7 @@ func (be *NameTransform) EncryptPathDirIV(plainPath string, rootDir string) (cip
}
encryptedName := be.EncryptName(plainName, iv)
if be.longNames && len(encryptedName) > syscall.NAME_MAX {
encryptedName = HashLongName(encryptedName)
encryptedName = be.HashLongName(encryptedName)
}
encryptedNames = append(encryptedNames, encryptedName)
wd = filepath.Join(wd, encryptedName)

View File

@ -2,7 +2,6 @@ package nametransform
import (
"crypto/sha256"
"encoding/base64"
"io/ioutil"
"os"
"path/filepath"
@ -24,9 +23,9 @@ const (
// HashLongName - take the hash of a long string "name" and return
// "gocryptfs.longname.[sha256]"
func HashLongName(name string) string {
func (n *NameTransform) HashLongName(name string) string {
hashBin := sha256.Sum256([]byte(name))
hashBase64 := base64.URLEncoding.EncodeToString(hashBin[:])
hashBase64 := n.b64.EncodeToString(hashBin[:])
return longNamePrefix + hashBase64
}