diff --git a/resources/binaries b/resources/binaries
index 572da127b..2305d0038 160000
--- a/resources/binaries
+++ b/resources/binaries
@@ -1 +1 @@
-Subproject commit 572da127bb14842bba6f84e6315a5ecefb44ed07
+Subproject commit 2305d003830b54d1705a3bc49d3493ec96c59b2d
diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG
index 0e79879d0..1af141511 100644
--- a/resources/text/CHANGELOG
+++ b/resources/text/CHANGELOG
@@ -15,6 +15,12 @@
+ 2.5.1
+ Added:
+
+ - 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.
+
+
2.5.0
Added:
diff --git a/src/definitions/definitions.h.in b/src/definitions/definitions.h.in
index 9e568255b..adc147a8d 100755
--- a/src/definitions/definitions.h.in
+++ b/src/definitions/definitions.h.in
@@ -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"
diff --git a/src/miscellaneous/iofactory.cpp b/src/miscellaneous/iofactory.cpp
index c47db79f4..a10565eea 100755
--- a/src/miscellaneous/iofactory.cpp
+++ b/src/miscellaneous/iofactory.cpp
@@ -24,6 +24,7 @@
#include
#include
#include
+#include
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)) {
diff --git a/src/miscellaneous/iofactory.h b/src/miscellaneous/iofactory.h
index 56a054680..3331b5b06 100755
--- a/src/miscellaneous/iofactory.h
+++ b/src/miscellaneous/iofactory.h
@@ -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);
};
diff --git a/src/miscellaneous/textfactory.cpp b/src/miscellaneous/textfactory.cpp
index 219f754e9..939ad1641 100755
--- a/src/miscellaneous/textfactory.cpp
+++ b/src/miscellaneous/textfactory.cpp
@@ -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
#include
#include
+#include
+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();
+}
diff --git a/src/miscellaneous/textfactory.h b/src/miscellaneous/textfactory.h
index 458620b00..ac43064bc 100644
--- a/src/miscellaneous/textfactory.h
+++ b/src/miscellaneous/textfactory.h
@@ -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