1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +02:00

Update CipherType/CipherMode to StringId.

As in 6cc521b, this allows option values and enums to be easily mapped together.
This commit is contained in:
David Steele
2021-04-28 11:36:20 -04:00
committed by GitHub
parent c3b15fc3bd
commit 85fc3da4c3
36 changed files with 128 additions and 189 deletions

View File

@ -90,12 +90,15 @@
<commit subject="Update storage module to use StringIds.">
<github-pull-request id="1379"/>
</commit>
<commit subject="Update CipherType/CipherMode to StringId.">
<github-pull-request id="1384"/>
</commit>
<release-item-contributor-list>
<release-item-reviewer id="cynthia.shang"/>
</release-item-contributor-list>
<p>Add StringId type.</p>
<p>Add <code>StringId</code> type.</p>
</release-item>
<release-item>

View File

@ -390,7 +390,7 @@ archiveGetCheck(const StringList *archiveRequestList)
ArchiveGetFindCacheRepo cacheRepo =
{
.repoIdx = repoIdx,
.cipherType = cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
.cipherType = cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
.archiveList = lstNewP(sizeof(ArchiveGetFindCacheArchive)),
.warnList = strLstNew(),
};
@ -839,7 +839,7 @@ static ProtocolParallelJob *archiveGetAsyncCallback(void *data, unsigned int cli
protocolCommandParamAdd(command, VARSTR(actual->file));
protocolCommandParamAdd(command, VARUINT(actual->repoIdx));
protocolCommandParamAdd(command, VARSTR(actual->archiveId));
protocolCommandParamAdd(command, VARUINT(actual->cipherType));
protocolCommandParamAdd(command, VARUINT64(actual->cipherType));
protocolCommandParamAdd(command, VARSTR(actual->cipherPassArchive));
}

View File

@ -48,7 +48,7 @@ archiveGetFileProtocol(const VariantList *paramList, ProtocolServer *server)
.file = varStr(varLstGet(paramList, paramFixed + (actualIdx * paramActual))),
.repoIdx = varUIntForce(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 1)),
.archiveId = varStr(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 2)),
.cipherType = (CipherType)varUIntForce(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 3)),
.cipherType = varUInt64(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 3)),
.cipherPassArchive = varStr(varLstGet(paramList, paramFixed + (actualIdx * paramActual) + 4)),
});
}

View File

@ -39,7 +39,7 @@ archivePushFileProtocol(const VariantList *paramList, ProtocolServer *server)
{
.repoIdx = varUIntForce(varLstGet(paramList, paramIdx)),
.archiveId = varStr(varLstGet(paramList, paramIdx + 1)),
.cipherType = (CipherType)varUIntForce(varLstGet(paramList, paramIdx + 2)),
.cipherType = varUInt64(varLstGet(paramList, paramIdx + 2)),
.cipherPass = varStr(varLstGet(paramList, paramIdx + 3)),
});

View File

@ -229,7 +229,7 @@ archivePushCheck(bool pgPathSet)
storageRepoIdx(repoIdx);
// Get cipher type
CipherType repoCipherType = cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx));
CipherType repoCipherType = cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx);
// Attempt to load the archive info file
InfoArchive *info = infoArchiveLoadFile(
@ -478,7 +478,7 @@ archivePushAsyncCallback(void *data, unsigned int clientIdx)
protocolCommandParamAdd(command, VARUINT(data->repoIdx));
protocolCommandParamAdd(command, VARSTR(data->archiveId));
protocolCommandParamAdd(command, VARUINT(data->cipherType));
protocolCommandParamAdd(command, VARUINT64(data->cipherType));
protocolCommandParamAdd(command, VARSTR(data->cipherPass));
}

View File

