CryConfigLoader asks for cipher to use when creating a new config
This commit is contained in:
parent
337d2c055b
commit
67c56648e3
@ -24,6 +24,7 @@ void CryConfig::load() {
|
|||||||
|
|
||||||
_rootBlob = pt.get("cryfs.rootblob", "");
|
_rootBlob = pt.get("cryfs.rootblob", "");
|
||||||
_encKey = pt.get("cryfs.key", "");
|
_encKey = pt.get("cryfs.key", "");
|
||||||
|
_cipher = pt.get("cryfs.cipher", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryConfig::save() const {
|
void CryConfig::save() const {
|
||||||
@ -31,6 +32,7 @@ void CryConfig::save() const {
|
|||||||
|
|
||||||
pt.put("cryfs.rootblob", _rootBlob);
|
pt.put("cryfs.rootblob", _rootBlob);
|
||||||
pt.put("cryfs.key", _encKey);
|
pt.put("cryfs.key", _encKey);
|
||||||
|
pt.put("cryfs.cipher", _cipher);
|
||||||
|
|
||||||
write_json(_configfile.native(), pt);
|
write_json(_configfile.native(), pt);
|
||||||
}
|
}
|
||||||
@ -51,6 +53,14 @@ void CryConfig::SetEncryptionKey(const std::string &value) {
|
|||||||
_encKey = value;
|
_encKey = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string &CryConfig::Cipher() const {
|
||||||
|
return _cipher;
|
||||||
|
};
|
||||||
|
|
||||||
|
void CryConfig::SetCipher(const std::string &value) {
|
||||||
|
_cipher = value;
|
||||||
|
}
|
||||||
|
|
||||||
CryConfig::~CryConfig() {
|
CryConfig::~CryConfig() {
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,9 @@ public:
|
|||||||
const std::string &EncryptionKey() const;
|
const std::string &EncryptionKey() const;
|
||||||
void SetEncryptionKey(const std::string &value);
|
void SetEncryptionKey(const std::string &value);
|
||||||
|
|
||||||
|
const std::string &Cipher() const;
|
||||||
|
void SetCipher(const std::string &value);
|
||||||
|
|
||||||
void save() const;
|
void save() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -28,6 +31,7 @@ private:
|
|||||||
|
|
||||||
std::string _rootBlob;
|
std::string _rootBlob;
|
||||||
std::string _encKey;
|
std::string _encKey;
|
||||||
|
std::string _cipher;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CryConfig);
|
DISALLOW_COPY_AND_ASSIGN(CryConfig);
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
#include "CryConfigLoader.h"
|
#include "CryConfigLoader.h"
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include "utils/Console.h"
|
||||||
|
|
||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
using cpputils::unique_ref;
|
using cpputils::unique_ref;
|
||||||
using cpputils::make_unique_ref;
|
using cpputils::make_unique_ref;
|
||||||
using boost::optional;
|
using boost::optional;
|
||||||
using boost::none;
|
using boost::none;
|
||||||
|
using std::vector;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
@ -25,15 +28,27 @@ unique_ref<CryConfig> CryConfigLoader::createNew(const bf::path &filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CryConfigLoader::_initializeConfig(CryConfig *config) {
|
void CryConfigLoader::_initializeConfig(CryConfig *config) {
|
||||||
|
_generateCipher(config);
|
||||||
_generateEncKey(config);
|
_generateEncKey(config);
|
||||||
_generateRootBlobKey(config);
|
_generateRootBlobKey(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryConfigLoader::_initializeConfigWithWeakKey(CryConfig *config) {
|
void CryConfigLoader::_initializeConfigWithWeakKey(CryConfig *config) {
|
||||||
|
_generateTestCipher(config);
|
||||||
_generateWeakEncKey(config);
|
_generateWeakEncKey(config);
|
||||||
_generateRootBlobKey(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) {
|
void CryConfigLoader::_generateEncKey(CryConfig *config) {
|
||||||
printf("Generating secure encryption key...");
|
printf("Generating secure encryption key...");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -24,11 +24,13 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static void _initializeConfig(CryConfig *config);
|
static void _initializeConfig(CryConfig *config);
|
||||||
|
static void _generateCipher(CryConfig *config);
|
||||||
static void _generateEncKey(CryConfig *config);
|
static void _generateEncKey(CryConfig *config);
|
||||||
static void _generateRootBlobKey(CryConfig *config);
|
static void _generateRootBlobKey(CryConfig *config);
|
||||||
|
|
||||||
static void _initializeConfigWithWeakKey(CryConfig *config);
|
static void _initializeConfigWithWeakKey(CryConfig *config); // TODO Rename to _initializeConfigForTest
|
||||||
static void _generateWeakEncKey(CryConfig *config);
|
static void _generateWeakEncKey(CryConfig *config); // TODO Rename to _generateTestEncKey
|
||||||
|
static void _generateTestCipher(CryConfig *config);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user