CryConfigLoader asks for cipher to use when creating a new config

This commit is contained in:
Sebastian Messmer 2015-07-01 14:33:18 +02:00
parent 337d2c055b
commit 67c56648e3
4 changed files with 33 additions and 2 deletions

View File

@ -24,6 +24,7 @@ void CryConfig::load() {
_rootBlob = pt.get("cryfs.rootblob", "");
_encKey = pt.get("cryfs.key", "");
_cipher = pt.get("cryfs.cipher", "");
}
void CryConfig::save() const {
@ -31,6 +32,7 @@ void CryConfig::save() const {
pt.put("cryfs.rootblob", _rootBlob);
pt.put("cryfs.key", _encKey);
pt.put("cryfs.cipher", _cipher);
write_json(_configfile.native(), pt);
}
@ -51,6 +53,14 @@ void CryConfig::SetEncryptionKey(const std::string &value) {
_encKey = value;
}
const std::string &CryConfig::Cipher() const {
return _cipher;
};
void CryConfig::SetCipher(const std::string &value) {
_cipher = value;
}
CryConfig::~CryConfig() {
save();
}

View File

@ -19,6 +19,9 @@ public:
const std::string &EncryptionKey() const;
void SetEncryptionKey(const std::string &value);
const std::string &Cipher() const;
void SetCipher(const std::string &value);
void save() const;
private:
@ -28,6 +31,7 @@ private:
std::string _rootBlob;
std::string _encKey;
std::string _cipher;
DISALLOW_COPY_AND_ASSIGN(CryConfig);
};

View File

@ -1,11 +1,14 @@
#include "CryConfigLoader.h"
#include <boost/filesystem.hpp>
#include "utils/Console.h"
namespace bf = boost::filesystem;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
using boost::optional;
using boost::none;
using std::vector;
using std::string;
namespace cryfs {
@ -25,15 +28,27 @@ unique_ref<CryConfig> CryConfigLoader::createNew(const bf::path &filename) {
}
void CryConfigLoader::_initializeConfig(CryConfig *config) {
_generateCipher(config);
_generateEncKey(config);
_generateRootBlobKey(config);
}
void CryConfigLoader::_initializeConfigWithWeakKey(CryConfig *config) {
_generateTestCipher(config);
_generateWeakEncKey(config);
_generateRootBlobKey(config);
}
void CryConfigLoader::_generateCipher(CryConfig *config) {
vector<string> ciphers = {"aes-256-gcm", "aes-256-cfb"};
int cipherIndex = Console().ask("Which block cipher do you want to use?", ciphers);
config->SetCipher(ciphers[cipherIndex]);
}
void CryConfigLoader::_generateTestCipher(CryConfig *config) {
config->SetCipher("aes-256-gcm");
}
void CryConfigLoader::_generateEncKey(CryConfig *config) {
printf("Generating secure encryption key...");
fflush(stdout);

View File

@ -24,11 +24,13 @@ public:
private:
static void _initializeConfig(CryConfig *config);
static void _generateCipher(CryConfig *config);
static void _generateEncKey(CryConfig *config);
static void _generateRootBlobKey(CryConfig *config);
static void _initializeConfigWithWeakKey(CryConfig *config);
static void _generateWeakEncKey(CryConfig *config);
static void _initializeConfigWithWeakKey(CryConfig *config); // TODO Rename to _initializeConfigForTest
static void _generateWeakEncKey(CryConfig *config); // TODO Rename to _generateTestEncKey
static void _generateTestCipher(CryConfig *config);
};
}