diff --git a/filestore.go b/filestore.go index d7500a5c258285f24f40a686b503285304a4ed1a..d55a0c40f5620e951229b10d8a6fe40c96a031ba 100644 --- a/filestore.go +++ b/filestore.go @@ -12,13 +12,18 @@ import ( "crypto/rand" "encoding/hex" "encoding/json" - "github.com/pkg/errors" - "gitlab.com/elixxir/ekv/portableOS" "io" "os" "sync" + + jww "github.com/spf13/jwalterweatherman" + + "github.com/pkg/errors" + "gitlab.com/elixxir/ekv/portableOS" ) +const enableInsecureDebugging = true + // Filestore implements an ekv by reading and writing to files in a // directory. type Filestore struct { @@ -184,6 +189,13 @@ func (f *Filestore) getData(key string) ([]byte, error) { if err == nil { decryptedContents, err = decrypt(encryptedContents, f.password) } + + if enableInsecureDebugging { + jww.TRACE.Printf("[EKV] Get %s -> %s, ciphertet %d bytes, "+ + "encrypted %d bytes", encryptedKey, key, + len(encryptedContents), + len(decryptedContents)) + } return decryptedContents, errors.WithStack(err) } @@ -191,6 +203,12 @@ func (f *Filestore) setData(key string, data []byte) error { encryptedKey := f.getKey(key) encryptedContents := encrypt(data, f.password, f.csprng) + if enableInsecureDebugging { + jww.TRACE.Printf("[EKV] Set %s -> %s, ciphertet %d bytes, "+ + "encrypted %d bytes", key, encryptedKey, len(data), + len(encryptedContents)) + } + lck := f.getLock(encryptedKey) lck.Lock() defer lck.Unlock() diff --git a/go.mod b/go.mod index a690b32a693ff0b11ce92748844b87820b0212c1..765167b48b8eead7bdfa4bbbd31cfc3144581991 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.13 require ( github.com/pkg/errors v0.9.1 + github.com/spf13/jwalterweatherman v1.1.0 // indirect golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect ) diff --git a/go.sum b/go.sum index 39d0193a9af2a6e556fd559686dd9593de5547cb..230841740241486239cfb3fe19f40a28bcaa9ff2 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,10 @@ +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= +github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 h1:SLP7Q4Di66FONjDJbCYrCRrh97focO6sLogHO7/g8F0= golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=