Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 12011ba

Browse files
committed
added qrng to generate better keys
1 parent 1d94ee3 commit 12011ba

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

src/3rdparty/qpm.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"description": "",
44
"dependencies": [
55
6-
6+
7+
78
],
89
"license": "NONE",
910
"pri_filename": "",

src/datasync/changecontroller_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Q_SLOTS:
7474
Q_SIGNALS:
7575
void loadLocalStatus();
7676
void updateSyncState(SyncController::SyncState state);
77-
void updateSyncProgress(quint32 remainingOperations);
77+
void updateSyncProgress(int remainingOperations);
7878

7979
void beginRemoteOperation(const ChangeOperation &operation);
8080
void beginLocalOperation(const ChangeOperation &operation);

src/datasync/datasync.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ HEADERS += \
3131
exceptions.h \
3232
qtdatasync_global.h \
3333
encryptor.h \
34-
qtinyaesencryptor_p.h
34+
qtinyaesencryptor_p.h
3535

3636
SOURCES += \
3737
asyncdatastore.cpp \
@@ -53,7 +53,7 @@ SOURCES += \
5353
wsremoteconnector.cpp \
5454
exceptions.cpp \
5555
encryptor.cpp \
56-
qtinyaesencryptor.cpp
56+
qtinyaesencryptor.cpp
5757

5858
OTHER_FILES += \
5959
engine.qmodel

src/datasync/qtinyaesencryptor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <QtCore/qcryptographichash.h>
66

77
#include <qtinyaes.h>
8+
#include <qrng.h>
89
using namespace QtDataSync;
910

1011
QTinyAesEncryptor::QTinyAesEncryptor(QObject *parent) :
@@ -19,8 +20,9 @@ void QTinyAesEncryptor::initialize(Defaults *defaults)
1920
_defaults = defaults;
2021
_key = _defaults->settings()->value(QStringLiteral("encryption/key")).toByteArray();
2122
if(_key.isEmpty()) {
22-
for(quint32 i = 0; i < QTinyAes::KEYSIZE; i++)
23-
_key += (char)qrand();
23+
QRng secureRng;
24+
secureRng.setSecurityLevel(QRng::HighSecurity);
25+
_key = secureRng.generateRandom(QTinyAes::KEYSIZE);
2426
_defaults->settings()->setValue(QStringLiteral("encryption/key"), _key);
2527
}
2628
}
@@ -42,9 +44,7 @@ void QTinyAesEncryptor::setKey(const QByteArray &key)
4244

4345
QJsonValue QTinyAesEncryptor::encrypt(const ObjectKey &key, const QJsonObject &object, const QByteArray &keyProperty) const
4446
{
45-
QByteArray salt;
46-
for(quint32 i = 0; i < 28; i++)//224 bits
47-
salt += (char)qrand();
47+
auto salt = QRng().generateRandom(28);//224 bits
4848
auto iv = QCryptographicHash::hash(salt + key.first + key.second.toUtf8() + keyProperty, QCryptographicHash::Sha3_224);
4949
iv.resize(QTinyAes::BLOCKSIZE);
5050

src/datasync/wsauthenticator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ WsAuthenticator::WsAuthenticator(WsRemoteConnector *connector, Defaults *default
1414
d->settings = defaults->createSettings(this);
1515

1616
connect(d->connector, &WsRemoteConnector::remoteStateChanged,
17-
this, &WsAuthenticator::updateConnected,
17+
this, [this](RemoteConnector::RemoteState s){updateConnected(s);},
1818
Qt::QueuedConnection);
1919
}
2020

@@ -132,9 +132,9 @@ RemoteConnector *WsAuthenticator::connector()
132132
return d->connector;
133133
}
134134

135-
void WsAuthenticator::updateConnected(bool connected)
135+
void WsAuthenticator::updateConnected(int connected)
136136
{
137-
d->connected = connected;
137+
d->connected = (connected != RemoteConnector::RemoteDisconnected);
138138
emit connectedChanged(connected);
139139
}
140140

src/datasync/wsauthenticator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Q_SLOTS:
8181
RemoteConnector *connector() override;
8282

8383
private Q_SLOTS:
84-
void updateConnected(bool connected);
84+
void updateConnected(int connected);
8585

8686
private:
8787
QScopedPointer<WsAuthenticatorPrivate> d;

0 commit comments

Comments
 (0)