mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Load encrypted history log/tox datafile
This commit is contained in:
parent
08d7964dae
commit
6febde3167
108
src/core.cpp
108
src/core.cpp
|
@ -1096,19 +1096,11 @@ bool Core::loadConfiguration(QString path)
|
|||
|
||||
if (Settings::getInstance().getEncryptTox())
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
if (Settings::getInstance().getEnableLogging() && Settings::getInstance().getEncryptLogs())
|
||||
while (!isPasswordSet())
|
||||
{
|
||||
emit blockingGetPassword(tr("Tox datafile decryption password"));
|
||||
if (!isPasswordSet())
|
||||
{
|
||||
emit blockingGetPassword();
|
||||
if (!HistoryKeeper::checkPassword())
|
||||
{
|
||||
// FIXME: more interactive
|
||||
qWarning() << "Wrong password! History will be wiped!";
|
||||
}
|
||||
QMessageBox::warning(nullptr, tr("Password error"), tr("Failed to setup password.\nEmpty password."));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1122,29 +1114,89 @@ bool Core::loadConfiguration(QString path)
|
|||
}
|
||||
else if (error == 1) // Encrypted data save
|
||||
{
|
||||
if (!pwsaltedkey)
|
||||
do
|
||||
{
|
||||
qWarning() << "Core: Can not open encrypted tox save";
|
||||
if (QMessageBox::Ok != QMessageBox::warning(nullptr, tr("Encrypted profile"),
|
||||
tr("Your tox profile seems to be encrypted, qTox can't open it\nDo you want to erase this profile ?"),
|
||||
QMessageBox::Ok | QMessageBox::Cancel))
|
||||
while (!isPasswordSet())
|
||||
{
|
||||
emit blockingGetPassword(tr("Tox datafile decryption password"));
|
||||
if (!isPasswordSet())
|
||||
QMessageBox::warning(nullptr, tr("Password error"), tr("Failed to setup password.\nEmpty password."));
|
||||
}
|
||||
|
||||
error = tox_encrypted_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size(), pwsaltedkey, TOX_HASH_LENGTH);
|
||||
|
||||
if (error != 0)
|
||||
{
|
||||
QMessageBox msgb;
|
||||
QPushButton *tryAgain = msgb.addButton(tr("Try Again"), QMessageBox::AcceptRole);
|
||||
QPushButton *cancel = msgb.addButton(tr("Change profile"), QMessageBox::RejectRole);
|
||||
QPushButton *wipe = msgb.addButton(tr("Reinit current profile"), QMessageBox::ActionRole);
|
||||
msgb.setDefaultButton(tryAgain);
|
||||
|
||||
msgb.exec();
|
||||
|
||||
if (msgb.clickedButton() == tryAgain)
|
||||
{
|
||||
clearPassword();
|
||||
} else if (msgb.clickedButton() == cancel)
|
||||
{
|
||||
qWarning() << "Core: Couldn't open encrypted save, giving up";
|
||||
configurationFile.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /*
|
||||
while (error != 0)
|
||||
} else if (msgb.clickedButton() == wipe)
|
||||
{
|
||||
error = tox_encrypted_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size(), pwsaltedkey, TOX_HASH_LENGTH);
|
||||
emit blockingGetPassword();
|
||||
if (!pwsaltedkey)
|
||||
// we need a way to start core without any profile
|
||||
} */
|
||||
clearPassword();
|
||||
Settings::getInstance().setEncryptTox(false);
|
||||
error = 0;
|
||||
}
|
||||
}
|
||||
|
||||
} while (error != 0);
|
||||
}
|
||||
}
|
||||
|
||||
// tox core is already decrypted
|
||||
if (Settings::getInstance().getEnableLogging() && Settings::getInstance().getEncryptLogs())
|
||||
{
|
||||
if (isPasswordSet())
|
||||
{
|
||||
if (!HistoryKeeper::checkPassword())
|
||||
{
|
||||
QMessageBox::warning(nullptr, tr("Different passwords!"),
|
||||
tr("Tox datafile and history log encrypted with different passwords."));
|
||||
Settings::getInstance().setEncryptLogs(false);
|
||||
Settings::getInstance().setEnableLogging(false);
|
||||
}
|
||||
} else {
|
||||
bool error = true;
|
||||
do
|
||||
{
|
||||
while (!isPasswordSet())
|
||||
{
|
||||
emit blockingGetPassword(tr("History Log decpytion password"));
|
||||
if (!isPasswordSet())
|
||||
QMessageBox::warning(nullptr, tr("Password error"), tr("Failed to setup password.\nEmpty password."));
|
||||
}
|
||||
|
||||
if (!HistoryKeeper::checkPassword())
|
||||
{
|
||||
if (QMessageBox::Ok == QMessageBox::warning(nullptr, tr("Encrypted log"),
|
||||
tr("Your history encrypted with different password\nDo you want to try another password?"),
|
||||
QMessageBox::Ok | QMessageBox::Cancel))
|
||||
{
|
||||
error = true;
|
||||
clearPassword();
|
||||
} else {
|
||||
error = false;
|
||||
clearPassword();
|
||||
QMessageBox::warning(nullptr, tr("Loggin"), tr("Due to incorret password logging will be disabled"));
|
||||
Settings::getInstance().setEncryptLogs(false);
|
||||
Settings::getInstance().setEnableLogging(false);
|
||||
}
|
||||
} else {
|
||||
error = false;
|
||||
}
|
||||
} while (error);
|
||||
}
|
||||
}
|
||||
|
||||
configurationFile.close();
|
||||
|
@ -1218,7 +1270,7 @@ void Core::saveConfiguration(const QString& path)
|
|||
if (Settings::getInstance().getEncryptTox())
|
||||
{
|
||||
if (!pwsaltedkey)
|
||||
emit blockingGetPassword();
|
||||
emit blockingGetPassword(tr("Tox datafile encryption password"));
|
||||
//if (!pwsaltedkey)
|
||||
// revert to unsaved...? or maybe we shouldn't even try to get a pw from here ^
|
||||
int ret = tox_encrypted_save(tox, data, pwsaltedkey, TOX_HASH_LENGTH);
|
||||
|
|
|
@ -114,7 +114,7 @@ signals:
|
|||
void connected();
|
||||
void disconnected();
|
||||
void blockingClearContacts();
|
||||
void blockingGetPassword();
|
||||
void blockingGetPassword(QString info);
|
||||
|
||||
void friendRequestReceived(const QString& userId, const QString& message);
|
||||
void friendMessageReceived(int friendId, const QString& message, bool isAction);
|
||||
|
|
|
@ -17,11 +17,14 @@
|
|||
#include "inputpassworddialog.h"
|
||||
#include "ui_inputpassworddialog.h"
|
||||
|
||||
InputPasswordDialog::InputPasswordDialog(QWidget *parent) :
|
||||
InputPasswordDialog::InputPasswordDialog(QString title, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::InputPasswordDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if (title != QString())
|
||||
setWindowTitle(title);
|
||||
}
|
||||
|
||||
InputPasswordDialog::~InputPasswordDialog()
|
||||
|
|
|
@ -28,7 +28,7 @@ class InputPasswordDialog : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InputPasswordDialog(QWidget *parent = 0);
|
||||
explicit InputPasswordDialog(QString title = QString(), QWidget *parent = 0);
|
||||
~InputPasswordDialog();
|
||||
|
||||
QString getPassword();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>121</height>
|
||||
<height>123</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
|
@ -911,9 +911,9 @@ void Widget::onGroupSendResult(int groupId, const QString& message, int result)
|
|||
g->chatForm->addSystemInfoMessage("Message failed to send", "red", QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
void Widget::getPassword()
|
||||
void Widget::getPassword(QString info)
|
||||
{
|
||||
InputPasswordDialog dialog;
|
||||
InputPasswordDialog dialog(info);
|
||||
if (dialog.exec())
|
||||
{
|
||||
QString pswd = dialog.getPassword();
|
||||
|
|
|
@ -112,7 +112,7 @@ private slots:
|
|||
void playRingtone();
|
||||
void onIconClick();
|
||||
void onUserAway();
|
||||
void getPassword();
|
||||
void getPassword(QString info);
|
||||
|
||||
private:
|
||||
void hideMainForms();
|
||||
|
|
Loading…
Reference in New Issue
Block a user