From ff9c1bed5de380a6e7df1cbc6870b972d93b3dc4 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 22 May 2019 11:24:18 -0400 Subject: [PATCH] Save cipher-pass key/value missed in f492f057. This value is required when encryption is enabled. In passing simplify the expression used to skip the checksum when calculating the checksum. --- src/info/info.c | 11 ++++++++--- test/src/module/info/infoTest.c | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/info/info.c b/src/info/info.c index b0da95536..e9850606b 100644 --- a/src/info/info.c +++ b/src/info/info.c @@ -89,8 +89,7 @@ infoHash(const Ini *ini) String *key = strLstGet(keyList, keyIdx); // Skip the backrest checksum in the file - if ((strEq(section, INFO_SECTION_BACKREST_STR) && !strEq(key, INFO_KEY_CHECKSUM_STR)) || - !strEq(section, INFO_SECTION_BACKREST_STR)) + if (!strEq(section, INFO_SECTION_BACKREST_STR) || !strEq(key, INFO_KEY_CHECKSUM_STR)) { ioFilterProcessIn(hash, BUFSTRDEF("\"")); ioFilterProcessIn(hash, BUFSTR(key)); @@ -325,9 +324,15 @@ infoSave( MEM_CONTEXT_TEMP_BEGIN() { - // Add common info values + // Add version and format iniSet(ini, INFO_SECTION_BACKREST_STR, INFO_KEY_VERSION_STR, jsonFromStr(STRDEF(PROJECT_VERSION))); iniSet(ini, INFO_SECTION_BACKREST_STR, INFO_KEY_FORMAT_STR, jsonFromUInt(REPOSITORY_FORMAT)); + + // Add cipher passphrase if defined + if (this->cipherPass != NULL) + iniSet(ini, INFO_SECTION_CIPHER_STR, INFO_KEY_CIPHER_PASS_STR, jsonFromStr(this->cipherPass)); + + // Add checksum (this must be set after all other values or it will not be valid) iniSet(ini, INFO_SECTION_BACKREST_STR, INFO_KEY_CHECKSUM_STR, jsonFromStr(infoHash(ini))); // Save info file diff --git a/test/src/module/info/infoTest.c b/test/src/module/info/infoTest.c index 866b1753d..5f3a50430 100644 --- a/test/src/module/info/infoTest.c +++ b/test/src/module/info/infoTest.c @@ -264,10 +264,13 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- ini = iniNew(); iniSet(ini, strNew("section1"), strNew("key1"), strNew("value4")); - TEST_RESULT_VOID(infoSave(infoNew(), ini, storageTest, fileName, cipherTypeAes256Cbc, cipherPass), "save encrypted info"); + Info *info = infoNew(); + info->cipherPass = strNew("/badpass"); + TEST_RESULT_VOID(infoSave(info, ini, storageTest, fileName, cipherTypeAes256Cbc, cipherPass), "save encrypted info"); ini = NULL; TEST_RESULT_VOID(infoNewLoad(storageTest, fileName, cipherTypeAes256Cbc, cipherPass, &ini), " reload info"); TEST_RESULT_STR(strPtr(iniGet(ini, strNew("section1"), strNew("key1"))), "value4", " check ini"); + TEST_RESULT_STR(strPtr(iniGet(ini, strNew("cipher"), strNew("cipher-pass"))), "\"/badpass\"", " check cipher-pass"); } }