fix possibly #184

This commit is contained in:
Martin Rotter 2019-04-05 12:22:29 +02:00
parent aae077243b
commit 27bdad2fbb
2 changed files with 11 additions and 5 deletions

View File

@ -10,6 +10,7 @@
#include <QDir> #include <QDir>
#include <QLocale> #include <QLocale>
#include <QRandomGenerator>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
@ -124,12 +125,19 @@ quint64 TextFactory::initializeSecretEncryptionKey() {
QString encryption_file_path = qApp->settings()->pathName() + QDir::separator() + ENCRYPTION_FILE_NAME; QString encryption_file_path = qApp->settings()->pathName() + QDir::separator() + ENCRYPTION_FILE_NAME;
try { try {
s_encryptionKey = (quint64) QString(IOFactory::readFile(encryption_file_path)).toLongLong(); s_encryptionKey = quint64(QString(IOFactory::readFile(encryption_file_path)).toLongLong());
} }
catch (ApplicationException) { catch (ApplicationException) {
// Well, key does not exist or is invalid, generate and save one. // Well, key does not exist or is invalid, generate and save one.
s_encryptionKey = generateSecretEncryptionKey(); s_encryptionKey = generateSecretEncryptionKey();
IOFactory::writeFile(encryption_file_path, QString::number(s_encryptionKey).toLocal8Bit());
try {
IOFactory::writeFile(encryption_file_path, QString::number(s_encryptionKey).toLocal8Bit());
}
catch (ApplicationException& ex) {
qCritical("Failed to write newly generated encryption key to file, error '%s'. Now, your passwords won't be "
"readable after you start this application again.", qPrintable(ex.message()));
}
} }
} }
@ -137,5 +145,5 @@ quint64 TextFactory::initializeSecretEncryptionKey() {
} }
quint64 TextFactory::generateSecretEncryptionKey() { quint64 TextFactory::generateSecretEncryptionKey() {
return RAND_MAX * qrand() + qrand(); return QRandomGenerator().generate64();
} }

View File

@ -175,8 +175,6 @@ void Downloader::progressInternal(qint64 bytes_received, qint64 bytes_total) {
QList<HttpResponse> Downloader::decodeMultipartAnswer(QNetworkReply* reply) { QList<HttpResponse> Downloader::decodeMultipartAnswer(QNetworkReply* reply) {
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
IOFactory::writeFile("b.json", data);
if (data.isEmpty()) { if (data.isEmpty()) {
return QList<HttpResponse>(); return QList<HttpResponse>();
} }