Offer a default configuration when creating new filesystems

This commit is contained in:
Sebastian Messmer 2016-01-25 14:33:40 +01:00
parent 33906947a8
commit af4ef5d425
5 changed files with 48 additions and 12 deletions

View File

@ -1,6 +1,7 @@
Version 0.8.5
---------------
* Fix package manager warning when installing the .deb package
* Offer a default configuration when creating new filesystems
Version 0.8.4
---------------
@ -10,15 +11,15 @@ Version 0.8.4
Version 0.8.3
---------------
* Ask for password confirmation when creating new filesystem.
* Ask for password confirmation when creating new filesystem
* Check for new CryFS versions and ask the user to update if a new version is available
* Implemented a mechanism that can show warnings about security bugs to users of a certain CryFS version. Let's hope this won't be necessary ;)
* Compatibility with GCC 4.8 (that allows compiling on Ubuntu 14.04 for example)
Version 0.8.2
---------------
* Mount directory, base directory, logfile and config file can be specified as relative paths.
* Improved error messages.
* Mount directory, base directory, logfile and config file can be specified as relative paths
* Improved error messages
Version 0.8.1
---------------

View File

@ -10,11 +10,21 @@ using std::vector;
using std::shared_ptr;
namespace cryfs {
constexpr const char *CryConfigConsole::DEFAULT_CIPHER;
CryConfigConsole::CryConfigConsole(shared_ptr<Console> console)
: _console(std::move(console)) {
: _console(std::move(console)), _useDefaultSettings(none) {
}
string CryConfigConsole::askCipher() const {
string CryConfigConsole::askCipher() {
if (_checkUseDefaultSettings()) {
return DEFAULT_CIPHER;
} else {
return _askCipher();
}
}
string CryConfigConsole::_askCipher() const {
vector<string> ciphers = CryCiphers::supportedCipherNames();
string cipherName = "";
bool askAgain = true;
@ -34,4 +44,11 @@ namespace cryfs {
}
return _console->askYesNo(string() + (*warning) + " Do you want to take this cipher nevertheless?");
}
bool CryConfigConsole::_checkUseDefaultSettings() {
if (_useDefaultSettings == none) {
_useDefaultSettings = _console->askYesNo("Use default settings?");
}
return *_useDefaultSettings;
}
}

View File

@ -12,14 +12,18 @@ namespace cryfs {
CryConfigConsole(std::shared_ptr<cpputils::Console> console);
CryConfigConsole(CryConfigConsole &&rhs) = default;
std::string askCipher() const;
std::string askCipher();
private:
static constexpr const char *DEFAULT_CIPHER = "aes-256-gcm";
private:
bool _checkUseDefaultSettings();
std::string _askCipher() const;
bool _showWarningForCipherAndReturnIfOk(const std::string &cipherName) const;
std::shared_ptr<cpputils::Console> _console;
boost::optional<bool> _useDefaultSettings;
DISALLOW_COPY_AND_ASSIGN(CryConfigConsole);
};

View File

@ -36,13 +36,22 @@ public:
class CryConfigConsoleTest_Cipher: public CryConfigConsoleTest {};
#define EXPECT_ASK_FOR_CIPHER() EXPECT_CALL(*console, ask(HasSubstr("block cipher"), UnorderedElementsAreArray(CryCiphers::supportedCipherNames())))
#define EXPECT_ASK_FOR_CIPHER() \
EXPECT_CALL(*console, askYesNo("Use default settings?")).Times(1).WillOnce(Return(false)); \
EXPECT_CALL(*console, ask(HasSubstr("block cipher"), UnorderedElementsAreArray(CryCiphers::supportedCipherNames()))).Times(1)
TEST_F(CryConfigConsoleTest_Cipher, AsksForCipher) {
EXPECT_ASK_FOR_CIPHER().Times(1).WillOnce(ChooseAnyCipher());
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseAnyCipher());
cryconsole.askCipher();
}
TEST_F(CryConfigConsoleTest_Cipher, ChooseDefaultCipher) {
EXPECT_CALL(*console, askYesNo("Use default settings?")).Times(1).WillOnce(Return(true));
EXPECT_CALL(*console, ask(HasSubstr("block cipher"), _)).Times(0);
string cipher = cryconsole.askCipher();
EXPECT_EQ(CryConfigConsole::DEFAULT_CIPHER, cipher);
}
class CryConfigConsoleTest_Cipher_Choose: public CryConfigConsoleTest_Cipher, public ::testing::WithParamInterface<string> {
public:
string cipherName = GetParam();

View File

@ -34,15 +34,20 @@ public:
CryConfigCreator creator;
};
#define EXPECT_ASK_FOR_CIPHER() EXPECT_CALL(*console, ask(HasSubstr("block cipher"), UnorderedElementsAreArray(CryCiphers::supportedCipherNames())))
#define EXPECT_ASK_FOR_CIPHER() \
EXPECT_CALL(*console, askYesNo("Use default settings?")).Times(1).WillOnce(Return(false)); \
EXPECT_CALL(*console, ask(HasSubstr("block cipher"), UnorderedElementsAreArray(CryCiphers::supportedCipherNames()))).Times(1)
#define EXPECT_DOES_NOT_ASK_FOR_CIPHER() \
EXPECT_CALL(*console, askYesNo("Use default settings?")).Times(0); \
EXPECT_CALL(*console, ask(HasSubstr("block cipher"), _)).Times(0);
TEST_F(CryConfigCreatorTest, DoesAskForCipherIfNotSpecified) {
EXPECT_ASK_FOR_CIPHER().Times(1).WillOnce(ChooseAnyCipher());
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseAnyCipher());
CryConfig config = creator.create(none);
}
TEST_F(CryConfigCreatorTest, DoesNotAskForCipherIfSpecified) {
EXPECT_ASK_FOR_CIPHER().Times(0);
EXPECT_DOES_NOT_ASK_FOR_CIPHER();
CryConfig config = creator.create(string("aes-256-gcm"));
}