-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathWSClient.h
More file actions
223 lines (174 loc) · 8.31 KB
/
Copy pathWSClient.h
File metadata and controls
223 lines (174 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/******************************************************************************
** Copyright (c) Raoul Hecky. All Rights Reserved.
**
** Moolticute is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** Moolticute is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Foobar; if not, write to the Free Software
** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**
******************************************************************************/
#ifndef WSCLIENT_H
#define WSCLIENT_H
#include <QtCore>
#include <QWebSocket>
#include <QJsonDocument>
#include "Common.h"
#include "QtHelper.h"
class SettingsGuiHelper;
class WSClient: public QObject
{
Q_OBJECT
QT_WRITABLE_PROPERTY(bool, connected, false)
QT_WRITABLE_PROPERTY(Common::MPStatus, status, Common::UnknownStatus)
QT_WRITABLE_PROPERTY(bool, memMgmtMode, false)
QT_WRITABLE_PROPERTY(Common::MPHwVersion, mpHwVersion, Common::MP_Unknown)
QT_WRITABLE_PROPERTY(QString, fwVersion, QString())
QT_WRITABLE_PROPERTY(quint32, hwSerial, 0)
QT_WRITABLE_PROPERTY(int, hwMemory, 0)
QT_WRITABLE_PROPERTY(qint64, uid, -1)
QT_WRITABLE_PROPERTY(QString, cardId, QString())
QT_WRITABLE_PROPERTY(int, credentialsDbChangeNumber, 0)
QT_WRITABLE_PROPERTY(int, dataDbChangeNumber, 0)
QT_WRITABLE_PROPERTY(QString, mainMCUVersion, QString())
QT_WRITABLE_PROPERTY(QString, auxMCUVersion, QString())
QT_WRITABLE_PROPERTY(int, bundleVersion, 0)
QT_WRITABLE_PROPERTY(bool, advancedMenu, false)
QT_WRITABLE_PROPERTY(quint32, platformSerial, 0)
public:
explicit WSClient(QObject *parent = nullptr);
~WSClient();
void openWebsocket();
void closeWebsocket();
QJsonObject &getMemoryData() { return memData; }
QJsonArray &getFilesCache() { return filesCache; }
bool isMPMini() const;
bool isMPBLE() const;
bool isConnected() const;
bool isDeviceConnected() const;
bool isCredMirroringAvailable() const;
bool isMultipleDomainsAvailable() const;
bool requestDeviceUID(const QByteArray &key);
void sendEnterMMRequest(bool wantData = false, bool wantFido = false);
void sendLeaveMMRequest();
void sendFetchNotes();
void addOrUpdateCredential(const QString &service, const QString &login,
const QString &password, const QString &description = {});
void requestPassword(const QString &service, const QString &login);
void requestDataFile(const QString &service);
void requestDeleteDataFile(const QString &file);
void sendDataFile(const QString &service, const QByteArray &data, bool isFile = true);
void deleteDataFilesAndLeave(const QStringList &services, const QStringList ¬es);
void deleteFidoAndLeave(const QList<FidoCredential> &fidoCredentials);
void requestNote(const QString ¬eName);
void requestDeleteNoteFile(const QString ¬e);
void requestResetCard();
void requestAvailableUserNumber();
void serviceExists(bool isDatanode, const QString &service);
void sendCredentialsMM(const QJsonArray &creds);
void exportDbFile(const QString &encryption);
void importDbFile(const QByteArray &fileData, bool noDelete);
void importCSVFile(const QList<QStringList> &fileData);
void sendListFilesCacheRequest();
void sendRefreshFilesCacheRequest();
void sendPlatInfoRequest();
void sendFlashMCU();
void sendUploadBundle(QString bundleFilePath, QString password);
void sendFetchData(QString fileName, Common::FetchType fetchType);
void sendStopFetchData();
void sendGetUserCategories();
void sendSetUserCategories(const QString& cat1, const QString& cat2, const QString& cat3, const QString& cat4);
void sendUserSettingsRequest();
void sendLoadParams();
void sendBatteryRequest();
void sendBleNameRequest();
void sendCurrentCategory(int category);
void sendNiMHReconditioning(bool enableRestart, int ratedCapacity);
void sendSecurityChallenge(QString str);
void sendSetBleName(QString name);
void sendSetSerialNumber(uint serialNum);
void sendChangedParam(const QString& paramName, int value);
inline bool isFw12() const { return isFwVersion(12); }
inline bool isFw13() const { return isFwVersion(13); }
void requestBleKeyboardLayout(bool onlyCheck);
void sendLockDevice();
void sendInformLocked();
void sendInformUnlocked();
SettingsGuiHelper* settingsHelper();
bool areSettingsFetched() const { return m_settingsFetched; };
signals:
void wsConnected();
void wsDisconnected();
void memoryDataChanged();
void passwordUnlocked(const QString & service, const QString & login, const QString & password, bool success);
void credentialsUpdated(const QString & service, const QString & login, const QString & description, bool success, const QString& msg);
void showAppRequested();
void progressChanged(int total, int current, QString statusMsg);
void memcheckFinished(bool success, int freeBlocks = 0, int totalBlocks = 0);
void dataFileRequested(const QString &service, const QByteArray &data, bool success);
void dataFileSent(const QString &service, bool success);
void dataFileDeleted(const QString &service, bool success);
void credentialsExists(const QString &service, bool exists);
void dataNodeExists(const QString &service, bool exists);
void dbExported(const QByteArray &fileData, bool success);
void dbImported(bool success, QString message);
void memMgmtModeFailed(int errCode, QString errMsg);
void filesCacheChanged(bool isInSync);
void cardDbMetadataChanged(QString cardId, int credentialsDbChangeNumber, int dataDbChangeNumber);
void cardResetFinished(bool successfully);
void displayStatusWarning();
void displayDebugPlatInfo(int auxMajor, int auxMinor, int mainMajor, int mainMinor);
void displayUploadBundleResult(bool success);
void displayAvailableUsers(const QString& num);
void displayUserCategories(const QString& cat1, const QString& cat2, const QString& cat3, const QString& cat4);
void updateCurrentCategories(const QString& cat1, const QString& cat2, const QString& cat3, const QString& cat4);
void updateUserSettingsOnUI(const QJsonObject& userSettings);
void deviceConnected();
void deviceDisconnected();
void deleteDataNodesFinished();
void updateBLEDeviceLanguage(const QJsonObject& langs);
void updateBLEKeyboardLayout(const QJsonObject& layouts);
void updateBatteryPercent(int battery);
void updateChargingStatus(int charging);
void challengeResultReceived(QString result);
void challengeResultFailed();
void reconditionFinished(bool success, double dischargeTime, bool restarted);
void deleteFidoNodesFailed();
void showExportPrompt();
void displayMiniImportWarning();
void notesFetched(const QJsonArray& notes);
void noteReceived(const QString ¬e, const QByteArray &data, bool success);
void noteSaved(const QString ¬e, bool success);
void noteDeleted(bool success, const QString& note);
void fileDeleted(bool success, const QString& file);
void bleNameChanged(const QString& name);
void serialNumberChanged(bool success, int serialNumber);
public slots:
void sendJsonData(const QJsonObject &data);
void queryRandomNumbers();
void sendLoginJson(QString message, QString loginName);
void sendDomainJson(QString message, QString serviceName);
private slots:
void onWsConnected();
void onWsDisconnected();
void onWsError();
void onTextMessageReceived(const QString &message);
private:
bool isFwVersion(int version) const;
QWebSocket *wsocket = nullptr;
QJsonObject memData;
QJsonArray filesCache;
SettingsGuiHelper* m_settingsHelper = nullptr;
QTimer *randomNumTimer = nullptr;
QString HIBP_COMPROMISED_FORMAT = tr("this password has been compromised %1 times.");
bool m_settingsFetched = true;
};
#endif // WSCLIENT_H