#pragma once #ifndef MESSMER_CRYFS_CLI_H #define MESSMER_CRYFS_CLI_H #include "program_options/ProgramOptions.h" #include #include #include #include #include #include #include #include "CallAfterTimeout.h" #include #include namespace cryfs { class Cli final { public: Cli(cpputils::RandomGenerator &keyGenerator, const cpputils::SCryptSettings &scryptSettings, std::shared_ptr console); int main(int argc, const char *argv[], cpputils::unique_ref httpClient); private: void _checkForUpdates(cpputils::unique_ref httpClient); void _runFilesystem(const program_options::ProgramOptions &options); CryConfigLoader::ConfigLoadResult _loadOrCreateConfig(const program_options::ProgramOptions &options, const LocalStateDir& localStateDir); void _checkConfigIntegrity(const boost::filesystem::path& basedir, const LocalStateDir& localStateDir, const CryConfigFile& config, bool allowReplacedFilesystem); boost::optional _loadOrCreateConfigFile(boost::filesystem::path configFilePath, LocalStateDir localStateDir, const boost::optional &cipher, const boost::optional &blocksizeBytes, bool allowFilesystemUpgrade, const boost::optional &missingBlockIsIntegrityViolation, bool allowReplacedFilesystem); boost::filesystem::path _determineConfigFile(const program_options::ProgramOptions &options); static std::function _askPasswordForExistingFilesystem(std::shared_ptr console); static std::function _askPasswordForNewFilesystem(std::shared_ptr console); static std::function _askPasswordNoninteractive(std::shared_ptr console); static bool _confirmPassword(cpputils::Console* console, const std::string &password); static bool _checkPassword(const std::string &password); void _showVersion(cpputils::unique_ref httpClient); void _initLogfile(const program_options::ProgramOptions &options); void _sanityChecks(const program_options::ProgramOptions &options); void _checkMountdirDoesntContainBasedir(const program_options::ProgramOptions &options); bool _pathContains(const boost::filesystem::path &parent, const boost::filesystem::path &child); void _checkDirAccessible(const boost::filesystem::path &dir, const std::string &name, ErrorCode errorCode); std::shared_ptr _checkDirWriteable(const boost::filesystem::path &dir, const std::string &name, ErrorCode errorCode); void _checkDirReadable(const boost::filesystem::path &dir, std::shared_ptr tempfile, const std::string &name, ErrorCode errorCode); boost::optional> _createIdleCallback(boost::optional minutes, std::function callback); void _sanityCheckFilesystem(CryDevice *device); cpputils::RandomGenerator &_keyGenerator; cpputils::SCryptSettings _scryptSettings; std::shared_ptr _console; bool _noninteractive; DISALLOW_COPY_AND_ASSIGN(Cli); }; } #endif