@ -397,7 +397,7 @@ backupBuildIncrPrior(const InfoBackup *infoBackup)
{
result = manifestLoadFile(
storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabelPrior)),
cipherType(cfgOptionStr(cfgOptRepoCipherType)), infoPgCipherPass(infoBackupPg(infoBackup)));
cfgOptionStrId(cfgOptRepoCipherType), infoPgCipherPass(infoBackupPg(infoBackup)));
const ManifestData *manifestPriorData = manifestData(result);
LOG_INFO_FMT(
@ -707,7 +707,7 @@ backupResumeFind(const Manifest *manifest, const String *cipherPassBackup)
TRY_BEGIN()
{
manifestResume = manifestLoadFile(
storageRepo(), manifestFile, cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherPassBackup);
storageRepo(), manifestFile, cfgOptionStrId(cfgOptRepoCipherType), cipherPassBackup);
const ManifestData *manifestResumeData = manifestData(manifestResume);
// Check pgBackRest version. This allows the resume implementation to be changed with each version of
@ -961,7 +961,7 @@ backupFilePut(BackupData *backupData, Manifest *manifest, const String *name, ti
// Add encryption filter if required
cipherBlockFilterGroupAdd(
filterGroup, cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeEncrypt, manifestCipherSubPass(manifest));
filterGroup, cfgOptionStrId(cfgOptRepoCipherType), cipherModeEncrypt, manifestCipherSubPass(manifest));
// Add size filter last to calculate repo size
ioFilterGroupAdd(filterGroup, ioSizeNew());
@ -1251,7 +1251,7 @@ backupManifestSaveCopy(Manifest *const manifest, const String *cipherPassBackup)
// Add encryption filter if required
cipherBlockFilterGroupAdd(
ioWriteFilterGroup(write), cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeEncrypt, cipherPassBackup);
ioWriteFilterGroup(write), cfgOptionStrId(cfgOptRepoCipherType), cipherModeEncrypt, cipherPassBackup);
// Save file
manifestSave(manifest, write);
@ -1492,7 +1492,7 @@ static ProtocolParallelJob *backupJobCallback(void *data, unsigned int clientIdx
protocolCommandParamAdd(command, VARINT(jobData->compressLevel));
protocolCommandParamAdd(command, VARSTR(jobData->backupLabel));
protocolCommandParamAdd(command, VARBOOL(jobData->delta));
protocolCommandParamAdd(command, VARUINT(jobData->cipherType));
protocolCommandParamAdd(command, VARUINT64(jobData->cipherType));
protocolCommandParamAdd(command, VARSTR(jobData->cipherSubPass));
// Remove job from the queue
@ -1583,7 +1583,7 @@ backupProcess(BackupData *backupData, Manifest *manifest, const String *lsnStart
.backupStandby = backupStandby,
.compressType = compressTypeEnum(cfgOptionStr(cfgOptCompressType)),
.compressLevel = cfgOptionInt(cfgOptCompressLevel),
.cipherType = cipherType(cfgOptionStr(cfgOptRepoCipherType)),
.cipherType = cfgOptionStrId(cfgOptRepoCipherType),
.cipherSubPass = manifestCipherSubPass(manifest),
.delta = cfgOptionBool(cfgOptDelta),
.lsnStart = cfgOptionBool(cfgOptOnline) ? pgLsnFromStr(lsnStart) : 0xFFFFFFFFFFFFFFFF,
@ -1755,7 +1755,7 @@ backupArchiveCheckCopy(Manifest *manifest, unsigned int walSegmentSize, const St
// Loop through all the segments in the lsn range
InfoArchive *infoArchive = infoArchiveLoadFile(
storageRepo(), INFO_ARCHIVE_PATH_FILE_STR, cipherType(cfgOptionStr(cfgOptRepoCipherType)),
storageRepo(), INFO_ARCHIVE_PATH_FILE_STR, cfgOptionStrId(cfgOptRepoCipherType),
cfgOptionStrNull(cfgOptRepoCipherPass));
const String *archiveId = infoArchiveId(infoArchive);
@ -1788,7 +1788,7 @@ backupArchiveCheckCopy(Manifest *manifest, unsigned int walSegmentSize, const St
// Decrypt with archive key if encrypted
cipherBlockFilterGroupAdd(
filterGroup, cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeDecrypt,
filterGroup, cfgOptionStrId(cfgOptRepoCipherType), cipherModeDecrypt,
infoArchiveCipherPass(infoArchive));
// Compress/decompress if archive and backup do not have the same compression settings
@ -1806,8 +1806,7 @@ backupArchiveCheckCopy(Manifest *manifest, unsigned int walSegmentSize, const St
// Encrypt with backup key if encrypted
cipherBlockFilterGroupAdd(
filterGroup, cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeEncrypt,
manifestCipherSubPass(manifest));
filterGroup, cfgOptionStrId(cfgOptRepoCipherType), cipherModeEncrypt, manifestCipherSubPass(manifest));
// Add size filter last to calculate repo size
ioFilterGroupAdd(filterGroup, ioSizeNew());
@ -1891,7 +1890,7 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest)
storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel)));
cipherBlockFilterGroupAdd(
ioReadFilterGroup(storageReadIo(manifestRead)), cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeDecrypt,
ioReadFilterGroup(storageReadIo(manifestRead)), cfgOptionStrId(cfgOptRepoCipherType), cipherModeDecrypt,
infoPgCipherPass(infoBackupPg(infoBackup)));
StorageWrite *manifestWrite = storageNewWriteP(
@ -1903,7 +1902,7 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest)
ioFilterGroupAdd(ioWriteFilterGroup(storageWriteIo(manifestWrite)), compressFilter(compressTypeGz, 9));
cipherBlockFilterGroupAdd(
ioWriteFilterGroup(storageWriteIo(manifestWrite)), cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeEncrypt,
ioWriteFilterGroup(storageWriteIo(manifestWrite)), cfgOptionStrId(cfgOptRepoCipherType), cipherModeEncrypt,
infoPgCipherPass(infoBackupPg(infoBackup)));
storageCopyP(manifestRead, manifestWrite);
@ -1922,7 +1921,7 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest)
infoBackupDataAdd(infoBackup, manifest);
infoBackupSaveFile(
infoBackup, storageRepoWrite(), INFO_BACKUP_PATH_FILE_STR, cipherType(cfgOptionStr(cfgOptRepoCipherType)),
infoBackup, storageRepoWrite(), INFO_BACKUP_PATH_FILE_STR, cfgOptionStrId(cfgOptRepoCipherType),
cfgOptionStrNull(cfgOptRepoCipherPass));
}
MEM_CONTEXT_TEMP_END();
@ -1954,8 +1953,7 @@ cmdBackup(void)
// Load backup.info
InfoBackup *infoBackup = infoBackupLoadFileReconstruct(
storageRepo(), INFO_BACKUP_PATH_FILE_STR, cipherType(cfgOptionStr(cfgOptRepoCipherType)),
cfgOptionStrNull(cfgOptRepoCipherPass));
storageRepo(), INFO_BACKUP_PATH_FILE_STR, cfgOptionStrId(cfgOptRepoCipherType), cfgOptionStrNull(cfgOptRepoCipherPass));
InfoPgData infoPg = infoPgDataCurrent(infoBackupPg(infoBackup));
const String *cipherPassBackup = infoPgCipherPass(infoBackupPg(infoBackup));
@ -1982,7 +1980,7 @@ cmdBackup(void)
// Build an incremental backup if type is not full (manifestPrior will be freed in this call)
if (!backupBuildIncr(infoBackup, manifest, manifestPrior, backupStartResult.walSegmentName))
manifestCipherSubPassSet(manifest, cipherPassGen(cipherType(cfgOptionStr(cfgOptRepoCipherType))));
manifestCipherSubPassSet(manifest, cipherPassGen(cfgOptionStrId(cfgOptRepoCipherType)));
// Set delta if it is not already set and the manifest requires it
if (!cfgOptionBool(cfgOptDelta) && varBool(manifestData(manifest)->backupOptionDelta))

View File

@ -55,7 +55,7 @@ backupFile(
FUNCTION_LOG_PARAM(INT, repoFileCompressLevel); // Compression level for repo file
FUNCTION_LOG_PARAM(STRING, backupLabel); // Label of current backup
FUNCTION_LOG_PARAM(BOOL, delta); // Is the delta option on?
FUNCTION_LOG_PARAM(ENUM, cipherType); // Encryption type
FUNCTION_LOG_PARAM(STRING_ID, cipherType); // Encryption type
FUNCTION_TEST_PARAM(STRING, cipherPass); // Password to access the repo file if encrypted
FUNCTION_LOG_END();

View File

@ -32,8 +32,8 @@ backupFileProtocol(const VariantList *paramList, ProtocolServer *server)
varBool(varLstGet(paramList, 3)), varStr(varLstGet(paramList, 4)), varBool(varLstGet(paramList, 5)),
varUInt64(varLstGet(paramList, 6)), varStr(varLstGet(paramList, 7)), varBool(varLstGet(paramList, 8)),
(CompressType)varUIntForce(varLstGet(paramList, 9)), varIntForce(varLstGet(paramList, 10)),
varStr(varLstGet(paramList, 11)), varBool(varLstGet(paramList, 12)),
(CipherType)varUIntForce(varLstGet(paramList, 13)), varStr(varLstGet(paramList, 14)));
varStr(varLstGet(paramList, 11)), varBool(varLstGet(paramList, 12)), varUInt64(varLstGet(paramList, 13)),
varStr(varLstGet(paramList, 14)));
// Return backup result
VariantList *resultList = varLstNew();

