Skip to content
Permalink
Browse files

Save cipher-pass key/value missed in f492f05.

This value is required when encryption is enabled.

In passing simplify the expression used to skip the checksum when calculating the checksum.
  • Loading branch information...
dwsteele committed May 22, 2019
1 parent 3da60f4 commit ff9c1bed5de380a6e7df1cbc6870b972d93b3dc4
Showing with 12 additions and 4 deletions.
  1. +8 −3 src/info/info.c
  2. +4 −1 test/src/module/info/infoTest.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
@@ -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");
}
}

0 comments on commit ff9c1be

Please sign in to comment.
You can’t perform that action at this time.