|
|
|
@ -1070,6 +1070,8 @@ bool Core::loadConfiguration()
@@ -1070,6 +1070,8 @@ bool Core::loadConfiguration()
|
|
|
|
|
qWarning() << "Core: tox_load failed with error "<<error; |
|
|
|
|
} |
|
|
|
|
else if (error == 1) // Encrypted data save
|
|
|
|
|
{ |
|
|
|
|
if (!pwhash) |
|
|
|
|
{ |
|
|
|
|
qWarning() << "Core: Can not open encrypted tox save"; |
|
|
|
|
if (QMessageBox::Ok != QMessageBox::warning(nullptr, tr("Encrypted profile"), |
|
|
|
@ -1081,6 +1083,15 @@ bool Core::loadConfiguration()
@@ -1081,6 +1083,15 @@ bool Core::loadConfiguration()
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ /*
|
|
|
|
|
while (error != 0) |
|
|
|
|
{ |
|
|
|
|
error = tox_encrypted_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size(), pwhash, TOX_HASH_LENGTH); |
|
|
|
|
// something something QInputDialog new password
|
|
|
|
|
} */ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
configurationFile.close(); |
|
|
|
@ -1467,6 +1478,20 @@ QByteArray Core::encryptData(const QByteArray& data)
@@ -1467,6 +1478,20 @@ QByteArray Core::encryptData(const QByteArray& data)
|
|
|
|
|
return QByteArray(reinterpret_cast<char*>(encrypted), data.size() + tox_pass_encryption_extra_length()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QByteArray Core::decryptData(const QByteArray& data) |
|
|
|
|
{ |
|
|
|
|
if (!pwhash) |
|
|
|
|
return QByteArray(); |
|
|
|
|
int sz = data.size() - tox_pass_encryption_extra_length(); |
|
|
|
|
uint8_t decrypted[sz]; |
|
|
|
|
if (tox_pass_decrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(), pwhash, TOX_HASH_LENGTH, decrypted) != sz) |
|
|
|
|
{ |
|
|
|
|
qWarning() << "Core::decryptData: decryption failed"; |
|
|
|
|
return QByteArray(); |
|
|
|
|
} |
|
|
|
|
return QByteArray(reinterpret_cast<char*>(decrypted), sz); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Core::encryptFile(const QString& path) |
|
|
|
|
{ |
|
|
|
|
if (!pwhash) |
|
|
|
@ -1495,3 +1520,22 @@ bool Core::encryptFile(const QString& path)
@@ -1495,3 +1520,22 @@ bool Core::encryptFile(const QString& path)
|
|
|
|
|
file.close(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QByteArray Core::decryptFile(const QString& path) |
|
|
|
|
{ |
|
|
|
|
if (!pwhash) |
|
|
|
|
return QByteArray(); |
|
|
|
|
QFile file(path); |
|
|
|
|
if (!file.exists()) { |
|
|
|
|
qWarning() << "Core::decryptFile: file" << path << "DNE"; |
|
|
|
|
return QByteArray(); |
|
|
|
|
} |
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) { |
|
|
|
|
qCritical() << "Core::decryptFile:" << path << " cannot be opened"; |
|
|
|
|
return QByteArray(); |
|
|
|
|
} |
|
|
|
|
QByteArray data = file.readAll(); |
|
|
|
|
file.close(); |
|
|
|
|
|
|
|
|
|
return decryptData(data); |
|
|
|
|
} |
|
|
|
|