View File

@ -88,7 +88,7 @@ checkStandby(const DbGetResult dbGroup, unsigned int pgPathDefinedTotal)
// Check that the backup and archive info files exist and are valid for the current database of the stanza
checkStanzaInfoPg(
storageRepo, pgControl.version, pgControl.systemId, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepo, pgControl.version, pgControl.systemId, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
}
@ -134,12 +134,12 @@ checkPrimary(const DbGetResult dbGroup)
// Check that the backup and archive info files exist and are valid for the current database of the stanza
checkStanzaInfoPg(
storageRepo, pgControl.version, pgControl.systemId, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepo, pgControl.version, pgControl.systemId, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
// Attempt to load the archive info file and retrieve the archiveId
InfoArchive *archiveInfo = infoArchiveLoadFile(
storageRepo, INFO_ARCHIVE_PATH_FILE_STR, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepo, INFO_ARCHIVE_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
repoArchiveId[repoIdx] = infoArchiveId(archiveInfo);

View File

@ -131,7 +131,7 @@ checkStanzaInfoPg(
FUNCTION_LOG_PARAM(STORAGE, storage);
FUNCTION_LOG_PARAM(UINT, pgVersion);
FUNCTION_LOG_PARAM(UINT64, pgSystemId);
FUNCTION_LOG_PARAM(ENUM, cipherType);
FUNCTION_LOG_PARAM(STRING_ID, cipherType);
FUNCTION_TEST_PARAM(STRING, cipherPass);
FUNCTION_TEST_END();

View File

@ -429,7 +429,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
{
// Attempt to load the archive info file
InfoArchive *infoArchive = infoArchiveLoadFile(
storageRepoIdx(repoIdx), INFO_ARCHIVE_PATH_FILE_STR, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepoIdx(repoIdx), INFO_ARCHIVE_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
InfoPg *infoArchivePgData = infoArchivePg(infoArchive);
@ -828,7 +828,7 @@ removeExpiredBackup(InfoBackup *infoBackup, const String *adhocBackupLabel, unsi
else
{
Manifest *manifestResume = manifestLoadFile(
storageRepoIdx(repoIdx), manifestFileName, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepoIdx(repoIdx), manifestFileName, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
infoPgCipherPass(infoBackupPg(infoBackup)));
// If the ancestor of the resumable backup still exists in backup.info then do not remove the resumable backup
@ -915,7 +915,7 @@ cmdExpire(void)
{
// Load the backup.info
infoBackup = infoBackupLoadFileReconstruct(
storageRepo, INFO_BACKUP_PATH_FILE_STR, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepo, INFO_BACKUP_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
// If a backupLabel was set, then attempt to expire the requested backup
@ -960,8 +960,7 @@ cmdExpire(void)
{
infoBackupSaveFile(
infoBackup, storageRepoIdxWrite(repoIdx), INFO_BACKUP_PATH_FILE_STR,
cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
}
// Remove all files on disk that are now expired

View File

@ -106,7 +106,7 @@ Data types and structures
typedef struct InfoRepoData
{
unsigned int key; // User-defined repo key
CipherType cipher; // Encryption type (0 = none)
CipherType cipher; // Encryption type
const String *cipherPass; // Passphrase if the repo is encrypted (else NULL)
int stanzaStatus; // Status code of the the stanza on this repo
unsigned int backupIdx; // Index of the next backup that may be a candidate for sorting
@ -640,7 +640,7 @@ stanzaInfoList(List *stanzaRepoList, const String *backupLabel, unsigned int rep
VariantList *repoSection = varLstNew();
int stanzaStatusCode = -1;
unsigned int stanzaCipherType = 0;
uint64_t stanzaCipherType = cipherTypeNone;
// Set the stanza name and initialize the overall stanza variables
kvPut(varKv(stanzaInfo), KEY_NAME_VAR, VARSTR(stanzaData->name));
@ -652,7 +652,7 @@ stanzaInfoList(List *stanzaRepoList, const String *backupLabel, unsigned int rep
Variant *repoInfo = varNewKv(kvNew());
kvPut(varKv(repoInfo), REPO_KEY_KEY_VAR, VARUINT(repoData->key));
kvPut(varKv(repoInfo), KEY_CIPHER_VAR, VARSTR(cipherTypeName(repoData->cipher)));
kvPut(varKv(repoInfo), KEY_CIPHER_VAR, VARSTR(strIdToStr(repoData->cipher)));
// If the stanza on this repo has the default status of ok but the backupInfo was not read, then the stanza exists on
// other repos but not this one
@ -745,7 +745,7 @@ stanzaInfoList(List *stanzaRepoList, const String *backupLabel, unsigned int rep
// Set the overall cipher type
if (stanzaCipherType != INFO_STANZA_STATUS_CODE_MIXED)
kvPut(varKv(stanzaInfo), KEY_CIPHER_VAR, VARSTR(cipherTypeName(stanzaCipherType)));
kvPut(varKv(stanzaInfo), KEY_CIPHER_VAR, VARSTR(strIdToStr(stanzaCipherType)));
else
kvPut(varKv(stanzaInfo), KEY_CIPHER_VAR, VARSTRDEF(INFO_STANZA_MIXED));
@ -1232,7 +1232,7 @@ infoRender(void)
repoErrorList[repoIdx] = (InfoRepoData)
{
.key = cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx),
.cipher = cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
.cipher = cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
.cipherPass = cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx),
.error = NULL,
};
@ -1304,7 +1304,7 @@ infoRender(void)
stanzaRepo.repoList[repoListIdx] = (InfoRepoData)
{
.key = cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoListIdx),
.cipher = cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoListIdx)),
.cipher = cfgOptionIdxStrId(cfgOptRepoCipherType, repoListIdx),
.cipherPass = cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoListIdx),
.error = NULL,
};

View File

@ -61,7 +61,7 @@ storageGetProcess(IoWrite *destination)
// Add decryption if needed
if (!cfgOptionBool(cfgOptRaw))
{
CipherType repoCipherType = cipherType(cfgOptionStr(cfgOptRepoCipherType));
CipherType repoCipherType = cfgOptionStrId(cfgOptRepoCipherType);
if (repoCipherType != cipherTypeNone)
{

View File

@ -39,7 +39,7 @@ storagePutProcess(IoRead *source)
// Add encryption if needed
if (!cfgOptionBool(cfgOptRaw))
{
CipherType repoCipherType = cipherType(cfgOptionStr(cfgOptRepoCipherType));
CipherType repoCipherType = cfgOptionStrId(cfgOptRepoCipherType);
if (repoCipherType != cipherTypeNone)
{

View File

@ -232,7 +232,7 @@ restoreBackupData(const String *backupLabel, unsigned int repoIdx, const String
{
restoreBackup.backupSet = strDup(backupLabel);
restoreBackup.repoIdx = repoIdx;
restoreBackup.repoCipherType = cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx));
restoreBackup.repoCipherType = cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx);
restoreBackup.backupCipherPass = strDup(backupCipherPass);
}
MEM_CONTEXT_PRIOR_END();
@ -288,7 +288,7 @@ restoreBackupSet(void)
TRY_BEGIN()
{
infoBackup = infoBackupLoadFile(
storageRepoIdx(repoIdx), INFO_BACKUP_PATH_FILE_STR, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepoIdx(repoIdx), INFO_BACKUP_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
}
CATCH_ANY()

View File

@ -73,24 +73,24 @@ cmdStanzaCreate(void)
}
// If the repo is encrypted, generate a cipher passphrase for encrypting subsequent archive files
String *cipherPassSub = cipherPassGen(cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)));
String *cipherPassSub = cipherPassGen(cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx));
// Create and save archive info
infoArchive = infoArchiveNew(pgControl.version, pgControl.systemId, cipherPassSub);
infoArchiveSaveFile(
infoArchive, storageRepoWriteStanza, INFO_ARCHIVE_PATH_FILE_STR,
cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
// If the repo is encrypted, generate a cipher passphrase for encrypting subsequent backup files
cipherPassSub = cipherPassGen(cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)));
cipherPassSub = cipherPassGen(cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx));
// Create and save backup info
infoBackup = infoBackupNew(pgControl.version, pgControl.systemId, pgControl.catalogVersion, cipherPassSub);
infoBackupSaveFile(
infoBackup, storageRepoWriteStanza, INFO_BACKUP_PATH_FILE_STR,
cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
}
// Else if at least one archive and one backup info file exists, then ensure both are valid
else if ((archiveInfoFileExists || archiveInfoFileCopyExists) && (backupInfoFileExists || backupInfoFileCopyExists))
@ -99,7 +99,7 @@ cmdStanzaCreate(void)
// current database
checkStanzaInfoPg(
storageRepoReadStanza, pgControl.version, pgControl.systemId,
cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
// The files are valid - upgrade
const String *sourceFile = NULL;

View File

@ -51,12 +51,12 @@ cmdStanzaUpgrade(void)
// Load the info files (errors if missing)
InfoArchive *infoArchive = infoArchiveLoadFile(
storageRepoReadStanza, INFO_ARCHIVE_PATH_FILE_STR, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepoReadStanza, INFO_ARCHIVE_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
InfoPgData archiveInfo = infoPgData(infoArchivePg(infoArchive), infoPgDataCurrentId(infoArchivePg(infoArchive)));
InfoBackup *infoBackup = infoBackupLoadFile(
storageRepoReadStanza, INFO_BACKUP_PATH_FILE_STR, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)),
storageRepoReadStanza, INFO_BACKUP_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
InfoPgData backupInfo = infoPgData(infoBackupPg(infoBackup), infoPgDataCurrentId(infoBackupPg(infoBackup)));
@ -86,15 +86,15 @@ cmdStanzaUpgrade(void)
{
infoArchiveSaveFile(
infoArchive, storageRepoWriteStanza, INFO_ARCHIVE_PATH_FILE_STR,
cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
}
// Save backup info
if (infoBackupUpgrade)
{
infoBackupSaveFile(
infoBackup, storageRepoWriteStanza, INFO_BACKUP_PATH_FILE_STR,
cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, repoIdx)), cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
infoBackup, storageRepoWriteStanza, INFO_BACKUP_PATH_FILE_STR, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
cfgOptionIdxStrNull(cfgOptRepoCipherPass, repoIdx));
}
if (!(infoArchiveUpgrade || infoBackupUpgrade))

View File

@ -172,7 +172,7 @@ verifyFileLoad(const String *pathFileName, const String *cipherPass)
// *read points to a location within result so update result with contents based on necessary filters
IoRead *read = storageReadIo(result);
cipherBlockFilterGroupAdd(
ioReadFilterGroup(read), cipherType(cfgOptionStr(cfgOptRepoCipherType)), cipherModeDecrypt, cipherPass);
ioReadFilterGroup(read), cfgOptionStrId(cfgOptRepoCipherType), cipherModeDecrypt, cipherPass);
ioFilterGroupAdd(ioReadFilterGroup(read), cryptoHashNew(HASH_TYPE_SHA1_STR));
// If the file is compressed, add a decompression filter

View File

@ -392,8 +392,8 @@ IoFilter *
cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const String *digestName)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, mode);
FUNCTION_LOG_PARAM(ENUM, cipherType);
FUNCTION_LOG_PARAM(STRING_ID, mode);
FUNCTION_LOG_PARAM(STRING_ID, cipherType);
FUNCTION_TEST_PARAM(BUFFER, pass); // Use FUNCTION_TEST so passphrase is not logged
FUNCTION_LOG_PARAM(STRING, digestName);
FUNCTION_LOG_END();
@ -406,10 +406,10 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const
// Lookup cipher by name. This means the ciphers passed in must exactly match a name expected by OpenSSL. This is a good
// thing since the name required by the openssl command-line tool will match what is used by pgBackRest.
const EVP_CIPHER *cipher = EVP_get_cipherbyname(strZ(cipherTypeName(cipherType)));
const EVP_CIPHER *cipher = EVP_get_cipherbyname(strZ(strIdToStr(cipherType)));
if (!cipher)
THROW_FMT(AssertError, "unable to load cipher '%s'", strZ(cipherTypeName(cipherType)));
THROW_FMT(AssertError, "unable to load cipher '%s'", strZ(strIdToStr(cipherType)));
// Lookup digest. If not defined it will be set to sha1.
const EVP_MD *digest = NULL;
@ -444,8 +444,8 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const
// Create param list
VariantList *paramList = varLstNew();
varLstAdd(paramList, varNewUInt(mode));
varLstAdd(paramList, varNewUInt(cipherType));
varLstAdd(paramList, varNewUInt64(mode));
varLstAdd(paramList, varNewUInt64(cipherType));
// ??? Using a string here is not correct since the passphrase is being passed as a buffer so may contain null characters.
// However, since strings are used to hold the passphrase in the rest of the code this is currently valid.
varLstAdd(paramList, varNewStr(strNewBuf(pass)));
@ -465,7 +465,7 @@ IoFilter *
cipherBlockNewVar(const VariantList *paramList)
{
return cipherBlockNew(
(CipherMode)varUIntForce(varLstGet(paramList, 0)), (CipherType)varUIntForce(varLstGet(paramList, 1)),
(CipherMode)varUInt64(varLstGet(paramList, 0)), (CipherType)varUInt64(varLstGet(paramList, 1)),
BUFSTR(varStr(varLstGet(paramList, 2))), varLstGet(paramList, 3) == NULL ? NULL : varStr(varLstGet(paramList, 3)));
}
@ -475,8 +475,8 @@ cipherBlockFilterGroupAdd(IoFilterGroup *filterGroup, CipherType type, CipherMod
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(IO_FILTER_GROUP, filterGroup);
FUNCTION_LOG_PARAM(ENUM, type);
FUNCTION_LOG_PARAM(ENUM, mode);
FUNCTION_LOG_PARAM(STRING_ID, type);
FUNCTION_LOG_PARAM(STRING_ID, mode);
FUNCTION_TEST_PARAM(STRING, pass); // Use FUNCTION_TEST so passphrase is not logged
FUNCTION_LOG_END();

View File

@ -14,12 +14,6 @@ Crypto Common
#include "common/log.h"
#include "common/crypto/common.h"
/***********************************************************************************************************************************
Cipher types
***********************************************************************************************************************************/
STRING_EXTERN(CIPHER_TYPE_NONE_STR, CIPHER_TYPE_NONE);
STRING_EXTERN(CIPHER_TYPE_AES_256_CBC_STR, CIPHER_TYPE_AES_256_CBC);
/***********************************************************************************************************************************
Flag to indicate if OpenSSL has already been initialized
***********************************************************************************************************************************/
@ -54,43 +48,6 @@ cryptoErrorCode(unsigned long code, const char *description)
FUNCTION_TEST_RETURN_VOID();
}
/**********************************************************************************************************************************/
CipherType
cipherType(const String *name)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRING, name);
FUNCTION_TEST_END();
ASSERT(name != NULL);
CipherType result = cipherTypeNone;
if (strEq(name, CIPHER_TYPE_AES_256_CBC_STR))
result = cipherTypeAes256Cbc;
else if (!strEq(name, CIPHER_TYPE_NONE_STR))
THROW_FMT(AssertError, "invalid cipher name '%s'", strZ(name));
FUNCTION_TEST_RETURN(result);
}
const String *
cipherTypeName(CipherType type)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, type);
FUNCTION_TEST_END();
const String *result = CIPHER_TYPE_NONE_STR;
if (type == cipherTypeAes256Cbc)
result = CIPHER_TYPE_AES_256_CBC_STR;
else if (type != cipherTypeNone)
THROW_FMT(AssertError, "invalid cipher type %u", type);
FUNCTION_TEST_RETURN(result);
}
/**********************************************************************************************************************************/
void
cryptoInit(void)

