From e1201f901f42667dc09ef0b0e3b70d44cc02367a Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Wed, 31 Oct 2018 11:51:57 -0700 Subject: [PATCH] chore(core): improve failed decryption error handling --- src/core/toxencrypt.cpp | 4 ++++ src/core/toxencrypt.h | 6 +++--- src/persistence/profile.cpp | 9 ++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core/toxencrypt.cpp b/src/core/toxencrypt.cpp index b618e3cc6..d36ca0e06 100644 --- a/src/core/toxencrypt.cpp +++ b/src/core/toxencrypt.cpp @@ -325,6 +325,10 @@ QString getDecryptionError(TOX_ERR_DECRYPTION error) "The input data was shorter than TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes."); case TOX_ERR_DECRYPTION_BAD_FORMAT: return QStringLiteral("The input data is missing the magic number or is corrupted."); + case TOX_ERR_DECRYPTION_KEY_DERIVATION_FAILED: + return QStringLiteral("The crypto lib was unable to derive a key from the given passphrase."); + case TOX_ERR_DECRYPTION_FAILED: + return QStringLiteral("Decryption failed. Either the data was corrupted or the password/key was incorrect."); default: return QStringLiteral("Unknown decryption error."); } diff --git a/src/core/toxencrypt.h b/src/core/toxencrypt.h index bc5a94ced..8127d3ca5 100644 --- a/src/core/toxencrypt.h +++ b/src/core/toxencrypt.h @@ -17,12 +17,12 @@ along with qTox. If not, see . */ -#include -#include - #ifndef TOXENCRYPT_H #define TOXENCRYPT_H +#include +#include + #include struct Tox_Pass_Key; diff --git a/src/persistence/profile.cpp b/src/persistence/profile.cpp index 1b61571b7..67308d798 100644 --- a/src/persistence/profile.cpp +++ b/src/persistence/profile.cpp @@ -436,11 +436,11 @@ QPixmap Profile::loadAvatar(const ToxPk& owner) QPixmap pic; if (Settings::getInstance().getShowIdenticons()) { - const QByteArray avataData = loadAvatarData(owner); - if (avataData.isEmpty()) { + const QByteArray avatarData = loadAvatarData(owner); + if (avatarData.isEmpty()) { pic = QPixmap::fromImage(Identicon(owner.getKey()).toImage(16)); } else { - pic.loadFromData(avataData); + pic.loadFromData(avatarData); } } else { @@ -473,6 +473,9 @@ QByteArray Profile::loadAvatarData(const ToxPk& owner) QByteArray pic = file.readAll(); if (avatarEncrypted && !pic.isEmpty()) { pic = passkey->decrypt(pic); + if (pic.isEmpty()) { + qWarning() << "Failed to decrypt avatar at" << path; + } } return pic;