fixed directory decryption

This commit is contained in:
ston1th 2022-04-06 01:50:28 +02:00
commit 4e1d5b36b2
2 changed files with 33 additions and 10 deletions

View file

@ -47,15 +47,17 @@ func (fs *FS) encPath(path string) string {
return filepath.Join(cparts...)
}
func (fs *FS) decPath(path string) string {
func (fs *FS) decPath(path string) (string, error) {
parts := strings.Split(path, "/")
pparts := make([]string, len(parts))
for i, p := range parts {
pparts[i] = base64.RawURLEncoding.EncodeToString(
fs.cbc.decrypt([]byte(p)),
)
b, err := base64.RawURLEncoding.DecodeString(p)
if err != nil {
return "", err
}
pparts[i] = string(fs.cbc.decrypt(b))
}
return filepath.Join(pparts...)
return filepath.Join(pparts...), nil
}
func (fs *FS) name(p string) string {
@ -72,11 +74,16 @@ func (fs *FS) Remove(p string) error {
}
func (fs *FS) Open(p string) (provider.File, error) {
f, err := fs.fs.Open(fs.encPath(p))
c := fs.encPath(p)
fi, err := fs.fs.Stat(c)
if err != nil {
return nil, err
}
return newFile(fs.key, p, fs, f)
f, err := fs.fs.Open(c)
if err != nil {
return nil, err
}
return newFile(fs.key, p, fs, f, fi.IsDir())
}
func (fs *FS) OpenFile(p string, flags int, mode os.FileMode) (provider.File, error) {
@ -84,7 +91,7 @@ func (fs *FS) OpenFile(p string, flags int, mode os.FileMode) (provider.File, er
if err != nil {
return nil, err
}
return newFile(fs.key, p, fs, f)
return newFile(fs.key, p, fs, f, false)
}
func (fs *FS) MkdirAll(p string, mode os.FileMode) error {