forked from Silverfish/proton-bridge
GODT-1754: Add logs for unilateral updates and SEARCH.
This commit is contained in:
14
internal/store/cache/disk.go
vendored
14
internal/store/cache/disk.go
vendored
@ -21,7 +21,6 @@ import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@ -29,6 +28,7 @@ import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/algo"
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/semaphore"
|
||||
"github.com/ricochet2200/go-disk-usage/du"
|
||||
)
|
||||
@ -100,13 +100,7 @@ func (c *onDiskCache) Lock(userID string) {
|
||||
}
|
||||
|
||||
func (c *onDiskCache) Unlock(userID string, passphrase []byte) error {
|
||||
hash := sha256.New()
|
||||
|
||||
if _, err := hash.Write(passphrase); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
aes, err := aes.NewCipher(hash.Sum(nil))
|
||||
aes, err := aes.NewCipher(algo.Hash256(passphrase))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -279,9 +273,9 @@ func (c *onDiskCache) update() {
|
||||
}
|
||||
|
||||
func (c *onDiskCache) getUserPath(userID string) string {
|
||||
return filepath.Join(c.path, getHash(userID))
|
||||
return filepath.Join(c.path, algo.HashHexSHA256(userID))
|
||||
}
|
||||
|
||||
func (c *onDiskCache) getMessagePath(userID, messageID string) string {
|
||||
return filepath.Join(c.getUserPath(userID), getHash(messageID))
|
||||
return filepath.Join(c.getUserPath(userID), algo.HashHexSHA256(messageID))
|
||||
}
|
||||
|
||||
34
internal/store/cache/hash.go
vendored
34
internal/store/cache/hash.go
vendored
@ -1,34 +0,0 @@
|
||||
// Copyright (c) 2022 Proton AG
|
||||
//
|
||||
// This file is part of Proton Mail Bridge.
|
||||
//
|
||||
// Proton Mail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Proton Mail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package cache
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
func getHash(name string) string {
|
||||
hash := sha256.New()
|
||||
|
||||
if _, err := hash.Write([]byte(name)); err != nil {
|
||||
// sha256.Write always returns nill err so this should never happen
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return hex.EncodeToString(hash.Sum(nil))
|
||||
}
|
||||
Reference in New Issue
Block a user