From b28b8b6ea8c287fbc417d3590283019a34a961df Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sat, 14 Aug 2021 10:34:41 -0700 Subject: [PATCH] Show old config values at mount time, otherwise they'd just always show the current version --- src/cryfs-cli/Cli.cpp | 31 +++++++++++++++-------- src/cryfs/impl/config/CryConfigLoader.cpp | 7 ++--- src/cryfs/impl/config/CryConfigLoader.h | 1 + 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/cryfs-cli/Cli.cpp b/src/cryfs-cli/Cli.cpp index c8a13016..990ffc6f 100644 --- a/src/cryfs-cli/Cli.cpp +++ b/src/cryfs-cli/Cli.cpp @@ -230,18 +230,29 @@ namespace cryfs_cli { } namespace { - void printConfig(const CryConfig& config) { + void printConfig(const CryConfig& oldConfig, const CryConfig& updatedConfig) { + auto printValue = [&] (const char* prefix, const char* suffix, auto member) { + std::cout << prefix; + auto oldConfigValue = member(oldConfig); + auto updatedConfigValue = member(updatedConfig); + if (oldConfigValue == updatedConfigValue) { + std::cout << oldConfigValue; + } else { + std::cout << oldConfigValue << " -> " << updatedConfigValue; + } + std::cout << suffix; + }; std::cout << "\n----------------------------------------------------" << "\nFilesystem configuration:" - << "\n----------------------------------------------------" - << "\n- Filesystem format version: " << config.Version() - << "\n- Created with: CryFS " << config.CreatedWithVersion() - << "\n- Last opened with: CryFS " << config.LastOpenedWithVersion() - << "\n- Cipher: " << config.Cipher() - << "\n- Blocksize: " << config.BlocksizeBytes() << " bytes" - << "\n- Filesystem Id: " << config.FilesystemId().ToString() - << "\n----------------------------------------------------\n"; + << "\n----------------------------------------------------"; + printValue("\n- Filesystem format version: ", "", [] (const CryConfig& config) {return config.Version(); }); + printValue("\n- Created with: CryFS ", "", [] (const CryConfig& config) { return config.CreatedWithVersion(); }); + printValue("\n- Last opened with: CryFS ", "", [] (const CryConfig& config) { return config.LastOpenedWithVersion(); }); + printValue("\n- Cipher: ", "", [] (const CryConfig& config) { return config.Cipher(); }); + printValue("\n- Blocksize: ", " bytes", [] (const CryConfig& config) { return config.BlocksizeBytes(); }); + printValue("\n- Filesystem Id: ", "", [] (const CryConfig& config) { return config.FilesystemId().ToString(); }); + std::cout << "\n----------------------------------------------------\n"; } } @@ -250,7 +261,7 @@ namespace cryfs_cli { LocalStateDir localStateDir(Environment::localStateDir()); auto blockStore = make_unique_ref(options.baseDir()); auto config = _loadOrCreateConfig(options, localStateDir); - printConfig(*config.configFile->config()); + printConfig(config.oldConfig, *config.configFile->config()); unique_ptr fuse = nullptr; bool stoppedBecauseOfIntegrityViolation = false; diff --git a/src/cryfs/impl/config/CryConfigLoader.cpp b/src/cryfs/impl/config/CryConfigLoader.cpp index 32fd2551..c1982582 100644 --- a/src/cryfs/impl/config/CryConfigLoader.cpp +++ b/src/cryfs/impl/config/CryConfigLoader.cpp @@ -37,6 +37,7 @@ either CryConfigLoa if (config.is_left()) { return config.left(); } + auto oldConfig = *config.right()->config(); #ifndef CRYFS_NO_COMPATIBILITY //Since 0.9.7 and 0.9.8 set their own version to cryfs.version instead of the filesystem format version (which is 0.9.6), overwrite it if (config.right()->config()->Version() == "0.9.7" || config.right()->config()->Version() == "0.9.8") { @@ -60,7 +61,7 @@ either CryConfigLoa auto localState = LocalStateMetadata::loadOrGenerate(_localStateDir.forFilesystemId(config.right()->config()->FilesystemId()), cpputils::Data::FromString(config.right()->config()->EncryptionKey()), allowReplacedFilesystem); uint32_t myClientId = localState.myClientId(); _checkMissingBlocksAreIntegrityViolations(config.right().get(), myClientId); - return ConfigLoadResult {std::move(config.right()), myClientId}; + return ConfigLoadResult {std::move(oldConfig), std::move(config.right()), myClientId}; } void CryConfigLoader::_checkVersion(const CryConfig &config, bool allowFilesystemUpgrade) { @@ -118,8 +119,8 @@ either CryConfigLoa CryConfigLoader::ConfigLoadResult CryConfigLoader::_createConfig(bf::path filename, bool allowReplacedFilesystem) { auto config = _creator.create(_cipherFromCommandLine, _blocksizeBytesFromCommandLine, _missingBlockIsIntegrityViolationFromCommandLine, allowReplacedFilesystem); - auto result = CryConfigFile::create(std::move(filename), std::move(config.config), _keyProvider.get()); - return ConfigLoadResult {std::move(result), config.myClientId}; + auto result = CryConfigFile::create(std::move(filename), config.config, _keyProvider.get()); + return ConfigLoadResult {std::move(config.config), std::move(result), config.myClientId}; } diff --git a/src/cryfs/impl/config/CryConfigLoader.h b/src/cryfs/impl/config/CryConfigLoader.h index fb26efb9..5171cf1a 100644 --- a/src/cryfs/impl/config/CryConfigLoader.h +++ b/src/cryfs/impl/config/CryConfigLoader.h @@ -19,6 +19,7 @@ public: CryConfigLoader(CryConfigLoader &&rhs) = default; struct ConfigLoadResult { + CryConfig oldConfig; // loading a config file updates the config file, but this member keeps the original config cpputils::unique_ref configFile; uint32_t myClientId; };