Fixed decrypt/re-encrypt toggling

This commit is contained in:
Kenneth Skovhede
2024-08-20 21:10:15 +02:00
parent 3c1a4b5d94
commit d53357f4e7
2 changed files with 6 additions and 12 deletions
@@ -69,14 +69,10 @@ namespace Duplicati.Server.Database
public void ReWriteAllFieldsIfEncryptionChanged()
{
var activeToken = m_encryptSensitiveFields
? "enc-v1-canary"
: "no-encryption";
// The token is automatically decrypted when the settings are loaded
// In case the password has changed, this will fail and return the encrypted
// hex-string, but will crash before reaching this point
if (this.ApplicationSettings.EncryptionCanaryToken != activeToken)
if (this.ApplicationSettings.EncryptedFields != m_encryptSensitiveFields)
{
var backups = this.Backups;
foreach (var b in backups)
@@ -86,9 +82,7 @@ namespace Duplicati.Server.Database
}
this.SetSettings(this.GetSettings(ANY_BACKUP_ID), ANY_BACKUP_ID);
this.ApplicationSettings.EncryptionCanaryToken = m_encryptSensitiveFields
? EncryptedFieldHelper.Encrypt(activeToken)
: activeToken;
this.ApplicationSettings.EncryptedFields = m_encryptSensitiveFields;
}
}
@@ -59,7 +59,7 @@ namespace Duplicati.Server.Database
public const string PBKDF_CONFIG = "pbkdf-config";
public const string AUTOGENERATED_PASSPHRASE = "autogenerated-passphrase";
public const string DISABLE_VISUAL_CAPTCHA = "disable-visual-captcha";
public const string ENCRYPTION_CANARY_TOKEN = "encryption-canary-token";
public const string ENCRYPTED_FIELDS = "encrypted-fields";
}
private readonly Dictionary<string, string> settings;
@@ -653,16 +653,16 @@ namespace Duplicati.Server.Database
}
}
public string EncryptionCanaryToken
public bool EncryptedFields
{
get
{
return settings[CONST.ENCRYPTION_CANARY_TOKEN];
return Duplicati.Library.Utility.Utility.ParseBool(settings[CONST.ENCRYPTED_FIELDS], false);
}
set
{
lock (databaseConnection.m_lock)
settings[CONST.ENCRYPTION_CANARY_TOKEN] = value;
settings[CONST.ENCRYPTED_FIELDS] = value.ToString();
SaveSettings();
}
}