MyClientId is generated outside of CryDevice to give the CryConfigCreator access to it.

This commit is contained in:
Sebastian Messmer 2016-06-26 16:53:10 -07:00
parent 7b56706c1a
commit be8dffb24d
20 changed files with 132 additions and 81 deletions

View File

@ -191,7 +191,7 @@ namespace cryfs {
return *configFile;
}
CryConfigFile Cli::_loadOrCreateConfig(const ProgramOptions &options) {
CryConfigLoader::ConfigLoadResult Cli::_loadOrCreateConfig(const ProgramOptions &options) {
try {
auto configFile = _determineConfigFile(options);
auto config = _loadOrCreateConfigFile(configFile, options.cipher(), options.blocksizeBytes());
@ -206,7 +206,7 @@ namespace cryfs {
}
}
optional<CryConfigFile> Cli::_loadOrCreateConfigFile(const bf::path &configFilePath, const optional<string> &cipher, const optional<uint32_t> &blocksizeBytes) {
optional<CryConfigLoader::ConfigLoadResult> Cli::_loadOrCreateConfigFile(const bf::path &configFilePath, const optional<string> &cipher, const optional<uint32_t> &blocksizeBytes) {
if (_noninteractive) {
return CryConfigLoader(_console, _keyGenerator, _scryptSettings,
&Cli::_askPasswordNoninteractive,
@ -224,7 +224,7 @@ namespace cryfs {
try {
auto blockStore = make_unique_ref<OnDiskBlockStore>(options.baseDir());
auto config = _loadOrCreateConfig(options);
CryDevice device(std::move(config), std::move(blockStore));
CryDevice device(std::move(config.configFile), std::move(blockStore), config.myClientId);
_sanityCheckFilesystem(&device);
fspp::FilesystemImpl fsimpl(&device);
fspp::fuse::Fuse fuse(&fsimpl, "cryfs", "cryfs@"+options.baseDir().native());

View File

@ -11,6 +11,7 @@
#include <cpp-utils/network/HttpClient.h>
#include <cryfs/filesystem/CryDevice.h>
#include "CallAfterTimeout.h"
#include <cryfs/config/CryConfigLoader.h>
namespace cryfs {
class Cli final {
@ -21,8 +22,8 @@ namespace cryfs {
private:
void _checkForUpdates();
void _runFilesystem(const program_options::ProgramOptions &options);
CryConfigFile _loadOrCreateConfig(const program_options::ProgramOptions &options);
boost::optional<CryConfigFile> _loadOrCreateConfigFile(const boost::filesystem::path &configFilePath, const boost::optional<std::string> &cipher, const boost::optional<uint32_t> &blocksizeBytes);
CryConfigLoader::ConfigLoadResult _loadOrCreateConfig(const program_options::ProgramOptions &options);
boost::optional<CryConfigLoader::ConfigLoadResult> _loadOrCreateConfigFile(const boost::filesystem::path &configFilePath, const boost::optional<std::string> &cipher, const boost::optional<uint32_t> &blocksizeBytes);
boost::filesystem::path _determineConfigFile(const program_options::ProgramOptions &options);
static std::string _askPasswordForExistingFilesystem();
static std::string _askPasswordForNewFilesystem();

View File

@ -40,7 +40,8 @@ set(LIB_SOURCES
filesystem/cachingfsblobstore/SymlinkBlobRef.cpp
filesystem/CryFile.cpp
filesystem/CryDevice.cpp
filesystem/MyClientId.cpp
localstate/MyClientId.cpp
localstate/LocalStateDir.cpp
)
add_library(${PROJECT_NAME} STATIC ${LIB_SOURCES})

View File

@ -2,6 +2,8 @@
#include "CryCipher.h"
#include <gitversion/gitversion.h>
#include <cpp-utils/random/Random.h>
#include <cryfs/localstate/LocalStateDir.h>
#include <cryfs/localstate/MyClientId.h>
using cpputils::Console;
using cpputils::unique_ref;
@ -19,7 +21,7 @@ namespace cryfs {
:_console(console), _configConsole(console, noninteractive), _encryptionKeyGenerator(encryptionKeyGenerator) {
}
CryConfig CryConfigCreator::create(const optional<string> &cipherFromCommandLine, const optional<uint32_t> &blocksizeBytesFromCommandLine) {
CryConfigCreator::ConfigCreateResult CryConfigCreator::create(const optional<string> &cipherFromCommandLine, const optional<uint32_t> &blocksizeBytesFromCommandLine) {
CryConfig config;
config.SetCipher(_generateCipher(cipherFromCommandLine));
config.SetVersion(gitversion::VersionString());
@ -31,7 +33,8 @@ namespace cryfs {
#ifndef CRYFS_NO_COMPATIBILITY
config.SetHasVersionNumbers(true);
#endif
return config;
uint32_t myClientId = MyClientId(LocalStateDir::forFilesystemId(config.FilesystemId())).loadOrGenerate();
return ConfigCreateResult {std::move(config), myClientId};
}
uint32_t CryConfigCreator::_generateBlocksizeBytes(const optional<uint32_t> &blocksizeBytesFromCommandLine) {

View File

@ -14,7 +14,12 @@ namespace cryfs {
CryConfigCreator(std::shared_ptr<cpputils::Console> console, cpputils::RandomGenerator &encryptionKeyGenerator, bool noninteractive);
CryConfigCreator(CryConfigCreator &&rhs) = default;
CryConfig create(const boost::optional<std::string> &cipherFromCommandLine, const boost::optional<uint32_t> &blocksizeBytesFromCommandLine);
struct ConfigCreateResult {
CryConfig config;
uint32_t myClientId;
};
ConfigCreateResult create(const boost::optional<std::string> &cipherFromCommandLine, const boost::optional<uint32_t> &blocksizeBytesFromCommandLine);
private:
std::string _generateCipher(const boost::optional<std::string> &cipherFromCommandLine);
std::string _generateEncKey(const std::string &cipher);

View File

@ -6,6 +6,8 @@
#include <boost/algorithm/string/predicate.hpp>
#include <gitversion/gitversion.h>
#include <gitversion/VersionCompare.h>
#include "../localstate/LocalStateDir.h"
#include "../localstate/MyClientId.h"
namespace bf = boost::filesystem;
using cpputils::unique_ref;
@ -22,6 +24,8 @@ using std::vector;
using std::string;
using std::function;
using std::shared_ptr;
using std::unique_ptr;
using std::make_unique;
using gitversion::VersionCompare;
using namespace cpputils::logging;
@ -33,7 +37,7 @@ CryConfigLoader::CryConfigLoader(shared_ptr<Console> console, RandomGenerator &k
_cipherFromCommandLine(cipherFromCommandLine), _blocksizeBytesFromCommandLine(blocksizeBytesFromCommandLine) {
}
optional<CryConfigFile> CryConfigLoader::_loadConfig(const bf::path &filename) {
optional<CryConfigLoader::ConfigLoadResult> CryConfigLoader::_loadConfig(const bf::path &filename) {
string password = _askPasswordForExistingFilesystem();
std::cout << "Loading config file (this can take some time)..." << std::flush;
auto config = CryConfigFile::load(filename, password);
@ -53,7 +57,8 @@ optional<CryConfigFile> CryConfigLoader::_loadConfig(const bf::path &filename) {
config->save();
}
_checkCipher(*config->config());
return std::move(*config);
uint32_t myClientId = MyClientId(LocalStateDir::forFilesystemId(config->config()->FilesystemId())).loadOrGenerate();
return ConfigLoadResult {std::move(*config), myClientId};
}
void CryConfigLoader::_checkVersion(const CryConfig &config) {
@ -75,7 +80,7 @@ void CryConfigLoader::_checkCipher(const CryConfig &config) const {
}
}
optional<CryConfigFile> CryConfigLoader::loadOrCreate(const bf::path &filename) {
optional<CryConfigLoader::ConfigLoadResult> CryConfigLoader::loadOrCreate(const bf::path &filename) {
if (bf::exists(filename)) {
return _loadConfig(filename);
} else {
@ -83,14 +88,14 @@ optional<CryConfigFile> CryConfigLoader::loadOrCreate(const bf::path &filename)
}
}
CryConfigFile CryConfigLoader::_createConfig(const bf::path &filename) {
CryConfigLoader::ConfigLoadResult CryConfigLoader::_createConfig(const bf::path &filename) {
auto config = _creator.create(_cipherFromCommandLine, _blocksizeBytesFromCommandLine);
//TODO Ask confirmation if using insecure password (<8 characters)
string password = _askPasswordForNewFilesystem();
std::cout << "Creating config file (this can take some time)..." << std::flush;
auto result = CryConfigFile::create(filename, std::move(config), password, _scryptSettings);
auto result = CryConfigFile::create(filename, std::move(config.config), password, _scryptSettings);
std::cout << "done" << std::endl;
return result;
return ConfigLoadResult {std::move(result), config.myClientId};
}

View File

@ -16,11 +16,16 @@ public:
CryConfigLoader(std::shared_ptr<cpputils::Console> console, cpputils::RandomGenerator &keyGenerator, const cpputils::SCryptSettings &scryptSettings, std::function<std::string()> askPasswordForExistingFilesystem, std::function<std::string()> askPasswordForNewFilesystem, const boost::optional<std::string> &cipherFromCommandLine, const boost::optional<uint32_t> &blocksizeBytesFromCommandLine, bool noninteractive);
CryConfigLoader(CryConfigLoader &&rhs) = default;
boost::optional<CryConfigFile> loadOrCreate(const boost::filesystem::path &filename);
struct ConfigLoadResult {
CryConfigFile configFile;
uint32_t myClientId;
};
boost::optional<ConfigLoadResult> loadOrCreate(const boost::filesystem::path &filename);
private:
boost::optional<CryConfigFile> _loadConfig(const boost::filesystem::path &filename);
CryConfigFile _createConfig(const boost::filesystem::path &filename);
boost::optional<ConfigLoadResult> _loadConfig(const boost::filesystem::path &filename);
ConfigLoadResult _createConfig(const boost::filesystem::path &filename);
void _checkVersion(const CryConfig &config);
void _checkCipher(const CryConfig &config) const;

View File

@ -17,7 +17,8 @@
#include "../config/CryCipher.h"
#include <cpp-utils/system/homedir.h>
#include <gitversion/VersionCompare.h>
#include "MyClientId.h"
#include "cryfs/localstate/MyClientId.h"
#include "cryfs/localstate/LocalStateDir.h"
using std::string;
@ -52,12 +53,12 @@ namespace bf = boost::filesystem;
namespace cryfs {
CryDevice::CryDevice(CryConfigFile configFile, unique_ref<BlockStore> blockStore)
CryDevice::CryDevice(CryConfigFile configFile, unique_ref<BlockStore> blockStore, uint32_t myClientId)
: _fsBlobStore(
make_unique_ref<ParallelAccessFsBlobStore>(
make_unique_ref<CachingFsBlobStore>(
make_unique_ref<FsBlobStore>(
CreateBlobStore(std::move(blockStore), &configFile)
CreateBlobStore(std::move(blockStore), &configFile, myClientId)
)
)
)
@ -66,8 +67,8 @@ CryDevice::CryDevice(CryConfigFile configFile, unique_ref<BlockStore> blockStore
_onFsAction() {
}
unique_ref<blobstore::BlobStore> CryDevice::CreateBlobStore(unique_ref<BlockStore> blockStore, CryConfigFile *configFile) {
auto versionCountingEncryptedBlockStore = CreateVersionCountingEncryptedBlockStore(std::move(blockStore), configFile);
unique_ref<blobstore::BlobStore> CryDevice::CreateBlobStore(unique_ref<BlockStore> blockStore, CryConfigFile *configFile, uint32_t myClientId) {
auto versionCountingEncryptedBlockStore = CreateVersionCountingEncryptedBlockStore(std::move(blockStore), configFile, myClientId);
// Create versionCountingEncryptedBlockStore not in the same line as BlobStoreOnBlocks, because it can modify BlocksizeBytes
// in the configFile and therefore has to be run before the second parameter to the BlobStoreOnBlocks parameter is evaluated.
return make_unique_ref<BlobStoreOnBlocks>(
@ -77,11 +78,10 @@ unique_ref<blobstore::BlobStore> CryDevice::CreateBlobStore(unique_ref<BlockStor
configFile->config()->BlocksizeBytes());
}
unique_ref<BlockStore> CryDevice::CreateVersionCountingEncryptedBlockStore(unique_ref<BlockStore> blockStore, CryConfigFile *configFile) {
unique_ref<BlockStore> CryDevice::CreateVersionCountingEncryptedBlockStore(unique_ref<BlockStore> blockStore, CryConfigFile *configFile, uint32_t myClientId) {
auto encryptedBlockStore = CreateEncryptedBlockStore(*configFile->config(), std::move(blockStore));
auto statePath = _statePath(configFile->config()->FilesystemId());
auto statePath = LocalStateDir::forFilesystemId(configFile->config()->FilesystemId());
auto integrityFilePath = statePath / "integritydata";
auto myClientId = MyClientId(statePath).loadOrGenerate();
#ifndef CRYFS_NO_COMPATIBILITY
if (!configFile->config()->HasVersionNumbers()) {
@ -101,22 +101,6 @@ Key CryDevice::CreateRootBlobAndReturnKey() {
return rootBlob->key();
}
bf::path CryDevice::_statePath(const CryConfig::FilesystemID &filesystemId) {
bf::path app_dir = cpputils::system::HomeDirectory::get() / ".cryfs";
_createDirIfNotExists(app_dir);
bf::path filesystems_dir = app_dir / "filesystems";
_createDirIfNotExists(filesystems_dir);
bf::path this_filesystem_dir = filesystems_dir / filesystemId.ToString();
_createDirIfNotExists(this_filesystem_dir);
return this_filesystem_dir;
}
void CryDevice::_createDirIfNotExists(const bf::path &path) {
if (!bf::exists(path)) {
bf::create_directory(path);
}
}
optional<unique_ref<fspp::Node>> CryDevice::Load(const bf::path &path) {
// TODO Split into smaller functions
ASSERT(path.is_absolute(), "Non absolute path given");

View File

@ -17,7 +17,7 @@ namespace cryfs {
class CryDevice final: public fspp::Device {
public:
CryDevice(CryConfigFile config, cpputils::unique_ref<blockstore::BlockStore> blockStore);
CryDevice(CryConfigFile config, cpputils::unique_ref<blockstore::BlockStore> blockStore, uint32_t myClientId);
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
@ -47,13 +47,10 @@ private:
blockstore::Key _rootKey;
std::vector<std::function<void()>> _onFsAction;
static boost::filesystem::path _statePath(const CryConfig::FilesystemID &filesystemId);
static void _createDirIfNotExists(const boost::filesystem::path &path);
blockstore::Key GetOrCreateRootKey(CryConfigFile *config);
blockstore::Key CreateRootBlobAndReturnKey();
static cpputils::unique_ref<blobstore::BlobStore> CreateBlobStore(cpputils::unique_ref<blockstore::BlockStore> blockStore, CryConfigFile *configFile);
static cpputils::unique_ref<blockstore::BlockStore> CreateVersionCountingEncryptedBlockStore(cpputils::unique_ref<blockstore::BlockStore> blockStore, CryConfigFile *configFile);
static cpputils::unique_ref<blobstore::BlobStore> CreateBlobStore(cpputils::unique_ref<blockstore::BlockStore> blockStore, CryConfigFile *configFile, uint32_t myClientId);
static cpputils::unique_ref<blockstore::BlockStore> CreateVersionCountingEncryptedBlockStore(cpputils::unique_ref<blockstore::BlockStore> blockStore, CryConfigFile *configFile, uint32_t myClientId);
static cpputils::unique_ref<blockstore::BlockStore> CreateEncryptedBlockStore(const CryConfig &config, cpputils::unique_ref<blockstore::BlockStore> baseBlockStore);
struct BlobWithParent {

View File

@ -0,0 +1,23 @@
#include "LocalStateDir.h"
#include <cpp-utils/system/homedir.h>
#include <boost/filesystem.hpp>
namespace bf = boost::filesystem;
namespace cryfs {
bf::path LocalStateDir::forFilesystemId(const CryConfig::FilesystemID &filesystemId) {
bf::path app_dir = cpputils::system::HomeDirectory::get() / ".cryfs";
_createDirIfNotExists(app_dir);
bf::path filesystems_dir = app_dir / "filesystems";
_createDirIfNotExists(filesystems_dir);
bf::path this_filesystem_dir = filesystems_dir / filesystemId.ToString();
_createDirIfNotExists(this_filesystem_dir);
return this_filesystem_dir;
}
void LocalStateDir::_createDirIfNotExists(const bf::path &path) {
if (!bf::exists(path)) {
bf::create_directory(path);
}
}
}

View File

@ -0,0 +1,23 @@
#pragma once
#ifndef MESSMER_CRYFS_LOCALSTATE_LOCALSTATEDIR_H_
#define MESSMER_CRYFS_LOCALSTATE_LOCALSTATEDIR_H_
#include <cpp-utils/macros.h>
#include <boost/filesystem/path.hpp>
#include "../config/CryConfig.h"
namespace cryfs {
class LocalStateDir final {
public:
static boost::filesystem::path forFilesystemId(const CryConfig::FilesystemID &filesystemId);
private:
LocalStateDir(); // static functions only
static void _createDirIfNotExists(const boost::filesystem::path &path);
};
}
#endif

View File

@ -1,6 +1,6 @@
#pragma once
#ifndef MESSMER_CRYFS_FILESYSTEM_MYCLIENTID_H_
#define MESSMER_CRYFS_FILESYSTEM_MYCLIENTID_H_
#ifndef MESSMER_CRYFS_LOCALSTATE_MYCLIENTID_H_
#define MESSMER_CRYFS_LOCALSTATE_MYCLIENTID_H_
#include <cpp-utils/macros.h>
#include <boost/filesystem/path.hpp>

View File

@ -17,7 +17,7 @@ set(SOURCES
filesystem/CryFsTest.cpp
filesystem/CryNodeTest.cpp
filesystem/FileSystemTest.cpp
filesystem/MyClientIdTest.cpp
localstate/MyClientIdTest.cpp
)
add_executable(${PROJECT_NAME} ${SOURCES})

View File

@ -63,91 +63,91 @@ public:
TEST_F(CryConfigCreatorTest, DoesAskForCipherIfNotSpecified) {
AnswerNoToDefaultSettings();
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseAnyCipher());
CryConfig config = creator.create(none, none);
CryConfig config = creator.create(none, none).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForCipherIfSpecified) {
AnswerNoToDefaultSettings();
EXPECT_DOES_NOT_ASK_FOR_CIPHER();
CryConfig config = creator.create(string("aes-256-gcm"), none);
CryConfig config = creator.create(string("aes-256-gcm"), none).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForCipherIfUsingDefaultSettings) {
AnswerYesToDefaultSettings();
EXPECT_DOES_NOT_ASK_FOR_CIPHER();
CryConfig config = creator.create(none, none);
CryConfig config = creator.create(none, none).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForCipherIfNoninteractive) {
EXPECT_DOES_NOT_ASK_TO_USE_DEFAULT_SETTINGS();
EXPECT_DOES_NOT_ASK_FOR_CIPHER();
CryConfig config = noninteractiveCreator.create(none, none);
CryConfig config = noninteractiveCreator.create(none, none).config;
}
TEST_F(CryConfigCreatorTest, DoesAskForBlocksizeIfNotSpecified) {
AnswerNoToDefaultSettings();
EXPECT_ASK_FOR_BLOCKSIZE().WillOnce(Return(1));
CryConfig config = creator.create(none, none);
CryConfig config = creator.create(none, none).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForBlocksizeIfSpecified) {
AnswerNoToDefaultSettings();
EXPECT_DOES_NOT_ASK_FOR_BLOCKSIZE();
CryConfig config = creator.create(none, 10*1024u);
CryConfig config = creator.create(none, 10*1024u).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForBlocksizeIfNoninteractive) {
EXPECT_DOES_NOT_ASK_TO_USE_DEFAULT_SETTINGS();
EXPECT_DOES_NOT_ASK_FOR_BLOCKSIZE();
CryConfig config = noninteractiveCreator.create(none, none);
CryConfig config = noninteractiveCreator.create(none, none).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForBlocksizeIfUsingDefaultSettings) {
AnswerYesToDefaultSettings();
EXPECT_DOES_NOT_ASK_FOR_BLOCKSIZE();
CryConfig config = creator.create(none, none);
CryConfig config = creator.create(none, none).config;
}
TEST_F(CryConfigCreatorTest, ChoosesEmptyRootBlobId) {
AnswerNoToDefaultSettings();
CryConfig config = creator.create(none, none);
CryConfig config = creator.create(none, none).config;
EXPECT_EQ("", config.RootBlob()); // This tells CryFS to create a new root blob
}
TEST_F(CryConfigCreatorTest, ChoosesValidEncryptionKey_448) {
AnswerNoToDefaultSettings();
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseCipher("mars-448-gcm"));
CryConfig config = creator.create(none, none);
CryConfig config = creator.create(none, none).config;
cpputils::Mars448_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
}
TEST_F(CryConfigCreatorTest, ChoosesValidEncryptionKey_256) {
AnswerNoToDefaultSettings();
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseCipher("aes-256-gcm"));
CryConfig config = creator.create(none, none);
CryConfig config = creator.create(none, none).config;
cpputils::AES256_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
}
TEST_F(CryConfigCreatorTest, ChoosesValidEncryptionKey_128) {
AnswerNoToDefaultSettings();
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseCipher("aes-128-gcm"));
CryConfig config = creator.create(none, none);
CryConfig config = creator.create(none, none).config;
cpputils::AES128_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
}
TEST_F(CryConfigCreatorTest, DoesNotAskForAnythingIfEverythingIsSpecified) {
EXPECT_DOES_NOT_ASK_TO_USE_DEFAULT_SETTINGS();
EXPECT_DOES_NOT_ASK_FOR_CIPHER();
CryConfig config = noninteractiveCreator.create(string("aes-256-gcm"), 10*1024u);
CryConfig config = noninteractiveCreator.create(string("aes-256-gcm"), 10*1024u).config;
}
TEST_F(CryConfigCreatorTest, SetsCorrectCreatedWithVersion) {
CryConfig config = noninteractiveCreator.create(none, none);
CryConfig config = noninteractiveCreator.create(none, none).config;
EXPECT_EQ(gitversion::VersionString(), config.CreatedWithVersion());
}
TEST_F(CryConfigCreatorTest, SetsCorrectVersion) {
CryConfig config = noninteractiveCreator.create(none, none);
CryConfig config = noninteractiveCreator.create(none, none).config;
EXPECT_EQ(gitversion::VersionString(), config.Version());
}

View File

@ -44,41 +44,45 @@ public:
CryConfigFile Create(const string &password = "mypassword", const optional<string> &cipher = none, bool noninteractive = false) {
EXPECT_FALSE(file.exists());
return loader(password, noninteractive, cipher).loadOrCreate(file.path()).value();
return loader(password, noninteractive, cipher).loadOrCreate(file.path()).value().configFile;
}
optional<CryConfigFile> Load(const string &password = "mypassword", const optional<string> &cipher = none, bool noninteractive = false) {
EXPECT_TRUE(file.exists());
return loader(password, noninteractive, cipher).loadOrCreate(file.path());
auto loadResult = loader(password, noninteractive, cipher).loadOrCreate(file.path());
if (loadResult == none) {
return none;
}
return std::move(loadResult->configFile);
}
void CreateWithRootBlob(const string &rootBlob, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path()).value();
auto cfg = loader(password, false).loadOrCreate(file.path()).value().configFile;
cfg.config()->SetRootBlob(rootBlob);
cfg.save();
}
void CreateWithCipher(const string &cipher, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path()).value();
auto cfg = loader(password, false).loadOrCreate(file.path()).value().configFile;
cfg.config()->SetCipher(cipher);
cfg.save();
}
void CreateWithEncryptionKey(const string &encKey, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path()).value();
auto cfg = loader(password, false).loadOrCreate(file.path()).value().configFile;
cfg.config()->SetEncryptionKey(encKey);
cfg.save();
}
void CreateWithVersion(const string &version, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path()).value();
auto cfg = loader(password, false).loadOrCreate(file.path()).value().configFile;
cfg.config()->SetVersion(version);
cfg.config()->SetCreatedWithVersion(version);
cfg.save();
}
void CreateWithFilesystemID(const CryConfig::FilesystemID &filesystemId, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path()).value();
auto cfg = loader(password, false).loadOrCreate(file.path()).value().configFile;
cfg.config()->SetFilesystemId(filesystemId);
cfg.save();
}

View File

@ -40,7 +40,7 @@ public:
CryConfigFile loadOrCreateConfig() {
auto askPassword = [] {return "mypassword";};
return CryConfigLoader(mockConsole(), Random::PseudoRandom(), SCrypt::TestSettings, askPassword, askPassword, none, none, true).loadOrCreate(config.path()).value();
return CryConfigLoader(mockConsole(), Random::PseudoRandom(), SCrypt::TestSettings, askPassword, askPassword, none, none, true).loadOrCreate(config.path()).value().configFile;
}
unique_ref<OnDiskBlockStore> blockStore() {
@ -53,20 +53,20 @@ public:
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) {
{
CryDevice dev(loadOrCreateConfig(), blockStore());
CryDevice dev(loadOrCreateConfig(), blockStore(), 0x12345678);
}
CryDevice dev(loadOrCreateConfig(), blockStore());
CryDevice dev(loadOrCreateConfig(), blockStore(), 0x12345678);
auto root = dev.Load(bf::path("/"));
dynamic_pointer_move<CryDir>(root.get()).get()->children();
}
TEST_F(CryFsTest, LoadingFilesystemDoesntModifyConfigFile) {
{
CryDevice dev(loadOrCreateConfig(), blockStore());
CryDevice dev(loadOrCreateConfig(), blockStore(), 0x12345678);
}
Data configAfterCreating = Data::LoadFromFile(config.path()).value();
{
CryDevice dev(loadOrCreateConfig(), blockStore());
CryDevice dev(loadOrCreateConfig(), blockStore(), 0x12345678);
}
Data configAfterLoading = Data::LoadFromFile(config.path()).value();
EXPECT_EQ(configAfterCreating, configAfterLoading);

View File

@ -31,7 +31,7 @@ public:
auto askPassword = [] {return "mypassword";};
auto config = CryConfigLoader(mockConsole(), Random::PseudoRandom(), SCrypt::TestSettings, askPassword, askPassword, none, none, true)
.loadOrCreate(configFile.path()).value();
return make_unique_ref<CryDevice>(std::move(config), std::move(blockStore));
return make_unique_ref<CryDevice>(std::move(config.configFile), std::move(blockStore), config.myClientId);
}
cpputils::TempFile configFile;

View File

@ -11,7 +11,7 @@ class CryTestBase : public TestWithFakeHomeDirectory {
public:
CryTestBase(): _configFile(false), _device(nullptr) {
auto fakeBlockStore = cpputils::make_unique_ref<blockstore::testfake::FakeBlockStore>();
_device = std::make_unique<cryfs::CryDevice>(configFile(), std::move(fakeBlockStore));
_device = std::make_unique<cryfs::CryDevice>(configFile(), std::move(fakeBlockStore), 0x12345678);
}
cryfs::CryConfigFile configFile() {

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include "../../../src/cryfs/filesystem/MyClientId.h"
#include "cryfs/localstate/MyClientId.h"
#include <cpp-utils/tempfile/TempDir.h>
using cpputils::TempDir;