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"
|
2016-02-11 16:39:42 +01:00
|
|
|
#include <cpp-utils/crypto/kdf/Scrypt.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:
|
2016-09-24 20:43:54 +02:00
|
|
|
CryConfigLoader(std::shared_ptr<cpputils::Console> console, cpputils::RandomGenerator &keyGenerator, const cpputils::SCryptSettings &scryptSettings, std::function<std::string()> askPasswordForExistingFilesystem, std::function<std::string()> askPasswordForNewFilesystem, 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;
|
|
|
|
};
|
|
|
|
|
2017-10-01 10:04:29 +02:00
|
|
|
boost::optional<ConfigLoadResult> loadOrCreate(boost::filesystem::path filename);
|
2015-07-26 13:09:55 +02:00
|
|
|
|
2015-06-16 18:20:31 +02:00
|
|
|
private:
|
2017-10-01 10:04:29 +02:00
|
|
|
boost::optional<ConfigLoadResult> _loadConfig(boost::filesystem::path filename);
|
|
|
|
ConfigLoadResult _createConfig(boost::filesystem::path filename);
|
2016-05-04 05:34:30 +02:00
|
|
|
void _checkVersion(const CryConfig &config);
|
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;
|
2015-11-04 05:27:00 +01:00
|
|
|
cpputils::SCryptSettings _scryptSettings;
|
2015-11-19 10:08:09 +01:00
|
|
|
std::function<std::string()> _askPasswordForExistingFilesystem;
|
|
|
|
std::function<std::string()> _askPasswordForNewFilesystem;
|
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;
|
2015-10-24 19:35:37 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CryConfigLoader);
|
2015-06-16 18:20:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|