View File

@ -4,13 +4,15 @@ Crypto Common
#ifndef COMMON_CRYPTO_COMMON_H
#define COMMON_CRYPTO_COMMON_H
#include <common/type/stringId.h>
/***********************************************************************************************************************************
Cipher modes
***********************************************************************************************************************************/
typedef enum
{
cipherModeEncrypt,
cipherModeDecrypt,
cipherModeEncrypt = STRID5("encrypt", 0x521990dc50),
cipherModeDecrypt = STRID5("decrypt", 0x521990ca40),
} CipherMode;
/***********************************************************************************************************************************
@ -18,17 +20,10 @@ Cipher types
***********************************************************************************************************************************/
typedef enum
{
cipherTypeNone,
cipherTypeAes256Cbc,
cipherTypeNone = STRID5("none", 0x2b9ee0),
cipherTypeAes256Cbc = STRID5("aes-256-cbc", 0xc43dfbbcdcca10),
} CipherType;
#include <common/type/string.h>
#define CIPHER_TYPE_NONE "none"
STRING_DECLARE(CIPHER_TYPE_NONE_STR);
#define CIPHER_TYPE_AES_256_CBC "aes-256-cbc"
STRING_DECLARE(CIPHER_TYPE_AES_256_CBC_STR);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
@ -42,10 +37,6 @@ bool cryptoIsInit(void);
void cryptoError(bool error, const char *description);
void cryptoErrorCode(unsigned long code, const char *description) __attribute__((__noreturn__));
// Get cipher type or name
CipherType cipherType(const String *name);
const String *cipherTypeName(CipherType type);
// Generate random bytes
void cryptoRandomBytes(unsigned char *buffer, size_t size);

