2016-04-26 02:42:17 +02:00
|
|
|
#ifndef MESSMER_CRYFS_TEST_CRYFS_FILESYSTEM_CRYTESTBASE_H
|
|
|
|
#define MESSMER_CRYFS_TEST_CRYFS_FILESYSTEM_CRYTESTBASE_H
|
|
|
|
|
2019-01-26 08:38:34 +01:00
|
|
|
#include <cryfs/impl/filesystem/CryDevice.h>
|
|
|
|
#include <cryfs/impl/config/CryPresetPasswordBasedKeyProvider.h>
|
2017-07-18 23:49:51 +02:00
|
|
|
#include <blockstore/implementations/inmemory/InMemoryBlockStore2.h>
|
2016-04-26 02:42:17 +02:00
|
|
|
#include <cpp-utils/tempfile/TempFile.h>
|
|
|
|
#include <cpp-utils/crypto/kdf/Scrypt.h>
|
2016-06-22 02:36:29 +02:00
|
|
|
#include "../../testutils/TestWithFakeHomeDirectory.h"
|
2018-10-22 04:31:08 +02:00
|
|
|
#include "../../testutils/MockConsole.h"
|
2016-04-26 02:42:17 +02:00
|
|
|
|
2018-12-11 06:20:18 +01:00
|
|
|
inline auto failOnIntegrityViolation() {
|
|
|
|
return [] {
|
|
|
|
EXPECT_TRUE(false);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-06-22 02:36:29 +02:00
|
|
|
class CryTestBase : public TestWithFakeHomeDirectory {
|
2016-04-26 02:42:17 +02:00
|
|
|
public:
|
2018-04-22 07:04:21 +02:00
|
|
|
CryTestBase(): _tempLocalStateDir(), _localStateDir(_tempLocalStateDir.path()), _configFile(false), _device(nullptr) {
|
2017-07-18 23:49:51 +02:00
|
|
|
auto fakeBlockStore = cpputils::make_unique_ref<blockstore::inmemory::InMemoryBlockStore2>();
|
2018-12-11 06:20:18 +01:00
|
|
|
_device = std::make_unique<cryfs::CryDevice>(configFile(), std::move(fakeBlockStore), _localStateDir, 0x12345678, false, false, failOnIntegrityViolation());
|
2019-10-13 13:29:59 +02:00
|
|
|
_device->setContext(fspp::Context { fspp::relatime() });
|
2016-04-26 02:42:17 +02:00
|
|
|
}
|
|
|
|
|
2018-12-22 00:58:30 +01:00
|
|
|
std::shared_ptr<cryfs::CryConfigFile> configFile() {
|
2016-04-26 02:42:17 +02:00
|
|
|
cryfs::CryConfig config;
|
|
|
|
config.SetCipher("aes-256-gcm");
|
2018-10-21 22:53:53 +02:00
|
|
|
config.SetEncryptionKey(cpputils::AES256_GCM::EncryptionKey::CreateKey(cpputils::Random::PseudoRandom(), cpputils::AES256_GCM::KEYSIZE).ToString());
|
2016-04-26 02:42:17 +02:00
|
|
|
config.SetBlocksizeBytes(10240);
|
2018-10-28 02:18:32 +01:00
|
|
|
cryfs::CryPresetPasswordBasedKeyProvider keyProvider("mypassword", cpputils::make_unique_ref<cpputils::SCrypt>(cpputils::SCrypt::TestSettings));
|
2018-10-22 04:31:08 +02:00
|
|
|
return cryfs::CryConfigFile::create(_configFile.path(), std::move(config), &keyProvider);
|
2016-04-26 02:42:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cryfs::CryDevice &device() {
|
|
|
|
return *_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-04-22 07:04:21 +02:00
|
|
|
cpputils::TempDir _tempLocalStateDir;
|
|
|
|
cryfs::LocalStateDir _localStateDir;
|
2016-04-26 02:42:17 +02:00
|
|
|
cpputils::TempFile _configFile;
|
|
|
|
std::unique_ptr<cryfs::CryDevice> _device;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|