2015-06-16 18:20:31 +02:00
|
|
|
#pragma once
|
2015-10-15 13:06:51 +02:00
|
|
|
#ifndef MESSMER_CRYFS_SRC_CONFIG_CRYCONFIGLOADER_H_
|
|
|
|
#define MESSMER_CRYFS_SRC_CONFIG_CRYCONFIGLOADER_H_
|
2015-06-16 18:20:31 +02:00
|
|
|
|
2016-02-11 16:39:42 +01:00
|
|
|
#include <cpp-utils/pointer/unique_ref.h>
|
2015-10-27 13:28:42 +01:00
|
|
|
#include <boost/filesystem.hpp>
|
2015-10-19 02:46:47 +02:00
|
|
|
#include "CryConfigFile.h"
|
2015-09-01 00:25:14 +02:00
|
|
|
#include "CryCipher.h"
|
2015-10-19 02:46:47 +02:00
|
|
|
#include "CryConfigCreator.h"
|
2018-10-22 04:31:08 +02:00
|
|
|
#include "CryKeyProvider.h"
|
2015-06-16 18:20:31 +02:00
|
|
|
|
|
|
|
namespace cryfs {
|
|
|
|
|
2015-11-27 14:06:17 +01:00
|
|
|
class CryConfigLoader final {
|
2015-06-16 18:20:31 +02:00
|
|
|
public:
|
2018-10-22 04:31:08 +02:00
|
|
|
// 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<cpputils::Console> console, cpputils::RandomGenerator &keyGenerator, cpputils::unique_ref<CryKeyProvider> keyProvider, LocalStateDir localStateDir, const boost::optional<std::string> &cipherFromCommandLine, const boost::optional<uint32_t> &blocksizeBytesFromCommandLine, const boost::optional<bool> &missingBlockIsIntegrityViolationFromCommandLine);
|
2015-10-24 19:35:37 +02:00
|
|
|
CryConfigLoader(CryConfigLoader &&rhs) = default;
|
2015-06-16 18:20:31 +02:00
|
|
|
|
2016-06-27 01:53:10 +02:00
|
|
|
struct ConfigLoadResult {
|
|
|
|
CryConfigFile configFile;
|
|
|
|
uint32_t myClientId;
|
|
|
|
};
|
|
|
|
|
2018-02-03 17:33:59 +01:00
|
|
|
boost::optional<ConfigLoadResult> loadOrCreate(boost::filesystem::path filename, bool allowFilesystemUpgrade, bool allowReplacedFilesystem);
|
2018-11-10 21:38:57 +01:00
|
|
|
boost::optional<ConfigLoadResult> load(boost::filesystem::path filename, bool allowFilesystemUpgrade, bool allowReplacedFilesystem);
|
2015-07-26 13:09:55 +02:00
|
|
|
|
2015-06-16 18:20:31 +02:00
|
|
|
private:
|
2018-02-03 17:33:59 +01:00
|
|
|
boost::optional<ConfigLoadResult> _loadConfig(boost::filesystem::path filename, bool allowFilesystemUpgrade, bool allowReplacedFilesystem);
|
|
|
|
ConfigLoadResult _createConfig(boost::filesystem::path filename, bool allowReplacedFilesystem);
|
2018-02-01 11:04:59 +01:00
|
|
|
void _checkVersion(const CryConfig &config, bool allowFilesystemUpgrade);
|
2016-02-09 10:55:28 +01:00
|
|
|
void _checkCipher(const CryConfig &config) const;
|
2016-06-27 08:24:32 +02:00
|
|
|
void _checkMissingBlocksAreIntegrityViolations(CryConfigFile *configFile, uint32_t myClientId);
|
2015-10-24 19:35:37 +02:00
|
|
|
|
2016-05-04 05:34:30 +02:00
|
|
|
std::shared_ptr<cpputils::Console> _console;
|
2015-10-24 19:35:37 +02:00
|
|
|
CryConfigCreator _creator;
|
2018-10-22 04:31:08 +02:00
|
|
|
cpputils::unique_ref<CryKeyProvider> _keyProvider;
|
2016-01-17 14:57:40 +01:00
|
|
|
boost::optional<std::string> _cipherFromCommandLine;
|
2016-03-04 23:12:41 +01:00
|
|
|
boost::optional<uint32_t> _blocksizeBytesFromCommandLine;
|
2016-06-27 08:24:32 +02:00
|
|
|
boost::optional<bool> _missingBlockIsIntegrityViolationFromCommandLine;
|
2018-04-22 07:04:21 +02:00
|
|
|
LocalStateDir _localStateDir;
|
2015-10-24 19:35:37 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CryConfigLoader);
|
2015-06-16 18:20:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|