Fix tests - were broken by the refactoring
This commit is contained in:
parent
9078a77850
commit
b0ee5258b1
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/toggledlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadV1(t *testing.T) {
|
func TestLoadV1(t *testing.T) {
|
||||||
@ -33,7 +35,7 @@ func TestLoadV2(t *testing.T) {
|
|||||||
|
|
||||||
func TestLoadV2PwdError(t *testing.T) {
|
func TestLoadV2PwdError(t *testing.T) {
|
||||||
if !testing.Verbose() {
|
if !testing.Verbose() {
|
||||||
Warn.Enabled = false
|
toggledlog.Warn.Enabled = false
|
||||||
}
|
}
|
||||||
_, _, err := LoadConfFile("config_test/v2.conf", "wrongpassword")
|
_, _, err := LoadConfFile("config_test/v2.conf", "wrongpassword")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -2,6 +2,11 @@ package contentenc
|
|||||||
|
|
||||||
import "github.com/rfjakob/gocryptfs/internal/cryptocore"
|
import "github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Default plaintext block size
|
||||||
|
DefaultBS = 4096
|
||||||
|
)
|
||||||
|
|
||||||
type ContentEnc struct {
|
type ContentEnc struct {
|
||||||
// Cryptographic primitives
|
// Cryptographic primitives
|
||||||
cryptoCore *cryptocore.CryptoCore
|
cryptoCore *cryptocore.CryptoCore
|
||||||
|
@ -2,6 +2,8 @@ package contentenc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testRange struct {
|
type testRange struct {
|
||||||
@ -20,8 +22,9 @@ func TestSplitRange(t *testing.T) {
|
|||||||
testRange{0, 65536},
|
testRange{0, 65536},
|
||||||
testRange{6654, 8945})
|
testRange{6654, 8945})
|
||||||
|
|
||||||
key := make([]byte, KEY_LEN)
|
key := make([]byte, cryptocore.KeyLen)
|
||||||
f := NewCryptFS(key, true, false, true)
|
cc := cryptocore.New(key, false, true)
|
||||||
|
f := New(cc, DefaultBS)
|
||||||
|
|
||||||
for _, r := range ranges {
|
for _, r := range ranges {
|
||||||
parts := f.ExplodePlainRange(r.offset, r.length)
|
parts := f.ExplodePlainRange(r.offset, r.length)
|
||||||
@ -31,7 +34,7 @@ func TestSplitRange(t *testing.T) {
|
|||||||
t.Errorf("Duplicate block number %d", p.BlockNo)
|
t.Errorf("Duplicate block number %d", p.BlockNo)
|
||||||
}
|
}
|
||||||
lastBlockNo = p.BlockNo
|
lastBlockNo = p.BlockNo
|
||||||
if p.Length > DEFAULT_PLAINBS || p.Skip >= DEFAULT_PLAINBS {
|
if p.Length > DefaultBS || p.Skip >= DefaultBS {
|
||||||
t.Errorf("Test fail: n=%d, length=%d, offset=%d\n", p.BlockNo, p.Length, p.Skip)
|
t.Errorf("Test fail: n=%d, length=%d, offset=%d\n", p.BlockNo, p.Length, p.Skip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,8 +50,9 @@ func TestCiphertextRange(t *testing.T) {
|
|||||||
testRange{65444, 54},
|
testRange{65444, 54},
|
||||||
testRange{6654, 8945})
|
testRange{6654, 8945})
|
||||||
|
|
||||||
key := make([]byte, KEY_LEN)
|
key := make([]byte, cryptocore.KeyLen)
|
||||||
f := NewCryptFS(key, true, false, true)
|
cc := cryptocore.New(key, false, true)
|
||||||
|
f := New(cc, DefaultBS)
|
||||||
|
|
||||||
for _, r := range ranges {
|
for _, r := range ranges {
|
||||||
|
|
||||||
@ -69,8 +73,9 @@ func TestCiphertextRange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBlockNo(t *testing.T) {
|
func TestBlockNo(t *testing.T) {
|
||||||
key := make([]byte, KEY_LEN)
|
key := make([]byte, cryptocore.KeyLen)
|
||||||
f := NewCryptFS(key, true, false, true)
|
cc := cryptocore.New(key, false, true)
|
||||||
|
f := New(cc, DefaultBS)
|
||||||
|
|
||||||
b := f.CipherOffToBlockNo(788)
|
b := f.CipherOffToBlockNo(788)
|
||||||
if b != 0 {
|
if b != 0 {
|
||||||
|
@ -21,8 +21,6 @@ import (
|
|||||||
"github.com/rfjakob/gocryptfs/internal/configfile"
|
"github.com/rfjakob/gocryptfs/internal/configfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
const plainBS = 4096
|
|
||||||
|
|
||||||
type FS struct {
|
type FS struct {
|
||||||
pathfs.FileSystem // loopbackFileSystem, see go-fuse/fuse/pathfs/loopback.go
|
pathfs.FileSystem // loopbackFileSystem, see go-fuse/fuse/pathfs/loopback.go
|
||||||
args Args // Stores configuration arguments
|
args Args // Stores configuration arguments
|
||||||
@ -40,7 +38,7 @@ type FS struct {
|
|||||||
func NewFS(args Args) *FS {
|
func NewFS(args Args) *FS {
|
||||||
|
|
||||||
cryptoCore := cryptocore.New(args.Masterkey, args.OpenSSL, args.GCMIV128)
|
cryptoCore := cryptocore.New(args.Masterkey, args.OpenSSL, args.GCMIV128)
|
||||||
contentEnc := contentenc.New(cryptoCore, plainBS)
|
contentEnc := contentenc.New(cryptoCore, contentenc.DefaultBS)
|
||||||
nameTransform := nametransform.New(cryptoCore, args.EMENames)
|
nameTransform := nametransform.New(cryptoCore, args.EMENames)
|
||||||
|
|
||||||
return &FS{
|
return &FS{
|
||||||
|
@ -3,6 +3,8 @@ package nametransform
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEncryptPathNoIV(t *testing.T) {
|
func TestEncryptPathNoIV(t *testing.T) {
|
||||||
@ -11,8 +13,9 @@ func TestEncryptPathNoIV(t *testing.T) {
|
|||||||
s = append(s, "foo12312312312312312313123123123")
|
s = append(s, "foo12312312312312312313123123123")
|
||||||
s = append(s, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
|
s = append(s, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
|
||||||
|
|
||||||
key := make([]byte, KEY_LEN)
|
key := make([]byte, cryptocore.KeyLen)
|
||||||
fs := NewCryptFS(key, true, false, true)
|
cc := cryptocore.New(key, false, true)
|
||||||
|
fs := New(cc, true)
|
||||||
|
|
||||||
for _, n := range s {
|
for _, n := range s {
|
||||||
c := fs.EncryptPathNoIV(n)
|
c := fs.EncryptPathNoIV(n)
|
||||||
@ -32,19 +35,16 @@ func TestPad16(t *testing.T) {
|
|||||||
s = append(s, []byte("12345678901234567"))
|
s = append(s, []byte("12345678901234567"))
|
||||||
s = append(s, []byte("12345678901234567abcdefg"))
|
s = append(s, []byte("12345678901234567abcdefg"))
|
||||||
|
|
||||||
key := make([]byte, KEY_LEN)
|
|
||||||
fs := NewCryptFS(key, true, false, true)
|
|
||||||
|
|
||||||
for i := range s {
|
for i := range s {
|
||||||
orig := s[i]
|
orig := s[i]
|
||||||
padded := fs.pad16(orig)
|
padded := pad16(orig)
|
||||||
if len(padded) <= len(orig) {
|
if len(padded) <= len(orig) {
|
||||||
t.Errorf("Padded length not bigger than orig: %d", len(padded))
|
t.Errorf("Padded length not bigger than orig: %d", len(padded))
|
||||||
}
|
}
|
||||||
if len(padded)%16 != 0 {
|
if len(padded)%16 != 0 {
|
||||||
t.Errorf("Length is not aligend: %d", len(padded))
|
t.Errorf("Length is not aligend: %d", len(padded))
|
||||||
}
|
}
|
||||||
unpadded, err := fs.unPad16(padded)
|
unpadded, err := unPad16(padded)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("unPad16 returned error:", err)
|
t.Error("unPad16 returned error:", err)
|
||||||
}
|
}
|
||||||
|
@ -12,15 +12,17 @@ import (
|
|||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rfjakob/gocryptfs/cryptfs"
|
|
||||||
"github.com/spacemonkeygo/openssl"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/spacemonkeygo/openssl"
|
||||||
|
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
|
||||||
fmt.Printf("Benchmarking AES-GCM-%d with 4kB block size\n", cryptfs.KEY_LEN*8)
|
fmt.Printf("Benchmarking AES-GCM-%d with 4kB block size\n", cryptocore.KeyLen*8)
|
||||||
|
|
||||||
r := m.Run()
|
r := m.Run()
|
||||||
os.Exit(r)
|
os.Exit(r)
|
||||||
@ -30,7 +32,7 @@ func BenchmarkGoEnc4K(b *testing.B) {
|
|||||||
buf := make([]byte, 1024*4)
|
buf := make([]byte, 1024*4)
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
|
|
||||||
var key [cryptfs.KEY_LEN]byte
|
var key [cryptocore.KeyLen]byte
|
||||||
var nonce [12]byte
|
var nonce [12]byte
|
||||||
aes, _ := aes.NewCipher(key[:])
|
aes, _ := aes.NewCipher(key[:])
|
||||||
aesgcm, _ := cipher.NewGCM(aes)
|
aesgcm, _ := cipher.NewGCM(aes)
|
||||||
@ -47,7 +49,7 @@ func BenchmarkGoDec4K(b *testing.B) {
|
|||||||
buf := make([]byte, 1024*4)
|
buf := make([]byte, 1024*4)
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
|
|
||||||
var key [cryptfs.KEY_LEN]byte
|
var key [cryptocore.KeyLen]byte
|
||||||
var nonce [12]byte
|
var nonce [12]byte
|
||||||
aes, _ := aes.NewCipher(key[:])
|
aes, _ := aes.NewCipher(key[:])
|
||||||
aesgcm, _ := cipher.NewGCM(aes)
|
aesgcm, _ := cipher.NewGCM(aes)
|
||||||
@ -67,7 +69,7 @@ func BenchmarkOpensslEnc4K(b *testing.B) {
|
|||||||
buf := make([]byte, 1024*4)
|
buf := make([]byte, 1024*4)
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
|
|
||||||
var key [cryptfs.KEY_LEN]byte
|
var key [cryptocore.KeyLen]byte
|
||||||
var nonce [12]byte
|
var nonce [12]byte
|
||||||
|
|
||||||
// This would be fileID + blockNo
|
// This would be fileID + blockNo
|
||||||
@ -79,7 +81,7 @@ func BenchmarkOpensslEnc4K(b *testing.B) {
|
|||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ciphertext.Reset()
|
ciphertext.Reset()
|
||||||
ectx, err := openssl.NewGCMEncryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
|
ectx, err := openssl.NewGCMEncryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.FailNow()
|
b.FailNow()
|
||||||
}
|
}
|
||||||
@ -112,7 +114,7 @@ func BenchmarkOpensslDec4K(b *testing.B) {
|
|||||||
tag := buf[4096:]
|
tag := buf[4096:]
|
||||||
buf = buf[0:4096]
|
buf = buf[0:4096]
|
||||||
|
|
||||||
var key [cryptfs.KEY_LEN]byte
|
var key [cryptocore.KeyLen]byte
|
||||||
var nonce [12]byte
|
var nonce [12]byte
|
||||||
|
|
||||||
var plaintext bytes.Buffer
|
var plaintext bytes.Buffer
|
||||||
@ -121,7 +123,7 @@ func BenchmarkOpensslDec4K(b *testing.B) {
|
|||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
plaintext.Reset()
|
plaintext.Reset()
|
||||||
dctx, err := openssl.NewGCMDecryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
|
dctx, err := openssl.NewGCMDecryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.FailNow()
|
b.FailNow()
|
||||||
}
|
}
|
||||||
@ -144,12 +146,12 @@ func BenchmarkOpensslDec4K(b *testing.B) {
|
|||||||
|
|
||||||
func makeOpensslCiphertext() []byte {
|
func makeOpensslCiphertext() []byte {
|
||||||
buf := make([]byte, 1024*4)
|
buf := make([]byte, 1024*4)
|
||||||
var key [cryptfs.KEY_LEN]byte
|
var key [cryptocore.KeyLen]byte
|
||||||
var nonce [12]byte
|
var nonce [12]byte
|
||||||
var ciphertext bytes.Buffer
|
var ciphertext bytes.Buffer
|
||||||
var part []byte
|
var part []byte
|
||||||
|
|
||||||
ectx, _ := openssl.NewGCMEncryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
|
ectx, _ := openssl.NewGCMEncryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
|
||||||
part, _ = ectx.EncryptUpdate(buf)
|
part, _ = ectx.EncryptUpdate(buf)
|
||||||
ciphertext.Write(part)
|
ciphertext.Write(part)
|
||||||
part, _ = ectx.EncryptFinal()
|
part, _ = ectx.EncryptFinal()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user