2015-10-29 10:47:14 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef MESSMER_CRYFS_CLI_H
|
|
|
|
#define MESSMER_CRYFS_CLI_H
|
|
|
|
|
|
|
|
#include "program_options/ProgramOptions.h"
|
2016-02-23 21:07:23 +01:00
|
|
|
#include <cryfs/config/CryConfigFile.h>
|
2015-10-29 10:47:14 +01:00
|
|
|
#include <boost/filesystem/path.hpp>
|
2016-02-11 16:39:42 +01:00
|
|
|
#include <cpp-utils/tempfile/TempFile.h>
|
|
|
|
#include <cpp-utils/io/Console.h>
|
|
|
|
#include <cpp-utils/random/RandomGenerator.h>
|
|
|
|
#include <cpp-utils/network/HttpClient.h>
|
2016-02-19 02:10:10 +01:00
|
|
|
#include <cryfs/filesystem/CryDevice.h>
|
2015-11-13 00:06:53 +01:00
|
|
|
#include "CallAfterTimeout.h"
|
2016-06-27 01:53:10 +02:00
|
|
|
#include <cryfs/config/CryConfigLoader.h>
|
2015-10-29 10:47:14 +01:00
|
|
|
|
|
|
|
namespace cryfs {
|
|
|
|
class Cli final {
|
|
|
|
public:
|
2017-09-30 19:53:03 +02:00
|
|
|
Cli(cpputils::RandomGenerator &keyGenerator, const cpputils::SCryptSettings &scryptSettings, std::shared_ptr<cpputils::Console> console);
|
|
|
|
int main(int argc, const char *argv[], cpputils::unique_ref<cpputils::HttpClient> httpClient);
|
2015-10-29 10:47:14 +01:00
|
|
|
|
|
|
|
private:
|
2017-09-30 19:53:03 +02:00
|
|
|
void _checkForUpdates(cpputils::unique_ref<cpputils::HttpClient> httpClient);
|
2015-11-03 21:22:35 +01:00
|
|
|
void _runFilesystem(const program_options::ProgramOptions &options);
|
2016-06-27 01:53:10 +02:00
|
|
|
CryConfigLoader::ConfigLoadResult _loadOrCreateConfig(const program_options::ProgramOptions &options);
|
2017-09-28 08:41:08 +02:00
|
|
|
void _checkConfigIntegrity(const boost::filesystem::path& basedir, const CryConfigFile& config);
|
2017-10-01 10:04:29 +02:00
|
|
|
boost::optional<CryConfigLoader::ConfigLoadResult> _loadOrCreateConfigFile(boost::filesystem::path configFilePath, const boost::optional<std::string> &cipher, const boost::optional<uint32_t> &blocksizeBytes, const boost::optional<bool> &missingBlockIsIntegrityViolation);
|
2015-11-03 21:22:35 +01:00
|
|
|
boost::filesystem::path _determineConfigFile(const program_options::ProgramOptions &options);
|
2015-11-19 10:08:09 +01:00
|
|
|
static std::string _askPasswordForExistingFilesystem();
|
|
|
|
static std::string _askPasswordForNewFilesystem();
|
2016-02-21 01:34:21 +01:00
|
|
|
static std::string _askPasswordNoninteractive();
|
2016-02-12 23:18:13 +01:00
|
|
|
static std::string _askPasswordFromStdin(const std::string &prompt);
|
2015-11-19 10:08:09 +01:00
|
|
|
static bool _confirmPassword(const std::string &password);
|
|
|
|
static bool _checkPassword(const std::string &password);
|
2017-09-30 19:53:03 +02:00
|
|
|
void _showVersion(cpputils::unique_ref<cpputils::HttpClient> httpClient);
|
2015-11-03 21:22:35 +01:00
|
|
|
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);
|
|
|
|
std::shared_ptr<cpputils::TempFile> _checkDirWriteable(const boost::filesystem::path &dir, const std::string &name);
|
|
|
|
void _checkDirReadable(const boost::filesystem::path &dir, std::shared_ptr<cpputils::TempFile> tempfile, const std::string &name);
|
2015-11-13 00:06:53 +01:00
|
|
|
boost::optional<cpputils::unique_ref<CallAfterTimeout>> _createIdleCallback(boost::optional<double> minutes, std::function<void()> callback);
|
2016-02-19 02:10:10 +01:00
|
|
|
void _sanityCheckFilesystem(CryDevice *device);
|
2015-11-03 21:22:35 +01:00
|
|
|
|
2016-02-21 01:34:21 +01:00
|
|
|
|
2015-11-03 21:22:35 +01:00
|
|
|
cpputils::RandomGenerator &_keyGenerator;
|
2015-11-04 05:27:00 +01:00
|
|
|
cpputils::SCryptSettings _scryptSettings;
|
2016-01-25 15:01:34 +01:00
|
|
|
std::shared_ptr<cpputils::Console> _console;
|
2016-02-21 01:34:21 +01:00
|
|
|
bool _noninteractive;
|
2015-11-27 14:06:17 +01:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Cli);
|
2015-10-29 10:47:14 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|