#pragma once #ifndef MESSMER_CRYFS_SRC_CONFIG_CRYCONFIGLOADER_H_ #define MESSMER_CRYFS_SRC_CONFIG_CRYCONFIGLOADER_H_ #include #include #include #include "CryConfigFile.h" #include "CryCipher.h" #include "CryConfigCreator.h" #include "CryKeyProvider.h" namespace cryfs { class CryConfigLoader final { public: // note: keyGenerator generates the inner (i.e. file system) key. keyProvider asks for the password and generates the outer (i.e. config file) key. CryConfigLoader(std::shared_ptr console, cpputils::RandomGenerator &keyGenerator, cpputils::unique_ref keyProvider, LocalStateDir localStateDir, const boost::optional &cipherFromCommandLine, const boost::optional &blocksizeBytesFromCommandLine, const boost::optional &missingBlockIsIntegrityViolationFromCommandLine); 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; }; cpputils::either loadOrCreate(boost::filesystem::path filename, bool allowFilesystemUpgrade, bool allowReplacedFilesystem); cpputils::either load(boost::filesystem::path filename, bool allowFilesystemUpgrade, bool allowReplacedFilesystem, CryConfigFile::Access access); private: cpputils::either _loadConfig(boost::filesystem::path filename, bool allowFilesystemUpgrade, bool allowReplacedFilesystem, CryConfigFile::Access access); ConfigLoadResult _createConfig(boost::filesystem::path filename, bool allowReplacedFilesystem); void _checkVersion(const CryConfig &config, bool allowFilesystemUpgrade); void _checkCipher(const CryConfig &config) const; void _checkMissingBlocksAreIntegrityViolations(CryConfigFile *configFile, uint32_t myClientId); std::shared_ptr _console; CryConfigCreator _creator; cpputils::unique_ref _keyProvider; boost::optional _cipherFromCommandLine; boost::optional _blocksizeBytesFromCommandLine; boost::optional _missingBlockIsIntegrityViolationFromCommandLine; LocalStateDir _localStateDir; DISALLOW_COPY_AND_ASSIGN(CryConfigLoader); }; } #endif