2016-06-06 23:57:42 +02:00
|
|
|
package example_filesystems
|
2015-11-15 15:05:15 +01:00
|
|
|
|
2016-06-27 23:43:43 +02:00
|
|
|
// Mount example filesystems, check that the example content (normal file, symlinks)
|
|
|
|
// is there and test mkdir and rmdir
|
|
|
|
//
|
|
|
|
// Runs all the tests twice, once with "-openssl=false" and once with
|
|
|
|
// "-openssl=true".
|
2015-11-15 15:05:15 +01:00
|
|
|
|
|
|
|
import (
|
2016-07-11 20:31:36 +02:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2015-11-15 15:05:15 +01:00
|
|
|
"os"
|
2018-03-22 00:02:10 +01:00
|
|
|
"os/exec"
|
2017-11-23 01:38:30 +01:00
|
|
|
"syscall"
|
2015-11-15 15:05:15 +01:00
|
|
|
"testing"
|
2016-06-06 23:57:42 +02:00
|
|
|
|
2017-02-26 19:53:29 +01:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/stupidgcm"
|
2016-06-06 23:57:42 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
2015-11-15 15:05:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const statusTxtContent = "It works!\n"
|
|
|
|
|
2016-06-30 00:57:14 +02:00
|
|
|
var opensslOpt string
|
2016-06-27 23:43:43 +02:00
|
|
|
|
2018-05-04 22:27:59 +02:00
|
|
|
// tmpFsPath contains a private writeable copy of the example_filesystems
|
|
|
|
// folder.
|
|
|
|
var tmpFsPath string
|
|
|
|
|
2016-06-06 23:57:42 +02:00
|
|
|
func TestMain(m *testing.M) {
|
2016-07-11 20:31:36 +02:00
|
|
|
// Make "testing.Verbose()" return the correct value
|
|
|
|
flag.Parse()
|
2017-03-05 17:44:14 +01:00
|
|
|
variants := []string{"-openssl=false"}
|
2017-02-26 19:53:29 +01:00
|
|
|
if !stupidgcm.BuiltWithoutOpenssl {
|
|
|
|
variants = append(variants, "-openssl=true")
|
|
|
|
} else {
|
|
|
|
fmt.Println("Skipping OpenSSL tests, I have been compiled without openssl support")
|
2016-10-04 22:29:14 +02:00
|
|
|
}
|
|
|
|
for _, opensslOpt = range variants {
|
2016-07-11 20:31:36 +02:00
|
|
|
if testing.Verbose() {
|
2016-07-11 20:40:53 +02:00
|
|
|
fmt.Printf("example_filesystems: testing with %q\n", opensslOpt)
|
2016-07-11 20:31:36 +02:00
|
|
|
}
|
2016-10-08 19:22:59 +02:00
|
|
|
test_helpers.ResetTmpDir(false)
|
2018-05-04 22:27:59 +02:00
|
|
|
|
|
|
|
// Create a private copy of the example filesystems that we can
|
|
|
|
// mess with
|
|
|
|
cmd := exec.Command("cp", "-a", "../example_filesystems", test_helpers.TmpDir)
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("cp -a failed: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
tmpFsPath = test_helpers.TmpDir + "/example_filesystems/"
|
|
|
|
|
2016-06-30 00:57:14 +02:00
|
|
|
r := m.Run()
|
|
|
|
if r != 0 {
|
|
|
|
os.Exit(r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os.Exit(0)
|
2016-06-06 23:57:42 +02:00
|
|
|
}
|
|
|
|
|
2016-06-23 22:02:31 +02:00
|
|
|
// This filesystem is not supported anymore.
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv04(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.4"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2016-06-27 23:43:43 +02:00
|
|
|
err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt)
|
2016-06-23 21:29:00 +02:00
|
|
|
if err == nil {
|
2016-06-23 22:02:31 +02:00
|
|
|
t.Errorf("Mounting too old FS should fail")
|
2015-11-15 15:05:15 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-28 20:31:01 +01:00
|
|
|
|
2016-06-23 22:02:31 +02:00
|
|
|
// This filesystem is not supported anymore.
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv05(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.5"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2016-06-27 23:43:43 +02:00
|
|
|
err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt)
|
2016-06-19 20:01:29 +02:00
|
|
|
if err == nil {
|
2016-06-23 22:02:31 +02:00
|
|
|
t.Errorf("Mounting too old FS should fail")
|
2016-06-19 20:01:29 +02:00
|
|
|
}
|
2015-11-28 20:31:01 +01:00
|
|
|
}
|
2015-12-08 16:17:19 +01:00
|
|
|
|
2016-06-23 22:10:19 +02:00
|
|
|
// This filesystem is not supported anymore.
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv06(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.6"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2016-06-27 23:43:43 +02:00
|
|
|
err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt)
|
2016-06-19 20:01:29 +02:00
|
|
|
if err == nil {
|
2016-06-23 22:10:19 +02:00
|
|
|
t.Errorf("Mounting too old FS should fail")
|
2015-12-08 16:17:19 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-10 19:50:45 +01:00
|
|
|
|
2016-06-23 22:10:19 +02:00
|
|
|
// This filesystem is not supported anymore.
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv06PlaintextNames(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.6-plaintextnames"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2016-06-27 23:43:43 +02:00
|
|
|
err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt)
|
2016-06-19 20:01:29 +02:00
|
|
|
if err == nil {
|
2016-06-23 22:10:19 +02:00
|
|
|
t.Errorf("Mounting too old FS should fail")
|
2015-12-19 14:41:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test example_filesystems/v0.7
|
|
|
|
// with password mount and -masterkey mount
|
|
|
|
// v0.7 adds 128 bit GCM IVs
|
|
|
|
func TestExampleFSv07(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.7"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2015-12-19 14:41:39 +01:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
|
2016-06-16 23:24:32 +02:00
|
|
|
checkExampleFS(t, pDir, true)
|
2016-07-11 20:31:36 +02:00
|
|
|
test_helpers.UnmountPanic(pDir)
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey",
|
|
|
|
"ed7f6d83-40cce86c-0e7d79c2-a9438710-575221bf-30a0eb60-2821fa8f-7f3123bf",
|
2017-03-06 22:59:30 +01:00
|
|
|
"-raw64=false", "-hkdf=false", opensslOpt)
|
2016-06-16 23:24:32 +02:00
|
|
|
checkExampleFS(t, pDir, true)
|
2016-07-11 20:31:36 +02:00
|
|
|
test_helpers.UnmountPanic(pDir)
|
2015-12-10 19:50:45 +01:00
|
|
|
}
|
2016-06-04 14:57:01 +02:00
|
|
|
|
2016-06-23 20:53:14 +02:00
|
|
|
// gocryptfs v0.7 filesystem created with "-plaintextnames"
|
|
|
|
func TestExampleFSv07PlaintextNames(t *testing.T) {
|
|
|
|
cDir := "v0.7-plaintextnames"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir + ".mnt"
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2016-06-23 20:53:14 +02:00
|
|
|
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
|
2016-06-23 20:53:14 +02:00
|
|
|
checkExampleFS(t, pDir, true)
|
2016-07-11 20:31:36 +02:00
|
|
|
test_helpers.UnmountPanic(pDir)
|
2016-06-30 00:57:14 +02:00
|
|
|
// The actual unmount takes some time, this causes weird problems. Just don't
|
|
|
|
// reuse the mountpoint.
|
|
|
|
pDir = pDir + ".2"
|
2016-06-23 20:53:14 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-plaintextnames", "-masterkey",
|
2016-06-27 23:43:43 +02:00
|
|
|
"6d96397b-585631e1-c7cba69d-61e738b6-4d5ad2c2-e21f0fb3-52f60d3a-b08526f7",
|
2017-03-06 22:59:30 +01:00
|
|
|
"-raw64=false", "-hkdf=false", opensslOpt)
|
2016-06-23 20:53:14 +02:00
|
|
|
checkExampleFS(t, pDir, true)
|
2016-07-11 20:31:36 +02:00
|
|
|
test_helpers.UnmountPanic(pDir)
|
2016-06-23 20:53:14 +02:00
|
|
|
}
|
|
|
|
|
2016-06-04 14:57:01 +02:00
|
|
|
// Test example_filesystems/v0.9
|
|
|
|
// (gocryptfs v0.9 introduced long file name support)
|
|
|
|
func TestExampleFSv09(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.9"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2016-06-04 14:57:01 +02:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
|
2016-06-04 14:57:01 +02:00
|
|
|
checkExampleFSLongnames(t, pDir)
|
2016-07-11 20:31:36 +02:00
|
|
|
test_helpers.UnmountPanic(pDir)
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir = pDir + ".2"
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey",
|
|
|
|
"1cafe3f4-bc316466-2214c47c-ecd89bf3-4e078fe4-f5faeea7-8b7cab02-884f5e1c",
|
2017-03-06 22:59:30 +01:00
|
|
|
"-raw64=false", "-hkdf=false", opensslOpt)
|
2016-06-04 14:57:01 +02:00
|
|
|
checkExampleFSLongnames(t, pDir)
|
2016-07-11 20:31:36 +02:00
|
|
|
test_helpers.UnmountPanic(pDir)
|
2016-06-04 14:57:01 +02:00
|
|
|
}
|
2016-10-08 21:24:26 +02:00
|
|
|
|
|
|
|
// gocryptfs v1.1 introduced AES-SIV
|
|
|
|
func TestExampleFSv11(t *testing.T) {
|
|
|
|
cDir := "v1.1-aessiv"
|
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2016-10-08 21:24:26 +02:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
|
|
|
|
checkExampleFSLongnames(t, pDir)
|
|
|
|
test_helpers.UnmountPanic(pDir)
|
|
|
|
pDir = pDir + ".2"
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey",
|
2016-10-08 21:45:11 +02:00
|
|
|
"eaf371c3-f9a55336-8819f22b-7bccd7c2-a738cf61-7261c658-14c28a03-9428992b",
|
2017-03-06 22:59:30 +01:00
|
|
|
"-aessiv", "-raw64=false", "-hkdf=false", opensslOpt)
|
2016-10-08 21:24:26 +02:00
|
|
|
checkExampleFSLongnames(t, pDir)
|
|
|
|
test_helpers.UnmountPanic(pDir)
|
|
|
|
}
|
2016-10-08 21:45:11 +02:00
|
|
|
|
|
|
|
// gocryptfs v1.1 introduced reverse mode
|
|
|
|
func TestExampleFSv11reverse(t *testing.T) {
|
|
|
|
dirA := "v1.1-reverse"
|
|
|
|
dirB := test_helpers.TmpDir + "/" + dirA + ".B"
|
|
|
|
err := os.Mkdir(dirB, 0700)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
dirC := test_helpers.TmpDir + "/" + dirA + ".C"
|
|
|
|
err = os.Mkdir(dirC, 0700)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-05-04 22:27:59 +02:00
|
|
|
dirA = tmpFsPath + dirA
|
2016-10-08 21:45:11 +02:00
|
|
|
test_helpers.MountOrFatal(t, dirA, dirB, "-reverse", "-extpass", "echo test", opensslOpt)
|
2016-10-08 22:25:08 +02:00
|
|
|
c := dirB + "/gocryptfs.conf"
|
|
|
|
if !test_helpers.VerifyExistence(c) {
|
|
|
|
t.Errorf("%s missing", c)
|
|
|
|
}
|
2016-10-08 21:45:11 +02:00
|
|
|
test_helpers.MountOrFatal(t, dirB, dirC, "-extpass", "echo test", opensslOpt)
|
|
|
|
checkExampleFSrw(t, dirC, false)
|
|
|
|
test_helpers.UnmountPanic(dirC)
|
|
|
|
test_helpers.UnmountPanic(dirB)
|
|
|
|
|
|
|
|
m := "68b51855-042abd80-635ae1ba-90152a78-2ec2d243-832ac72a-eab0561a-f2d37913"
|
2017-03-06 22:43:55 +01:00
|
|
|
test_helpers.MountOrFatal(t, dirA, dirB, "-reverse", "-masterkey", m,
|
2017-03-06 22:59:30 +01:00
|
|
|
"-raw64=false", "-hkdf=false", opensslOpt)
|
2016-10-08 22:25:08 +02:00
|
|
|
if !test_helpers.VerifyExistence(c) {
|
|
|
|
t.Errorf("%s missing", c)
|
|
|
|
}
|
2017-03-06 22:43:55 +01:00
|
|
|
test_helpers.MountOrFatal(t, dirB, dirC, "-aessiv", "-masterkey", m,
|
2017-03-06 22:59:30 +01:00
|
|
|
"-raw64=false", "-hkdf=false", opensslOpt)
|
2016-10-08 21:45:11 +02:00
|
|
|
checkExampleFSrw(t, dirC, false)
|
|
|
|
test_helpers.UnmountPanic(dirC)
|
|
|
|
test_helpers.UnmountPanic(dirB)
|
|
|
|
}
|
2016-10-08 21:49:21 +02:00
|
|
|
|
|
|
|
// gocryptfs v1.1 introduced reverse mode
|
|
|
|
func TestExampleFSv11reversePlaintextnames(t *testing.T) {
|
|
|
|
dirA := "v1.1-reverse-plaintextnames"
|
|
|
|
dirB := test_helpers.TmpDir + "/" + dirA + ".B"
|
|
|
|
err := os.Mkdir(dirB, 0700)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
dirC := test_helpers.TmpDir + "/" + dirA + ".C"
|
|
|
|
err = os.Mkdir(dirC, 0700)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-05-04 22:27:59 +02:00
|
|
|
dirA = tmpFsPath + dirA
|
2016-10-08 21:49:21 +02:00
|
|
|
test_helpers.MountOrFatal(t, dirA, dirB, "-reverse", "-extpass", "echo test", opensslOpt)
|
2016-10-08 22:25:08 +02:00
|
|
|
c := dirB + "/gocryptfs.conf"
|
|
|
|
if !test_helpers.VerifyExistence(c) {
|
|
|
|
t.Errorf("%s missing", c)
|
|
|
|
}
|
2016-10-08 21:49:21 +02:00
|
|
|
test_helpers.MountOrFatal(t, dirB, dirC, "-extpass", "echo test", opensslOpt)
|
|
|
|
checkExampleFSrw(t, dirC, false)
|
|
|
|
test_helpers.UnmountPanic(dirC)
|
|
|
|
test_helpers.UnmountPanic(dirB)
|
|
|
|
|
|
|
|
m := "e7fb8f0d-2a81df9e-26611e4b-5540b218-e48aa458-c2a623af-d0c82637-1466b5f2"
|
2017-03-06 22:43:55 +01:00
|
|
|
test_helpers.MountOrFatal(t, dirA, dirB, "-reverse", "-masterkey", m,
|
2017-03-06 22:59:30 +01:00
|
|
|
"-raw64=false", "-hkdf=false", opensslOpt)
|
2016-10-08 22:25:08 +02:00
|
|
|
if !test_helpers.VerifyExistence(c) {
|
|
|
|
t.Errorf("%s missing", c)
|
|
|
|
}
|
2017-03-06 22:43:55 +01:00
|
|
|
test_helpers.MountOrFatal(t, dirB, dirC, "-aessiv", "-masterkey", m,
|
2017-03-06 22:59:30 +01:00
|
|
|
"-raw64=false", "-hkdf=false", opensslOpt)
|
2016-10-08 21:49:21 +02:00
|
|
|
checkExampleFSrw(t, dirC, false)
|
|
|
|
test_helpers.UnmountPanic(dirC)
|
|
|
|
test_helpers.UnmountPanic(dirB)
|
|
|
|
}
|
2017-03-05 23:06:40 +01:00
|
|
|
|
|
|
|
// gocryptfs v1.3 introduced HKDF
|
|
|
|
func TestExampleFSv13(t *testing.T) {
|
|
|
|
cDir := "v1.3"
|
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2017-03-05 23:06:40 +01:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
|
|
|
|
checkExampleFSLongnames(t, pDir)
|
|
|
|
test_helpers.UnmountPanic(pDir)
|
2017-03-06 22:43:55 +01:00
|
|
|
|
|
|
|
pDir = pDir + "_m"
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey",
|
2017-03-06 22:53:49 +01:00
|
|
|
"fd890dab-86bf61cf-ec5ad460-ad3ed01f-9c52d546-2a31783d-a56b088d-3d05232e",
|
2017-03-06 22:43:55 +01:00
|
|
|
opensslOpt)
|
|
|
|
checkExampleFSLongnames(t, pDir)
|
|
|
|
test_helpers.UnmountPanic(pDir)
|
2017-03-05 23:06:40 +01:00
|
|
|
}
|
2017-05-28 19:02:22 +02:00
|
|
|
|
2018-03-22 00:02:10 +01:00
|
|
|
// Check that the masterkey=stdin cli option works.
|
|
|
|
func TestExampleFSv13MasterkeyStdin(t *testing.T) {
|
|
|
|
cDir := "v1.3"
|
|
|
|
pDir := test_helpers.TmpDir + "/TestExampleFSv13MasterkeyStdin.mnt"
|
2018-05-04 22:27:59 +02:00
|
|
|
cDir = tmpFsPath + cDir
|
2018-03-22 00:02:10 +01:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
args := []string{"-q", "-masterkey=stdin", opensslOpt, cDir, pDir}
|
|
|
|
cmd := exec.Command(test_helpers.GocryptfsBinary, args...)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
p, err := cmd.StdinPipe()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = cmd.Start()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
// Write masterkey to stdin
|
|
|
|
p.Write([]byte("fd890dab-86bf61cf-ec5ad460-ad3ed01f-9c52d546-2a31783d-a56b088d-3d05232e"))
|
|
|
|
p.Close()
|
|
|
|
err = cmd.Wait()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
// Check that the fs decrypts ok & unmount
|
|
|
|
checkExampleFSLongnames(t, pDir)
|
|
|
|
test_helpers.UnmountPanic(pDir)
|
|
|
|
}
|
|
|
|
|
2017-05-28 19:02:22 +02:00
|
|
|
// gocryptfs v1.3 introduced HKDF.
|
|
|
|
// We check the md5 sum of the encrypted version of a file to make sure we don't
|
|
|
|
// accidentially change the ciphertext generation.
|
2017-10-01 13:50:25 +02:00
|
|
|
// Create a full crypto round-trip by mounting two times:
|
|
|
|
// dirA -> reverse mount -> dirB -> forward mount -> dirC
|
2017-05-28 19:02:22 +02:00
|
|
|
func TestExampleFSv13reverse(t *testing.T) {
|
2017-11-23 01:38:30 +01:00
|
|
|
var R_OK uint32 = 4
|
2017-05-28 19:02:22 +02:00
|
|
|
// Prepare directories
|
|
|
|
dirA := "v1.3-reverse"
|
|
|
|
dirB := test_helpers.TmpDir + "/" + dirA + ".B"
|
|
|
|
err := os.Mkdir(dirB, 0700)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
dirC := test_helpers.TmpDir + "/" + dirA + ".C"
|
|
|
|
err = os.Mkdir(dirC, 0700)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-05-04 22:27:59 +02:00
|
|
|
dirA = tmpFsPath + dirA
|
2017-05-28 19:02:22 +02:00
|
|
|
// Mount using password
|
|
|
|
test_helpers.MountOrFatal(t, dirA, dirB, "-reverse", "-extpass", "echo test", opensslOpt)
|
|
|
|
c := dirB + "/gocryptfs.conf"
|
|
|
|
if !test_helpers.VerifyExistence(c) {
|
|
|
|
t.Errorf("%s missing", c)
|
|
|
|
}
|
|
|
|
test_helpers.MountOrFatal(t, dirB, dirC, "-extpass", "echo test", opensslOpt)
|
|
|
|
// Test
|
|
|
|
checkExampleFSrw(t, dirC, false)
|
2017-11-23 01:38:30 +01:00
|
|
|
// Access to encrypted version of '..' should fail
|
|
|
|
cPath := dirB + "/D8VwRPqWW8x7M5OEoMs0Eg"
|
|
|
|
err = syscall.Access(cPath, R_OK)
|
|
|
|
if err != syscall.ENOENT {
|
|
|
|
t.Errorf("want ENOENT, got: %v", err)
|
|
|
|
}
|
|
|
|
// Access to encrypted version of '.' should fail
|
|
|
|
cPath = dirB + "/kkmARPseVj4XQFW-EL42-w"
|
|
|
|
err = syscall.Access(cPath, R_OK)
|
|
|
|
if err != syscall.ENOENT {
|
|
|
|
t.Errorf("want ENOENT, got: %v", err)
|
|
|
|
}
|
2017-05-28 19:02:22 +02:00
|
|
|
// Encrypted version of dir1/dir2/file (10000 zero bytes)
|
2017-11-23 01:38:30 +01:00
|
|
|
cPath = dirB + "/zOsW1-BUX54hC2hmhu2EOw/4ZqrpGQdw5r07KR1qw2ZeQ/tfCm9Sp9J_Dvc-jD7J6p8g"
|
2017-05-28 19:02:22 +02:00
|
|
|
want := "9818501d214c5eb42ca2472caf6c82a1"
|
|
|
|
actual := test_helpers.Md5fn(cPath)
|
|
|
|
if actual != want {
|
|
|
|
t.Errorf("wrong md5")
|
|
|
|
}
|
|
|
|
// Unmount
|
|
|
|
test_helpers.UnmountPanic(dirC)
|
|
|
|
test_helpers.UnmountPanic(dirB)
|
|
|
|
|
|
|
|
// Mount using masterkey
|
|
|
|
m := "2290a7f4-3e1908fb-b006f7d9-261bdaf1-4b72bc38-3b24956c-db7d8a8d-d996076a"
|
|
|
|
test_helpers.MountOrFatal(t, dirA, dirB, "-reverse", "-masterkey", m, opensslOpt)
|
|
|
|
if !test_helpers.VerifyExistence(c) {
|
|
|
|
t.Errorf("%s missing", c)
|
|
|
|
}
|
|
|
|
test_helpers.MountOrFatal(t, dirB, dirC, "-aessiv", "-masterkey", m, opensslOpt)
|
|
|
|
// Test
|
|
|
|
checkExampleFSrw(t, dirC, false)
|
|
|
|
actual = test_helpers.Md5fn(cPath)
|
|
|
|
if actual != want {
|
|
|
|
t.Errorf("wrong md5")
|
|
|
|
}
|
|
|
|
// Unmmount
|
|
|
|
test_helpers.UnmountPanic(dirC)
|
|
|
|
test_helpers.UnmountPanic(dirB)
|
|
|
|
}
|