Fixed #115.
This commit is contained in:
parent
bd5fd3455d
commit
397c8ae177
@ -1 +1 @@
|
||||
Subproject commit 572da127bb14842bba6f84e6315a5ecefb44ed07
|
||||
Subproject commit 2305d003830b54d1705a3bc49d3493ec96c59b2d
|
@ -15,6 +15,12 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<center><h2>2.5.1</h2></center>
|
||||
Added:
|
||||
<ul>
|
||||
<li><b>Key used for proxy/feed password coding is now stored in separate file. This file lies in the same directory as configuration file. If your use password-protected proxy/feeds, then make sure that NOBODY gets access to that file and your DB file in the same time.</b></li>
|
||||
</ul>
|
||||
<hr/>
|
||||
<center><h2>2.5.0</h2></center>
|
||||
Added:
|
||||
<ul>
|
||||
|
@ -85,7 +85,7 @@
|
||||
#define NOTIFICATION_ICON_SIZE 64
|
||||
#define GOOGLE_SEARCH_URL "https://www.google.com/search?q=%1&ie=utf-8&oe=utf-8"
|
||||
#define GOOGLE_SUGGEST_URL "http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=%1"
|
||||
#define DUMMY_DUMMY_DUMMY 0xaec852f1
|
||||
#define ENCRYPTION_FILE_NAME "key.private"
|
||||
|
||||
#define FEED_INITIAL_OPML_PATTERN "feeds-%1.opml"
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
IOFactory::IOFactory() {
|
||||
@ -91,6 +92,21 @@ QByteArray IOFactory::readTextFile(const QString &file_path) {
|
||||
}
|
||||
}
|
||||
|
||||
void IOFactory::writeTextFile(const QString &file_path, const QByteArray &data) {
|
||||
QFile input_file(file_path);
|
||||
QTextStream stream(&input_file);
|
||||
|
||||
if (input_file.open(QIODevice::Text | QIODevice::WriteOnly)) {
|
||||
stream << data;
|
||||
stream.flush();
|
||||
input_file.flush();
|
||||
input_file.close();
|
||||
}
|
||||
else {
|
||||
throw IOException(tr("Cannot open file '%1' for writting.").arg(QDir::toNativeSeparators(file_path)));
|
||||
}
|
||||
}
|
||||
|
||||
bool IOFactory::copyFile(const QString &source, const QString &destination) {
|
||||
if (QFile::exists(destination)) {
|
||||
if (!QFile::remove(destination)) {
|
||||
|
@ -52,6 +52,8 @@ class IOFactory {
|
||||
// Throws exception when no such file exists.
|
||||
static QByteArray readTextFile(const QString &file_path);
|
||||
|
||||
static void writeTextFile(const QString &file_path, const QByteArray &data);
|
||||
|
||||
// Copies file, overwrites destination.
|
||||
static bool copyFile(const QString &source, const QString &destination);
|
||||
};
|
||||
|
@ -18,13 +18,19 @@
|
||||
#include "miscellaneous/textfactory.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/simplecrypt/simplecrypt.h"
|
||||
#include "miscellaneous/iofactory.h"
|
||||
#include "exceptions/applicationexception.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QLocale>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
quint64 TextFactory::s_encryptionKey = 0x0;
|
||||
|
||||
TextFactory::TextFactory() {
|
||||
}
|
||||
|
||||
@ -109,12 +115,12 @@ QDateTime TextFactory::parseDateTime(qint64 milis_from_epoch) {
|
||||
return QDateTime::fromMSecsSinceEpoch(milis_from_epoch);
|
||||
}
|
||||
|
||||
QString TextFactory::encrypt(const QString &text) {
|
||||
return SimpleCrypt(DUMMY_DUMMY_DUMMY).encryptToString(text);
|
||||
QString TextFactory::encrypt(const QString &text) {
|
||||
return SimpleCrypt(initializeSecretEncryptionKey()).encryptToString(text);
|
||||
}
|
||||
|
||||
QString TextFactory::decrypt(const QString &text) {
|
||||
return SimpleCrypt(DUMMY_DUMMY_DUMMY).decryptToString(text);
|
||||
return SimpleCrypt(initializeSecretEncryptionKey()).decryptToString(text);
|
||||
}
|
||||
|
||||
QString TextFactory::shorten(const QString &input, int text_length_limit) {
|
||||
@ -125,3 +131,25 @@ QString TextFactory::shorten(const QString &input, int text_length_limit) {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
quint64 TextFactory::initializeSecretEncryptionKey() {
|
||||
if (s_encryptionKey == 0x0) {
|
||||
// Check if file with encryption key exists.
|
||||
QString encryption_file_path = qApp->settings()->pathName() + QDir::separator() + ENCRYPTION_FILE_NAME;
|
||||
|
||||
try {
|
||||
s_encryptionKey = (quint64) QString(IOFactory::readTextFile(encryption_file_path)).toLongLong();
|
||||
}
|
||||
catch (ApplicationException) {
|
||||
// Well, key does not exist or is invalid, generate and save one.
|
||||
s_encryptionKey = generateSecretEncryptionKey();
|
||||
IOFactory::writeTextFile(encryption_file_path, QString::number(s_encryptionKey).toLocal8Bit());
|
||||
}
|
||||
}
|
||||
|
||||
return s_encryptionKey;
|
||||
}
|
||||
|
||||
quint64 TextFactory::generateSecretEncryptionKey() {
|
||||
return RAND_MAX * qrand() + qrand();
|
||||
}
|
||||
|
@ -52,6 +52,12 @@ class TextFactory {
|
||||
|
||||
// Shortens input string according to given length limit.
|
||||
static QString shorten(const QString &input, int text_length_limit = TEXT_TITLE_LIMIT);
|
||||
|
||||
private:
|
||||
static quint64 initializeSecretEncryptionKey();
|
||||
static quint64 generateSecretEncryptionKey();
|
||||
|
||||
static quint64 s_encryptionKey;
|
||||
};
|
||||
|
||||
#endif // TEXTFACTORY_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user