#pragma once #ifndef MESSMER_CRYFS_SRC_CONFIG_CRYCONFIGLOADER_H_ #define MESSMER_CRYFS_SRC_CONFIG_CRYCONFIGLOADER_H_ #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 { CryConfigFile configFile; uint32_t myClientId; }; boost::optional loadOrCreate(boost::filesystem::path filename, bool allowFilesystemUpgrade, bool allowReplacedFilesystem); private: boost::optional _loadConfig(boost::filesystem::path filename, bool allowFilesystemUpgrade, bool allowReplacedFilesystem); 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