View File

@ -252,7 +252,7 @@ infoArchiveLoadFile(const Storage *storage, const String *fileName, CipherType c
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(STORAGE, storage);
FUNCTION_LOG_PARAM(STRING, fileName);
FUNCTION_LOG_PARAM(ENUM, cipherType);
FUNCTION_LOG_PARAM(STRING_ID, cipherType);
FUNCTION_TEST_PARAM(STRING, cipherPass);
FUNCTION_LOG_END();
@ -306,7 +306,7 @@ infoArchiveSaveFile(
FUNCTION_LOG_PARAM(INFO_ARCHIVE, infoArchive);
FUNCTION_LOG_PARAM(STORAGE, storage);
FUNCTION_LOG_PARAM(STRING, fileName);
FUNCTION_LOG_PARAM(ENUM, cipherType);
FUNCTION_LOG_PARAM(STRING_ID, cipherType);
FUNCTION_TEST_PARAM(STRING, cipherPass);
FUNCTION_LOG_END();

View File

@ -552,7 +552,7 @@ infoBackupLoadFile(const Storage *storage, const String *fileName, CipherType ci
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(STORAGE, storage);
FUNCTION_LOG_PARAM(STRING, fileName);
FUNCTION_LOG_PARAM(ENUM, cipherType);
FUNCTION_LOG_PARAM(STRING_ID, cipherType);
FUNCTION_TEST_PARAM(STRING, cipherPass);
FUNCTION_LOG_END();
@ -602,7 +602,7 @@ infoBackupLoadFileReconstruct(const Storage *storage, const String *fileName, Ci
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(STORAGE, storage);
FUNCTION_LOG_PARAM(STRING, fileName);
FUNCTION_LOG_PARAM(ENUM, cipherType);
FUNCTION_LOG_PARAM(STRING_ID, cipherType);
FUNCTION_TEST_PARAM(STRING, cipherPass);
FUNCTION_LOG_END();
@ -707,7 +707,7 @@ infoBackupSaveFile(
FUNCTION_LOG_PARAM(INFO_BACKUP, infoBackup);
FUNCTION_LOG_PARAM(STORAGE, storage);
FUNCTION_LOG_PARAM(STRING, fileName);
FUNCTION_LOG_PARAM(ENUM, cipherType);
FUNCTION_LOG_PARAM(STRING_ID, cipherType);
FUNCTION_TEST_PARAM(STRING, cipherPass);
FUNCTION_LOG_END();

View File

@ -2837,7 +2837,7 @@ manifestLoadFile(const Storage *storage, const String *fileName, CipherType ciph
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(STORAGE, storage);
FUNCTION_LOG_PARAM(STRING, fileName);
FUNCTION_LOG_PARAM(ENUM, cipherType);
FUNCTION_LOG_PARAM(STRING_ID, cipherType);
FUNCTION_TEST_PARAM(STRING, cipherPass);
FUNCTION_LOG_END();

View File

@ -495,7 +495,7 @@ protocolRemoteGet(ProtocolStorageType protocolStorageType, unsigned int hostIdx)
PROTOCOL_SERVICE_REMOTE_STR, execIoRead(protocolHelperClient->exec), execIoWrite(protocolHelperClient->exec));
// Get cipher options from the remote if none are locally configured
if (isRepo && strEq(cfgOptionIdxStr(cfgOptRepoCipherType, hostIdx), CIPHER_TYPE_NONE_STR))
if (isRepo && cfgOptionIdxStrId(cfgOptRepoCipherType, hostIdx) == cipherTypeNone)
{
// Options to query
VariantList *param = varLstNew();
@ -504,7 +504,7 @@ protocolRemoteGet(ProtocolStorageType protocolStorageType, unsigned int hostIdx)
VariantList *optionList = configOptionRemote(protocolHelperClient->client, param);
if (!strEq(varStr(varLstGet(optionList, 0)), CIPHER_TYPE_NONE_STR))
if (!strEq(varStr(varLstGet(optionList, 0)), strIdToStr(cipherTypeNone)))
{
cfgOptionIdxSet(cfgOptRepoCipherType, hostIdx, cfgSourceConfig, varLstGet(optionList, 0));
cfgOptionIdxSet(cfgOptRepoCipherPass, hostIdx, cfgSourceConfig, varLstGet(optionList, 1));

View File

@ -269,7 +269,7 @@ hrnStoragePut(const Storage *storage, const char *file, const Buffer *buffer, Hr
}
// Add encrypted filter
if (param.cipherType != cipherTypeNone)
if (param.cipherType != 0 && param.cipherType != cipherTypeNone)
{
// Default to main cipher pass
if (param.cipherPass == NULL)
@ -293,7 +293,7 @@ hrnStoragePutLog(const Storage *storage, const char *file, const Buffer *buffer,
strCatFmt(log, "cmp[%s]", strZ(compressTypeStr(param.compressType)));
// Add encryption detail
if (param.cipherType != cipherTypeNone)
if (param.cipherType != 0 && param.cipherType != cipherTypeNone)
{
if (param.cipherPass == NULL)
param.cipherPass = TEST_CIPHER_PASS;
@ -301,11 +301,11 @@ hrnStoragePutLog(const Storage *storage, const char *file, const Buffer *buffer,
if (param.compressType != compressTypeNone)
strCatZ(log, "/");
strCatFmt(log, "enc[%s,%s]", strZ(cipherTypeName(param.cipherType)), param.cipherPass);
strCatFmt(log, "enc[%s,%s]", strZ(strIdToStr(param.cipherType)), param.cipherPass);
}
// Add a space if compression/encryption defined
if (param.compressType != compressTypeNone || param.cipherType != cipherTypeNone)
if (param.compressType != compressTypeNone || (param.cipherType != 0 && param.cipherType != cipherTypeNone))
strCatZ(log, " ");
// Add file name

View File

@ -960,7 +960,7 @@ testRun(void)
hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH_PG);
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 1, TEST_PATH_REPO "-bogus");
hrnCfgArgKeyRawFmt(argList, cfgOptRepoPath, 2, TEST_PATH_REPO);
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, TEST_CIPHER_PASS);
hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
strLstAddZ(argList, "01ABCDEF01ABCDEF01ABCDEF");
@ -1098,7 +1098,7 @@ testRun(void)
paramList, varNewStrZ("10-1/01ABCDEF01ABCDEF/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz"));
varLstAdd(paramList, varNewUInt(1));
varLstAdd(paramList, varNewStrZ("10-1"));
varLstAdd(paramList, varNewUInt(cipherTypeAes256Cbc));
varLstAdd(paramList, varNewUInt64(cipherTypeAes256Cbc));
varLstAdd(paramList, varNewStrZ(TEST_CIPHER_PASS_ARCHIVE));
TEST_RESULT_VOID(archiveGetFileProtocol(paramList, server), "protocol archive get");

View File

@ -538,7 +538,7 @@ testRun(void)
hrnCfgArgRawZ(argListTemp, cfgOptStanza, "test");
hrnCfgArgKeyRawFmt(argListTemp, cfgOptPgPath, 1, "%s/pg", testPath());
hrnCfgArgKeyRawFmt(argListTemp, cfgOptRepoPath, 2, "%s/repo2", testPath());
hrnCfgArgKeyRawZ(argListTemp, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argListTemp, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, "badpassphrase");
hrnCfgArgKeyRawFmt(argListTemp, cfgOptRepoPath, 3, "%s/repo3", testPath());
hrnCfgArgRawNegate(argListTemp, cfgOptCompress);

View File

@ -510,7 +510,7 @@ testRun(void)
varLstAdd(paramList, varNewInt(0)); // repoFileCompressLevel
varLstAdd(paramList, varNewStr(backupLabel)); // backupLabel
varLstAdd(paramList, varNewBool(false)); // delta
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
varLstAdd(paramList, varNewUInt64(cipherTypeNone)); // cipherType
varLstAdd(paramList, NULL); // cipherSubPass
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - skip");
@ -594,7 +594,7 @@ testRun(void)
varLstAdd(paramList, varNewInt(1)); // repoFileCompressLevel
varLstAdd(paramList, varNewStr(backupLabel)); // backupLabel
varLstAdd(paramList, varNewBool(false)); // delta
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
varLstAdd(paramList, varNewUInt64(cipherTypeNone)); // cipherType
varLstAdd(paramList, NULL); // cipherSubPass
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - pageChecksum");
@ -637,7 +637,7 @@ testRun(void)
varLstAdd(paramList, varNewInt(1)); // repoFileCompressLevel
varLstAdd(paramList, varNewStr(backupLabel)); // backupLabel
varLstAdd(paramList, varNewBool(true)); // delta
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
varLstAdd(paramList, varNewUInt64(cipherTypeNone)); // cipherType
varLstAdd(paramList, NULL); // cipherSubPass
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - noop");
@ -779,7 +779,7 @@ testRun(void)
varLstAdd(paramList, varNewInt(3)); // repoFileCompressLevel
varLstAdd(paramList, varNewStr(backupLabel)); // backupLabel
varLstAdd(paramList, varNewBool(false)); // delta
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
varLstAdd(paramList, varNewUInt64(cipherTypeNone)); // cipherType
varLstAdd(paramList, NULL); // cipherSubPass
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - copy, compress");
@ -894,7 +894,7 @@ testRun(void)
varLstAdd(paramList, varNewInt(0)); // repoFileCompressLevel
varLstAdd(paramList, varNewStr(backupLabel)); // backupLabel
varLstAdd(paramList, varNewBool(false)); // delta
varLstAdd(paramList, varNewUInt(cipherTypeAes256Cbc)); // cipherType
varLstAdd(paramList, varNewUInt64(cipherTypeAes256Cbc));// cipherType
varLstAdd(paramList, varNewStrZ("12345678")); // cipherPass
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - recopy, encrypt");
@ -1583,7 +1583,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
hrnCfgArgKeyRawFmt(argList, cfgOptRepoPath, 2, "%s/repo2", testPath());
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, TEST_CIPHER_PASS);
hrnCfgArgRaw(argList, cfgOptPgPath, pg1Path);
strLstAddZ(argList, "--no-" CFGOPT_ONLINE);

View File

@ -553,7 +553,7 @@ testRun(void)
// Version mismatch
TEST_ERROR_FMT(
checkStanzaInfoPg(
storageRepoIdx(0), PG_VERSION_94, 6569239123849665679, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, 0)),
storageRepoIdx(0), PG_VERSION_94, 6569239123849665679, cfgOptionIdxStrId(cfgOptRepoCipherType, 0),
cfgOptionIdxStr(cfgOptRepoCipherPass, 0)),
FileInvalidError,
"backup and archive info files exist but do not match the database\n"
@ -563,7 +563,7 @@ testRun(void)
// SystemId mismatch
TEST_ERROR_FMT(
checkStanzaInfoPg(
storageRepoIdx(0), PG_VERSION_96, 6569239123849665699, cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, 0)),
storageRepoIdx(0), PG_VERSION_96, 6569239123849665699, cfgOptionIdxStrId(cfgOptRepoCipherType, 0),
cfgOptionIdxStr(cfgOptRepoCipherPass, 0)),
FileInvalidError,
"backup and archive info files exist but do not match the database\n"

View File

@ -2028,7 +2028,7 @@ testRun(void)
hrnCfgArgRawZ(argList, cfgOptSet, "20181119-152850F_20181119-152252D");
hrnCfgArgKeyRawFmt(argList, cfgOptRepoPath, 2, "%s/repo2", testPath());
hrnCfgArgKeyRawZ(argList, cfgOptRepoRetentionFull, 2, "1");
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, TEST_CIPHER_PASS);
harnessCfgLoad(cfgCmdExpire, argList);

View File

@ -1078,7 +1078,7 @@ testRun(void)
StringList *argListMultiRepo = strLstNew();
hrnCfgArgRawZ(argListMultiRepo, cfgOptRepoPath, TEST_PATH_REPO);
hrnCfgArgKeyRawFmt(argListMultiRepo, cfgOptRepoPath, 2, "%s/repo2", testPath());
hrnCfgArgKeyRawZ(argListMultiRepo, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argListMultiRepo, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, TEST_CIPHER_PASS);
StringList *argListMultiRepoJson = strLstDup(argListMultiRepo);

View File

@ -315,7 +315,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, "--" CFGOPT_CIPHER_PASS "=custom");
strLstAdd(argList, fileEncCustomName);
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -327,7 +327,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, "--raw");
strLstAdd(argList, fileRawName);
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -349,7 +349,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_ARCHIVE "/test/" INFO_ARCHIVE_FILE);
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -360,7 +360,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_ARCHIVE "/test/" INFO_ARCHIVE_FILE ".copy");
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -371,7 +371,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/" INFO_BACKUP_FILE);
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -382,7 +382,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/" INFO_BACKUP_FILE ".copy");
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -399,7 +399,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, "--" CFGOPT_CIPHER_PASS "=custom");
strLstAdd(argList, strNew(STORAGE_PATH_ARCHIVE "/test/12-1/000000010000000100000001-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -414,7 +414,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, "--" CFGOPT_CIPHER_PASS "=custom");
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/latest/" BACKUP_MANIFEST_FILE);
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -426,7 +426,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, "--" CFGOPT_CIPHER_PASS "=custom");
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/latest/" BACKUP_MANIFEST_FILE ".copy");
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -440,7 +440,7 @@ testRun(void)
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 1, TEST_PATH "/bogus");
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 2, TEST_PATH_REPO);
hrnCfgArgRawZ(argList, cfgOptRepo, "2");
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
strLstAddZ(argList, "--" CFGOPT_CIPHER_PASS "=custom");
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/backup.history/2020/label.manifest.gz");
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -452,7 +452,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, "--" CFGOPT_CIPHER_PASS "=custom2");
strLstAdd(argList, strNew(STORAGE_PATH_BACKUP "/test/latest/pg_data/backup_label"));
harnessCfgLoad(cfgCmdRepoPut, argList);
@ -495,7 +495,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, "--" CFGOPT_CIPHER_PASS "=custom");
strLstAdd(argList, fileEncCustomName);
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -509,7 +509,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, "--raw");
strLstAdd(argList, fileRawName);
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -550,7 +550,7 @@ testRun(void)
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 1, TEST_PATH "/bogus");
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 2, TEST_PATH_REPO);
hrnCfgArgRawZ(argList, cfgOptRepo, "2");
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, "/somewhere/" INFO_ARCHIVE_FILE);
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -564,7 +564,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAdd(argList, fileEncCustomName);
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -579,7 +579,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
strLstAddZ(argList, "--" CFGOPT_STANZA "=test2");
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_ARCHIVE "/test/" INFO_ARCHIVE_FILE);
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -592,7 +592,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_ARCHIVE "/test/" INFO_ARCHIVE_FILE);
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -606,7 +606,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
strLstAddZ(argList, "--" CFGOPT_STANZA "=test");
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_ARCHIVE "/test/" INFO_ARCHIVE_FILE ".copy");
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -619,7 +619,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/" INFO_BACKUP_FILE);
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -632,7 +632,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/" INFO_BACKUP_FILE ".copy");
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -648,7 +648,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAdd(argList, strNewFmt(
"%s/repo/" STORAGE_PATH_ARCHIVE "/test/12-1/000000010000000100000001-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",testPath()));
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -662,7 +662,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/latest/" BACKUP_MANIFEST_FILE);
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -675,7 +675,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/latest/" BACKUP_MANIFEST_FILE ".copy");
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -688,7 +688,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/backup.history/2020/label.manifest.gz");
harnessCfgLoad(cfgCmdRepoGet, argList);
@ -701,7 +701,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
strLstAdd(argList, strNew(STORAGE_PATH_BACKUP "/test/latest/pg_data/backup_label"));
harnessCfgLoad(cfgCmdRepoGet, argList);

