Skip to content

Commit

Permalink
Translate Cipher and KDF strings
Browse files Browse the repository at this point in the history
* Fix #8952 - move translations for Cipher and KDF strings into evaluated code instead of globally defined code. The strings were being baked prior to the language being set resulting in only english being displayed.
  • Loading branch information
droidmonkey committed Feb 15, 2023
1 parent f9d99fe commit ba15981
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
8 changes: 8 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7913,6 +7913,14 @@ Kernel: %3 %4</source>
<source>Failed to sign challenge using Windows Hello.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Invalid Cipher</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Invalid KDF</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QtIOCompressor</name>
Expand Down
4 changes: 2 additions & 2 deletions src/cli/DatabaseInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ int DatabaseInfo::executeWithDatabase(QSharedPointer<Database> database, QShared
out << QObject::tr("Name: ") << database->metadata()->name() << endl;
out << QObject::tr("Description: ") << database->metadata()->description() << endl;
for (auto& cipher : asConst(KeePass2::CIPHERS)) {
if (cipher.first == database->cipher()) {
out << QObject::tr("Cipher: ") << cipher.second << endl;
if (cipher == database->cipher()) {
out << QObject::tr("Cipher: ") << KeePass2::cipherToString(cipher) << endl;
}
}
out << QObject::tr("KDF: ") << database->kdf()->toString() << endl;
Expand Down
40 changes: 31 additions & 9 deletions src/format/KeePass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,12 @@ const QString KeePass2::KDFPARAM_ARGON2_VERSION("V");
const QString KeePass2::KDFPARAM_ARGON2_SECRET("K");
const QString KeePass2::KDFPARAM_ARGON2_ASSOCDATA("A");

const QList<QPair<QUuid, QString>> KeePass2::CIPHERS{
qMakePair(KeePass2::CIPHER_AES256, QObject::tr("AES 256-bit")),
qMakePair(KeePass2::CIPHER_TWOFISH, QObject::tr("Twofish 256-bit")),
qMakePair(KeePass2::CIPHER_CHACHA20, QObject::tr("ChaCha20 256-bit"))};
const QList<QUuid> KeePass2::CIPHERS{KeePass2::CIPHER_AES256, KeePass2::CIPHER_TWOFISH, KeePass2::CIPHER_CHACHA20};

const QList<QPair<QUuid, QString>> KeePass2::KDFS{
qMakePair(KeePass2::KDF_ARGON2D, QObject::tr("Argon2d (KDBX 4 – recommended)")),
qMakePair(KeePass2::KDF_ARGON2ID, QObject::tr("Argon2id (KDBX 4)")),
qMakePair(KeePass2::KDF_AES_KDBX4, QObject::tr("AES-KDF (KDBX 4)")),
qMakePair(KeePass2::KDF_AES_KDBX3, QObject::tr("AES-KDF (KDBX 3)"))};
const QList<QUuid> KeePass2::KDFS{KeePass2::KDF_ARGON2D,
KeePass2::KDF_ARGON2ID,
KeePass2::KDF_AES_KDBX4,
KeePass2::KDF_AES_KDBX3};

QByteArray KeePass2::hmacKey(const QByteArray& masterSeed, const QByteArray& transformedMasterKey)
{
Expand Down Expand Up @@ -133,3 +129,29 @@ KeePass2::ProtectedStreamAlgo KeePass2::idToProtectedStreamAlgo(quint32 id)
return KeePass2::ProtectedStreamAlgo::InvalidProtectedStreamAlgo;
}
}

QString KeePass2::cipherToString(QUuid cipherUuid)
{
if (cipherUuid == KeePass2::CIPHER_AES256) {
return QObject::tr("AES 256-bit");
} else if (cipherUuid == KeePass2::CIPHER_TWOFISH) {
return QObject::tr("Twofish 256-bit");
} else if (cipherUuid == KeePass2::CIPHER_CHACHA20) {
return QObject::tr("ChaCha20 256-bit");
}
return QObject::tr("Invalid Cipher");
}

QString KeePass2::kdfToString(QUuid kdfUuid)
{
if (kdfUuid == KeePass2::KDF_ARGON2D) {
return QObject::tr("Argon2d (KDBX 4 – recommended)");
} else if (kdfUuid == KeePass2::KDF_ARGON2ID) {
return QObject::tr("Argon2id (KDBX 4)");
} else if (kdfUuid == KeePass2::KDF_AES_KDBX4) {
return QObject::tr("AES-KDF (KDBX 4)");
} else if (kdfUuid == KDF_AES_KDBX3) {
return QObject::tr("AES-KDF (KDBX 3)");
}
return QObject::tr("Invalid KDF");
}
8 changes: 4 additions & 4 deletions src/format/KeePass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Kdf;

namespace KeePass2
{

constexpr quint32 SIGNATURE_1 = 0x9AA2D903;
constexpr quint32 SIGNATURE_2 = 0xB54BFB67;

Expand Down Expand Up @@ -67,8 +66,8 @@ namespace KeePass2
extern const QString KDFPARAM_ARGON2_SECRET;
extern const QString KDFPARAM_ARGON2_ASSOCDATA;

extern const QList<QPair<QUuid, QString>> CIPHERS;
extern const QList<QPair<QUuid, QString>> KDFS;
extern const QList<QUuid> CIPHERS;
extern const QList<QUuid> KDFS;

enum class HeaderFieldID
{
Expand Down Expand Up @@ -130,7 +129,8 @@ namespace KeePass2
QVariantMap kdfToParameters(const QSharedPointer<Kdf>& kdf);
QSharedPointer<Kdf> uuidToKdf(const QUuid& uuid);
ProtectedStreamAlgo idToProtectedStreamAlgo(quint32 id);

QString cipherToString(QUuid cipherUuid);
QString kdfToString(QUuid kdfUuid);
} // namespace KeePass2

#endif // KEEPASSX_KEEPASS2_H
6 changes: 3 additions & 3 deletions src/gui/dbsettings/DatabaseSettingsWidgetEncryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void DatabaseSettingsWidgetEncryption::setupAlgorithmComboBox()
{
m_ui->algorithmComboBox->clear();
for (auto& cipher : asConst(KeePass2::CIPHERS)) {
m_ui->algorithmComboBox->addItem(cipher.second.toUtf8(), cipher.first.toByteArray());
m_ui->algorithmComboBox->addItem(KeePass2::cipherToString(cipher), cipher.toByteArray());
}
int cipherIndex = m_ui->algorithmComboBox->findData(m_db->cipher().toByteArray());
if (cipherIndex > -1) {
Expand All @@ -155,8 +155,8 @@ void DatabaseSettingsWidgetEncryption::setupKdfComboBox(bool enableKdbx3)
bool block = m_ui->kdfComboBox->blockSignals(true);
m_ui->kdfComboBox->clear();
for (auto& kdf : asConst(KeePass2::KDFS)) {
if (kdf.first != KeePass2::KDF_AES_KDBX3 or enableKdbx3) {
m_ui->kdfComboBox->addItem(kdf.second.toUtf8(), kdf.first.toByteArray());
if (kdf != KeePass2::KDF_AES_KDBX3 or enableKdbx3) {
m_ui->kdfComboBox->addItem(KeePass2::kdfToString(kdf), kdf.toByteArray());
}
}
m_ui->kdfComboBox->blockSignals(block);
Expand Down

0 comments on commit ba15981

Please sign in to comment.