mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Hacky fix to cancelling a switch to an encrypted profile closing
It's either this or some fairly major refactoring, which is preferable, but I've got another even bigger refactoring in mind, and fixing this will be rolled into that. Closes dubslow/qTox#4
This commit is contained in:
parent
ed22dc9ca5
commit
60e819baee
29
src/core.cpp
29
src/core.cpp
|
@ -178,7 +178,7 @@ void Core::make_tox()
|
||||||
{
|
{
|
||||||
qCritical() << "Core: bad proxy! no toxcore!";
|
qCritical() << "Core: bad proxy! no toxcore!";
|
||||||
emit badProxy();
|
emit badProxy();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qCritical() << "Tox core failed to start";
|
qCritical() << "Tox core failed to start";
|
||||||
|
@ -223,9 +223,19 @@ void Core::start()
|
||||||
{
|
{
|
||||||
if (loadPath.isEmpty())
|
if (loadPath.isEmpty())
|
||||||
{
|
{
|
||||||
qCritical() << "Core: loadConfiguration failed, exiting now";
|
QString profile;
|
||||||
emit failedToStart();
|
if ((profile = loadOldInformation()).isEmpty())
|
||||||
return;
|
{
|
||||||
|
qCritical() << "Core: loadConfiguration failed, exiting now";
|
||||||
|
emit failedToStart();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT);
|
||||||
|
Settings::getInstance().switchProfile(profile);
|
||||||
|
HistoryKeeper::resetInstance(); // I'm not actually sure if this is necessary
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// loadPath is meaningless after this
|
// loadPath is meaningless after this
|
||||||
|
@ -284,7 +294,7 @@ void Core::start()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
qDebug() << "Core: Error loading self avatar";
|
qDebug() << "Core: Error loading self avatar";
|
||||||
|
|
||||||
ready = true;
|
ready = true;
|
||||||
|
|
||||||
process(); // starts its own timer
|
process(); // starts its own timer
|
||||||
|
@ -1201,7 +1211,7 @@ bool Core::loadConfiguration(QString path)
|
||||||
QString name = getUsername();
|
QString name = getUsername();
|
||||||
if (!name.isEmpty())
|
if (!name.isEmpty())
|
||||||
emit usernameSet(name);
|
emit usernameSet(name);
|
||||||
|
|
||||||
QString msg = getStatusMessage();
|
QString msg = getStatusMessage();
|
||||||
if (!msg.isEmpty())
|
if (!msg.isEmpty())
|
||||||
emit statusMessageSet(msg);
|
emit statusMessageSet(msg);
|
||||||
|
@ -1229,7 +1239,7 @@ void Core::saveConfiguration()
|
||||||
qCritical() << "Error while creating directory " << dir;
|
qCritical() << "Error while creating directory " << dir;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString profile = Settings::getInstance().getCurrentProfile();
|
QString profile = Settings::getInstance().getCurrentProfile();
|
||||||
|
|
||||||
if (profile == "")
|
if (profile == "")
|
||||||
|
@ -1241,9 +1251,9 @@ void Core::saveConfiguration()
|
||||||
|
|
||||||
Settings::getInstance().switchProfile(profile);
|
Settings::getInstance().switchProfile(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString path = directory.filePath(profile + TOX_EXT);
|
QString path = directory.filePath(profile + TOX_EXT);
|
||||||
|
|
||||||
saveConfiguration(path);
|
saveConfiguration(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1255,6 +1265,7 @@ void Core::switchConfiguration(const QString& profile)
|
||||||
qDebug() << "Core: switching from" << Settings::getInstance().getCurrentProfile() << "to" << profile;
|
qDebug() << "Core: switching from" << Settings::getInstance().getCurrentProfile() << "to" << profile;
|
||||||
|
|
||||||
saveConfiguration();
|
saveConfiguration();
|
||||||
|
saveCurrentInformation(); // part of a hack, see core.h
|
||||||
|
|
||||||
ready = false;
|
ready = false;
|
||||||
Widget::getInstance()->setEnabledThreadsafe(false);
|
Widget::getInstance()->setEnabledThreadsafe(false);
|
||||||
|
|
18
src/core.h
18
src/core.h
|
@ -46,7 +46,7 @@ public:
|
||||||
explicit Core(Camera* cam, QThread* coreThread, QString initialLoadPath);
|
explicit Core(Camera* cam, QThread* coreThread, QString initialLoadPath);
|
||||||
static Core* getInstance(); ///< Returns the global widget's Core instance
|
static Core* getInstance(); ///< Returns the global widget's Core instance
|
||||||
~Core();
|
~Core();
|
||||||
|
|
||||||
static const QString TOX_EXT;
|
static const QString TOX_EXT;
|
||||||
static const QString CONFIG_FILE_NAME;
|
static const QString CONFIG_FILE_NAME;
|
||||||
static QString sanitize(QString name);
|
static QString sanitize(QString name);
|
||||||
|
@ -69,9 +69,9 @@ public:
|
||||||
|
|
||||||
void saveConfiguration();
|
void saveConfiguration();
|
||||||
void saveConfiguration(const QString& path);
|
void saveConfiguration(const QString& path);
|
||||||
|
|
||||||
QString getIDString() const; ///< Get the 12 first characters of our Tox ID
|
QString getIDString() const; ///< Get the 12 first characters of our Tox ID
|
||||||
|
|
||||||
QString getUsername() const; ///< Returns our username, or an empty string on failure
|
QString getUsername() const; ///< Returns our username, or an empty string on failure
|
||||||
QString getStatusMessage() const; ///< Returns our status message, or an empty string on failure
|
QString getStatusMessage() const; ///< Returns our status message, or an empty string on failure
|
||||||
ToxID getSelfId() const; ///< Returns our Tox ID
|
ToxID getSelfId() const; ///< Returns our Tox ID
|
||||||
|
@ -299,7 +299,17 @@ private:
|
||||||
QMutex fileSendMutex, messageSendMutex;
|
QMutex fileSendMutex, messageSendMutex;
|
||||||
bool ready;
|
bool ready;
|
||||||
|
|
||||||
uint8_t* pwsaltedkeys[PasswordType::ptCounter]; // use the pw's hash as the "pw"
|
uint8_t* pwsaltedkeys[PasswordType::ptCounter] = {nullptr}; // use the pw's hash as the "pw"
|
||||||
|
|
||||||
|
// Hack for reloading current profile if switching to an encrypted one fails.
|
||||||
|
// Testing the passwords before killing the current profile is perfectly doable,
|
||||||
|
// however it would require major refactoring;
|
||||||
|
// the Core class as a whole also requires major refactoring (especially to support multiple IDs at once),
|
||||||
|
// so I'm punting on this until then, when it would get fixed anyways
|
||||||
|
uint8_t* backupkeys[PasswordType::ptCounter] = {nullptr};
|
||||||
|
QString* backupProfile = nullptr;
|
||||||
|
void saveCurrentInformation();
|
||||||
|
QString loadOldInformation();
|
||||||
|
|
||||||
static const int videobufsize;
|
static const int videobufsize;
|
||||||
static uint8_t* videobuf;
|
static uint8_t* videobuf;
|
||||||
|
|
|
@ -65,6 +65,43 @@ void Core::clearPassword(PasswordType passtype)
|
||||||
pwsaltedkeys[passtype] = nullptr;
|
pwsaltedkeys[passtype] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// part of a hack, see core.h
|
||||||
|
void Core::saveCurrentInformation()
|
||||||
|
{
|
||||||
|
if (pwsaltedkeys[ptMain])
|
||||||
|
{
|
||||||
|
backupkeys[ptMain] = new uint8_t[tox_pass_key_length()];
|
||||||
|
std::copy(pwsaltedkeys[ptMain], pwsaltedkeys[ptMain]+tox_pass_key_length(), backupkeys[ptMain]);
|
||||||
|
}
|
||||||
|
if (pwsaltedkeys[ptHistory])
|
||||||
|
{
|
||||||
|
backupkeys[ptHistory] = new uint8_t[tox_pass_key_length()];
|
||||||
|
std::copy(pwsaltedkeys[ptHistory], pwsaltedkeys[ptHistory]+tox_pass_key_length(), backupkeys[ptHistory]);
|
||||||
|
}
|
||||||
|
backupProfile = new QString(Settings::getInstance().getCurrentProfile());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Core::loadOldInformation()
|
||||||
|
{
|
||||||
|
QString out;
|
||||||
|
if (backupProfile)
|
||||||
|
{
|
||||||
|
out = *backupProfile;
|
||||||
|
delete backupProfile;
|
||||||
|
backupProfile = nullptr;
|
||||||
|
}
|
||||||
|
backupProfile = nullptr;
|
||||||
|
clearPassword(ptMain);
|
||||||
|
clearPassword(ptHistory);
|
||||||
|
// we can just copy the pointer, as long as we null out backupkeys
|
||||||
|
// (if backupkeys was null anyways, then this is a null-op)
|
||||||
|
pwsaltedkeys[ptMain] = backupkeys[ptMain];
|
||||||
|
pwsaltedkeys[ptHistory] = backupkeys[ptHistory];
|
||||||
|
backupkeys[ptMain] = nullptr;
|
||||||
|
backupkeys[ptHistory] = nullptr;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray Core::encryptData(const QByteArray& data, PasswordType passtype)
|
QByteArray Core::encryptData(const QByteArray& data, PasswordType passtype)
|
||||||
{
|
{
|
||||||
if (!pwsaltedkeys[passtype])
|
if (!pwsaltedkeys[passtype])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user