aboutsummaryrefslogtreecommitdiff
path: root/cryptfs
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-10-03 13:36:49 +0200
committerJakob Unterwurzacher2015-10-03 19:16:34 +0200
commit79870ab0960febcbc82e32d632ed4a9ea99b6f03 (patch)
treee9af1bb576b40eef5214278e27bcb0fecb20aa3c /cryptfs
parent38bf8a2fcfe0b7260c08d49ed04c9667871f0992 (diff)
debug: log inode number instead of encrypted filename
Makes the log output smaller and more readable.
Diffstat (limited to 'cryptfs')
-rw-r--r--cryptfs/cryptfs.go6
-rw-r--r--cryptfs/cryptfs_content.go17
-rw-r--r--cryptfs/log.go14
3 files changed, 36 insertions, 1 deletions
diff --git a/cryptfs/cryptfs.go b/cryptfs/cryptfs.go
index 71ec996..46f5b65 100644
--- a/cryptfs/cryptfs.go
+++ b/cryptfs/cryptfs.go
@@ -58,6 +58,12 @@ func NewCryptFS(key []byte, useOpenssl bool) *CryptFS {
}
}
+// Get plaintext block size
func (be *CryptFS) PlainBS() uint64 {
return be.plainBS
}
+
+// Get ciphertext block size
+func (be *CryptFS) CipherBS() uint64 {
+ return be.cipherBS
+}
diff --git a/cryptfs/cryptfs_content.go b/cryptfs/cryptfs_content.go
index e42011a..a4dc78a 100644
--- a/cryptfs/cryptfs_content.go
+++ b/cryptfs/cryptfs_content.go
@@ -7,8 +7,22 @@ import (
"os"
"errors"
"crypto/cipher"
+ "crypto/md5"
+ "encoding/hex"
)
+const (
+ // A block of 4124 zero bytes has this md5
+ ZeroBlockMd5 = "64331af89bd15a987b39855338336237"
+)
+
+// md5sum - debug helper, return md5 hex string
+func md5sum(buf []byte) string {
+ rawHash := md5.Sum(buf)
+ hash := hex.EncodeToString(rawHash[:])
+ return hash
+}
+
type CryptFile struct {
file *os.File
gcm cipher.AEAD
@@ -55,6 +69,7 @@ func (be *CryptFS) DecryptBlock(ciphertext []byte) ([]byte, error) {
// Extract nonce
nonce := ciphertext[:NONCE_LEN]
+ ciphertextOrig := ciphertext
ciphertext = ciphertext[NONCE_LEN:]
// Decrypt
@@ -63,7 +78,7 @@ func (be *CryptFS) DecryptBlock(ciphertext []byte) ([]byte, error) {
plaintext, err := be.gcm.Open(plaintext, nonce, ciphertext, nil)
if err != nil {
- Warn.Printf("DecryptBlock: %s\n", err.Error())
+ Warn.Printf("DecryptBlock: %s, len=%d, md5=%s\n", err.Error(), len(ciphertextOrig), Warn.Md5sum(ciphertextOrig))
return nil, err
}
diff --git a/cryptfs/log.go b/cryptfs/log.go
index d40aa3f..850ec9e 100644
--- a/cryptfs/log.go
+++ b/cryptfs/log.go
@@ -15,6 +15,12 @@ func (l *logChannel) Printf(format string, args ...interface{}) {
}
}
+func (l *logChannel) Println(s string) {
+ if l.enabled == true {
+ fmt.Println(s)
+ }
+}
+
func (l *logChannel) Dump(d []byte) {
s := string(d)
fmt.Println(strings.Replace(s, "\000", "\\0", -1))
@@ -24,6 +30,14 @@ func (l *logChannel) Enable() {
l.enabled = true
}
+// Only actually calculate the md5sum if the log channel is enabled to save
+// CPU cycles
+func (l *logChannel) Md5sum(buf []byte) string {
+ if l.enabled == false {
+ return ""
+ }
+ return md5sum(buf)
+}
var Debug = logChannel{false}
var Notice = logChannel{true}