View File

@ -1373,7 +1373,7 @@ testRun(void)
"system databases (template0, postgres, etc.) are included by default");
TEST_RESULT_LOG("P00 DETAIL: databases found for selective restore (1, 12168, 16380, 16381, 16384, 16385)");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("error on missing database selected");
@ -1949,7 +1949,7 @@ testRun(void)
hrnCfgArgKeyRaw(argList, cfgOptRepoPath, 2, repoPathEncrpyt);
strLstAdd(argList, strNewFmt("--pg1-path=%s", strZ(pgPath)));
strLstAddZ(argList, "--set=20161219-212741F");
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, TEST_CIPHER_PASS);
harnessCfgLoad(cfgCmdRestore, argList);
@ -2051,7 +2051,7 @@ testRun(void)
// Add encryption filter and save the encrypted manifest
#define TEST_CIPHER_PASS_MANIFEST "backpass"
cipherBlockFilterGroupAdd(
ioWriteFilterGroup(write), cipherType(cfgOptionIdxStr(cfgOptRepoCipherType, 1)), cipherModeEncrypt,
ioWriteFilterGroup(write), cfgOptionIdxStrId(cfgOptRepoCipherType, 1), cipherModeEncrypt,
STRDEF(TEST_CIPHER_PASS_MANIFEST));
manifestSave(manifestEncrypted, write);
@ -2115,7 +2115,7 @@ testRun(void)
strLstAddZ(argList, "--set=20161219-212741F");
strLstAddZ(argList, "--" CFGOPT_DELTA);
strLstAddZ(argList, "--force");
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, TEST_CIPHER_PASS);
harnessCfgLoad(cfgCmdRestore, argList);

