1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

switch to tox_pass_encrypt/tox_pass_decrypt functions

This commit is contained in:
apprb 2014-10-18 00:53:06 +09:00
parent 177b27882b
commit 72aa313605
No known key found for this signature in database
GPG Key ID: B001911B5B22FB9B
2 changed files with 12 additions and 2 deletions

View File

@ -1536,6 +1536,10 @@ void Core::setPassword(QString& password)
CString str(password); CString str(password);
tox_derive_key_from_pass(str.data(), str.size(), pwsaltedkey); tox_derive_key_from_pass(str.data(), str.size(), pwsaltedkey);
barePassword.clear();
barePassword.append(password);
password.clear(); password.clear();
} }
@ -1545,6 +1549,7 @@ void Core::clearPassword()
{ {
delete[] pwsaltedkey; delete[] pwsaltedkey;
pwsaltedkey = nullptr; pwsaltedkey = nullptr;
barePassword.clear();
} }
} }
@ -1553,7 +1558,9 @@ QByteArray Core::encryptData(const QByteArray& data)
if (!pwsaltedkey) if (!pwsaltedkey)
return QByteArray(); return QByteArray();
uint8_t encrypted[data.size() + tox_pass_encryption_extra_length()]; uint8_t encrypted[data.size() + tox_pass_encryption_extra_length()];
if (tox_pass_key_encrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(), pwsaltedkey, encrypted) == -1) // if (tox_pass_key_encrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(), pwsaltedkey, encrypted) == -1)
if (tox_pass_encrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(),
reinterpret_cast<uint8_t*>(barePassword.data()), barePassword.size(), encrypted) == -1)
{ {
qWarning() << "Core::encryptData: encryption failed"; qWarning() << "Core::encryptData: encryption failed";
return QByteArray(); return QByteArray();
@ -1567,7 +1574,9 @@ QByteArray Core::decryptData(const QByteArray& data)
return QByteArray(); return QByteArray();
int sz = data.size() - tox_pass_encryption_extra_length(); int sz = data.size() - tox_pass_encryption_extra_length();
uint8_t decrypted[sz]; uint8_t decrypted[sz];
if (tox_pass_key_decrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(), pwsaltedkey, decrypted) != sz) // if (tox_pass_key_decrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(), pwsaltedkey, decrypted) != sz)
if (tox_pass_decrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(),
reinterpret_cast<uint8_t*>(barePassword.data()), barePassword.size(), decrypted) != sz)
{ {
qWarning() << "Core::decryptData: decryption failed"; qWarning() << "Core::decryptData: decryption failed";
return QByteArray(); return QByteArray();

View File

@ -251,6 +251,7 @@ private:
static QList<ToxFile> fileSendQueue, fileRecvQueue; static QList<ToxFile> fileSendQueue, fileRecvQueue;
static ToxCall calls[]; static ToxCall calls[];
uint8_t* pwsaltedkey = nullptr; // use the pw's hash as the "pw" uint8_t* pwsaltedkey = nullptr; // use the pw's hash as the "pw"
QByteArray barePassword; // to be deleted after tox_pass_key_decrypt/tox_pass_key_encrypt fix
static const int videobufsize; static const int videobufsize;
static uint8_t* videobuf; static uint8_t* videobuf;