View File

@ -123,11 +123,11 @@ testRun(void)
argList = strLstDup(argListBase);
hrnCfgArgKeyRawFmt(argList, cfgOptRepoPath, 2, "%s/repo2", testPath());
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, "12345678");
hrnCfgArgKeyRawFmt(argList, cfgOptRepoPath, 3, "%s/repo3", testPath());
hrnCfgArgKeyRawFmt(argList, cfgOptRepoPath, 4, "%s/repo4", testPath());
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 4, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 4, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 4, "87654321");
harnessCfgLoad(cfgCmdStanzaCreate, argList);
@ -302,7 +302,7 @@ testRun(void)
argList = strLstDup(argListBase);
hrnCfgArgKeyRawFmt(argList, cfgOptRepoPath, 2, "%s/repo2", testPath());
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, "12345678");
harnessCfgLoad(cfgCmdStanzaCreate, argList);

View File

@ -45,15 +45,6 @@ testRun(void)
TEST_ERROR(cryptoError(true, "no error"), CryptoError, "no error: [0] no details available");
// -------------------------------------------------------------------------------------------------------------------------
TEST_ERROR(cipherType(strNew(BOGUS_STR)), AssertError, "invalid cipher name 'BOGUS'");
TEST_RESULT_UINT(cipherType(strNew("none")), cipherTypeNone, "none type");
TEST_RESULT_UINT(cipherType(strNew("aes-256-cbc")), cipherTypeAes256Cbc, "aes-256-cbc type");
TEST_ERROR(cipherTypeName((CipherType)2), AssertError, "invalid cipher type 2");
TEST_RESULT_STR_Z(cipherTypeName(cipherTypeNone), "none", "none name");
TEST_RESULT_STR_Z(cipherTypeName(cipherTypeAes256Cbc), "aes-256-cbc", "aes-256-cbc name");
// Test if the buffer was overrun
// -------------------------------------------------------------------------------------------------------------------------
unsigned char buffer[256] = {0};