Browse Source

Merge branch 'duke' of https://github.com/myhush/silentdragon into duke

pull/140/head
Duke Leto 5 years ago
parent
commit
982c6a2d5d
  1. 1
      application.qrc
  2. 2069
      res/zec_qt_wallet_fi.ts
  3. 1
      silentdragon.pro
  4. 23
      src/connection.cpp
  5. 6
      src/mainwindow.cpp
  6. 25
      src/rpc.cpp
  7. 3
      src/scripts/dounifiedbuild.ps1
  8. 18
      src/scripts/mkmacdmg.sh
  9. 14
      src/sendtab.cpp
  10. 1
      src/settings.cpp
  11. 2
      src/version.h
  12. 169
      src/websockets.cpp
  13. 9
      src/websockets.h

1
application.qrc

@ -15,6 +15,7 @@
<qresource prefix="/translations">
<file>res/zec_qt_wallet_de.qm</file>
<file>res/zec_qt_wallet_es.qm</file>
<file>res/zec_qt_wallet_fi.qm</file>
<file>res/zec_qt_wallet_fr.qm</file>
<file>res/zec_qt_wallet_pt.qm</file>
<file>res/zec_qt_wallet_it.qm</file>

2069
res/zec_qt_wallet_fi.ts

File diff suppressed because it is too large

1
silentdragon.pro

@ -107,6 +107,7 @@ FORMS += \
TRANSLATIONS = res/zec_qt_wallet_es.ts \
res/zec_qt_wallet_fi.ts \
res/zec_qt_wallet_fr.ts \
res/zec_qt_wallet_de.ts \
res/zec_qt_wallet_pt.ts \

23
src/connection.cpp

@ -1,3 +1,5 @@
// Copyright 2019 The Hush developers
// GPLv3
#include "connection.h"
#include "mainwindow.h"
#include "settings.h"
@ -217,12 +219,13 @@ void ConnectionLoader::downloadParams(std::function<void(void)> cb) {
main->logger->write("Adding params to download queue");
// Add all the files to the download queue
downloadQueue = new QQueue<QUrl>();
client = new QNetworkAccessManager(main);
client = new QNetworkAccessManager(main);
//TODO: we never execute this
downloadQueue->enqueue(QUrl("https://z.cash/downloads/sapling-output.params"));
downloadQueue->enqueue(QUrl("https://z.cash/downloads/sapling-spend.params"));
doNextDownload(cb);
doNextDownload(cb);
}
void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
@ -586,24 +589,34 @@ QString ConnectionLoader::zcashParamsDir() {
bool ConnectionLoader::verifyParams() {
QDir paramsDir(zcashParamsDir());
// TODO: better error reporting if only 1 file exists or is missing
// TODO: do a basic size check, to filter out partial downloads and corrupt
// files from full HD's and other weird stuff
qDebug() << "Verifying sapling param files exist";
if( QFile( QDir(".").filePath("sapling-output.params") ).exists() && QFile( QDir(".").filePath("sapling-output.params") ).exists() ) {
// This list of locations to look must be kept in sync with the list in hushd
if( QFile( QDir(".").filePath("sapling-output.params") ).exists() && QFile( QDir(".").filePath("sapling-spend.params") ).exists() ) {
qDebug() << "Found params in .";
return true;
}
if( QFile( QDir("..").filePath("sapling-output.params") ).exists() && QFile( QDir("..").filePath("sapling-output.params") ).exists() ) {
if( QFile( QDir("..").filePath("sapling-output.params") ).exists() && QFile( QDir("..").filePath("sapling-spend.params") ).exists() ) {
qDebug() << "Found params in ..";
return true;
}
if( QFile( QDir("..").filePath("hush3/sapling-output.params") ).exists() && QFile( QDir("..").filePath("hush3/sapling-output.params") ).exists() ) {
if( QFile( QDir("..").filePath("hush3/sapling-output.params") ).exists() && QFile( QDir("..").filePath("hush3/sapling-spend.params") ).exists() ) {
qDebug() << "Found params in ../hush3";
return true;
}
// this is to support hushd inside a .dmg file, where the binaries are not at the root directory, but they are executed from the root dir of the .dmg
if( QFile( QDir("..").filePath("Contents/MacOS/sapling-output.params") ).exists() && QFile( QDir("..").filePath("Contents/MacOS/hush3/sapling-spend.params") ).exists() ) {
qDebug() << "Found params in ../Contents/MacOS";
return true;
}
if (QFile(paramsDir.filePath("sapling-output.params")).exists() && QFile(paramsDir.filePath("sapling-spend.params")).exists()) {
qDebug() << "Found params in " << paramsDir;
return true;

6
src/mainwindow.cpp

@ -122,6 +122,7 @@ MainWindow::MainWindow(QWidget *parent) :
setupZcashdTab();
rpc = new RPC(this);
qDebug() << "Created RPC";
restoreSavedStates();
@ -132,6 +133,7 @@ MainWindow::MainWindow(QWidget *parent) :
if (ads->getAllowInternetConnection())
wormholecode = ads->getWormholeCode(ads->getSecretHex());
qDebug() << "MainWindow: createWebsocket with wormholcode=" << wormholecode;
createWebsocket(wormholecode);
}
}
@ -142,10 +144,11 @@ void MainWindow::createWebsocket(QString wormholecode) {
// TODO: env var
bool msgDebug = true;
wsserver = new WSServer(wsport, msgDebug, this);
qDebug() << "Listening for app connections on port " << wsport;
qDebug() << "createWebsocket: Listening for app connections on port " << wsport;
if (!wormholecode.isEmpty()) {
// Connect to the wormhole service
qDebug() << "Creating WormholeClient";
wormhole = new WormholeClient(this, wormholecode);
}
}
@ -165,6 +168,7 @@ bool MainWindow::isWebsocketListening() {
}
void MainWindow::replaceWormholeClient(WormholeClient* newClient) {
qDebug() << "replacing WormholeClient";
delete wormhole;
wormhole = newClient;
}

25
src/rpc.cpp

@ -108,7 +108,7 @@ json RPC::makePayload(std::string method, std::string params) {
{"method", method },
{"params", {params}}
};
return payload;
return payload;
}
json RPC::makePayload(std::string method) {
@ -117,7 +117,7 @@ json RPC::makePayload(std::string method) {
{"id", "42" },
{"method", method },
};
return payload;
return payload;
}
void RPC::getTAddresses(const std::function<void(json)>& cb) {
@ -961,35 +961,34 @@ void RPC::watchTxStatus() {
return noConnection();
// Make an RPC to load pending operation statues
json payload = {
{"jsonrpc", "1.0"},
{"id", "someid"},
{"method", "z_getoperationstatus"},
};
conn->doRPCIgnoreError(payload, [=] (const json& reply) {
conn->doRPCIgnoreError(makePayload("z_getoperationstatus"), [=] (const json& reply) {
// conn->doRPCIgnoreError(payload, [=] (const json& reply) {
// There's an array for each item in the status
for (auto& it : reply.get<json::array_t>()) {
// If we were watching this Tx and its status became "success", then we'll show a status bar alert
QString id = QString::fromStdString(it["id"]);
if (watchingOps.contains(id)) {
// log any txs we are watching
// "creation_time": 1515969376,
// "execution_secs": 50.416337,
// And if it ended up successful
QString status = QString::fromStdString(it["status"]);
main->loadingLabel->setVisible(false);
if (status == "success") {
auto txid = QString::fromStdString(it["result"]["txid"]);
SentTxStore::addToSentTx(watchingOps[id].tx, txid);
auto wtx = watchingOps[id];
watchingOps.remove(id);
wtx.completed(id, txid);
// Refresh balances to show unconfirmed balances
qDebug() << "opid "<< id << " started at "<<QString::number((unsigned int)it["creation_time"])<<" took " << QString::number((double)it["execution_secs"]) << " seconds";
// Refresh balances to show unconfirmed balances
refresh(true);
} else if (status == "failed") {
// If it failed, then we'll actually show a warning.
// If it failed, then we'll actually show a warning.
auto errorMsg = QString::fromStdString(it["error"]["message"]);
auto wtx = watchingOps[id];
@ -1010,7 +1009,7 @@ void RPC::watchTxStatus() {
main->loadingLabel->setVisible(false);
} else {
main->loadingLabel->setVisible(true);
main->loadingLabel->setToolTip(QString::number(watchingOps.size()) + QObject::tr(" tx computing. This can take several minutes."));
main->loadingLabel->setToolTip(QString::number(watchingOps.size()) + QObject::tr(" transaction computing."));
}
});
}

3
src/scripts/dounifiedbuild.ps1

@ -2,6 +2,7 @@
param (
[Parameter(Mandatory=$true)][string]$version,
[Parameter(Mandatory=$true)][string]$prev,
[Parameter(Mandatory=$true)][string]$certificate,
[Parameter(Mandatory=$true)][string]$server,
[Parameter(Mandatory=$true)][string]$winserver
)
@ -27,7 +28,7 @@ Write-Host ""
Write-Host "[Building on Mac]"
bash src/scripts/mkmacdmg.sh --qt_path ~/Qt/5.11.1/clang_64/ --version $version --zcash_path ~/github/zcash
bash src/scripts/mkmacdmg.sh --qt_path ~/Qt/5.11.1/clang_64/ --version $version --zcash_path ~/gi/hush3 --certificate "$certificate"
if (! $?) {
Write-Output "[Error]"
exit 1;

18
src/scripts/mkmacdmg.sh

@ -17,6 +17,11 @@ case $key in
shift # past argument
shift # past value
;;
-c|--certificate)
CERTIFICATE="$2"
shift # past argument
shift # past value
;;
-v|--version)
APP_VERSION="$2"
shift # past argument
@ -40,6 +45,11 @@ if [ -z $HUSH_DIR ]; then
exit 1;
fi
if [ -z "$CERTIFICATE" ]; then
echo "CERTIFICATE is not set. Please set it the name of the MacOS developer certificate to sign the binary with";
exit 1;
fi
if [ -z $APP_VERSION ]; then
echo "APP_VERSION is not set. Please set it to the current release version of the app";
exit 1;
@ -85,10 +95,18 @@ cp $HUSH_DIR/src/hush-cli silentdragon.app/Contents/MacOS/
cp $HUSH_DIR/src/komodod silentdragon.app/Contents/MacOS/
cp $HUSH_DIR/src/komodo-cli silentdragon.app/Contents/MacOS/
$QT_PATH/bin/macdeployqt silentdragon.app
codesign --deep --force --verify --verbose -s "$CERTIFICATE" --options runtime --timestamp silentdragon.app
echo "[OK]"
# Code Signing Note:
# On MacOS, you still need to run these 3 commands:
# xcrun altool --notarize-app -t osx -f macOS-zecwallet-v0.8.0.dmg --primary-bundle-id="com.yourcompany.zecwallet" -u "apple developer id@email.com" -p "one time password"
# xcrun altool --notarization-info <output from pervious command> -u "apple developer id@email.com" -p "one time password"
#...wait for the notarization to finish...
# xcrun stapler staple macOS-zecwallet-v0.8.0.dmg
echo -n "Building dmg..........."
<<<<<<< HEAD
mv silentdragon.app silentdragon.app
create-dmg --volname "silentdragon-v$APP_VERSION" --volicon "res/logo.icns" --window-pos 200 120 --icon "silentdragon.app" 200 190 --app-drop-link 600 185 --hide-extension "silentdragon.app" --window-size 800 400 --hdiutil-quiet --background res/dmgbg.png artifacts/macOS-silentdragon-v$APP_VERSION.dmg silentdragon.app >/dev/null 2>&1

14
src/sendtab.cpp

@ -1,3 +1,4 @@
// Copyright 2019 The Hush developers
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "addressbook.h"
@ -705,27 +706,28 @@ void MainWindow::sendButton() {
// abort the Tx
return;
}
// Show a dialog to confirm the Tx
if (confirmTx(tx)) {
// And send the Tx
rpc->executeTransaction(tx,
rpc->executeTransaction(tx,
[=] (QString opid) {
ui->statusBar->showMessage(tr("Computing Tx: ") % opid);
ui->statusBar->showMessage(tr("Computing transaction: ") % opid);
qDebug() << "Computing opid: " << opid;
},
[=] (QString, QString txid) {
ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid);
},
[=] (QString opid, QString errStr) {
ui->statusBar->showMessage(QObject::tr(" Tx ") % opid % QObject::tr(" failed"), 15 * 1000);
ui->statusBar->showMessage(QObject::tr(" Transaction ") % opid % QObject::tr(" failed"), 15 * 1000);
if (!opid.isEmpty())
errStr = QObject::tr("The transaction with id ") % opid % QObject::tr(" failed. The error was") + ":\n\n" + errStr;
QMessageBox::critical(this, QObject::tr("Transaction Error"), errStr, QMessageBox::Ok);
QMessageBox::critical(this, QObject::tr("Transaction Error"), errStr, QMessageBox::Ok);
}
);
}
}
}
QString MainWindow::doSendTxValidations(Tx tx) {

1
src/settings.cpp

@ -1,3 +1,4 @@
// Copyright 2019 The Hush developers
#include "mainwindow.h"
#include "settings.h"

2
src/version.h

@ -1 +1 @@
#define APP_VERSION "0.8.2"
#define APP_VERSION "0.8.3"

169
src/websockets.cpp

@ -1,3 +1,4 @@
// Copyright 2019 The Hush developers
#include "websockets.h"
#include "rpc.h"
@ -5,7 +6,7 @@
#include "ui_mobileappconnector.h"
#include "version.h"
// Weap the sendTextMessage to check if the connection is valid and that the parent WebServer didn't close this connection
// Wrap the sendTextMessage to check if the connection is valid and that the parent WebServer didn't close this connection
// for some reason.
void ClientWebSocket::sendTextMessage(QString m) {
if (client) {
@ -36,13 +37,15 @@ WSServer::WSServer(quint16 port, bool debug, QObject *parent) :
WSServer::~WSServer()
{
qDebug() << "Closing websocket";
qDebug() << "Closing websocket server";
m_pWebSocketServer->close();
qDeleteAll(m_clients.begin(), m_clients.end());
qDebug() << "Deleted all websocket clients";
}
void WSServer::onNewConnection()
{
qDebug() << "Websocket server: new connection";
QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
connect(pSocket, &QWebSocket::textMessageReceived, this, &WSServer::processTextMessage);
@ -90,34 +93,76 @@ WormholeClient::WormholeClient(MainWindow* p, QString wormholeCode) {
this->parent = p;
this->code = wormholeCode;
connect();
qDebug() << "New wormhole client after connect()";
}
WormholeClient::~WormholeClient() {
qDebug() << "WormholeClient destructor";
shuttingDown = true;
if (m_webSocket->isValid()) {
if (m_webSocket && m_webSocket->isValid()) {
qDebug() << "Wormhole closing!";
m_webSocket->close();
}
if (timer)
if (timer) {
qDebug() << "Wormhole timer stopping";
timer->stop();
}
qDebug() << "Wormhole client destroyed";
delete timer;
qDebug() << "Wormhole timer deleted";
}
void ws_error() {
qDebug() << "websocket error!";
}
void WormholeClient::sslerrors(const QList<QSslError> &)
{
qDebug() << "SSL errors occurred!";
//TODO: don't do this in prod
//m_webSocket->ignoreSslErrors();
}
void WormholeClient::connect() {
qDebug() << "Wormhole::connect";
delete m_webSocket;
m_webSocket = new QWebSocket();
QUrl wormhole = QUrl("wss://wormhole.myhush.org:443");
if (m_webSocket) {
QObject::connect(m_webSocket, &QWebSocket::connected, this, &WormholeClient::onConnected);
QObject::connect(m_webSocket, &QWebSocket::disconnected, this, &WormholeClient::closed);
QObject::connect(m_webSocket, QOverload<const QList<QSslError>&>::of(&QWebSocket::sslErrors), this, &WormholeClient::sslerrors);
qDebug() << "Opening connection to the SilentDragonWormhole";
m_webSocket->open(wormhole);
qDebug() << "Opened connection to " << wormhole;
//TODO: use env var to over-ride
//m_webSocket->open(QUrl("ws://127.0.0.1:7070"));
} else {
qDebug() << "Invalid websocket object!";
}
}
QObject::connect(m_webSocket, &QWebSocket::connected, this, &WormholeClient::onConnected);
QObject::connect(m_webSocket, &QWebSocket::disconnected, this, &WormholeClient::closed);
m_webSocket->open(QUrl("wss://wormhole.myhush.org:443"));
//TODO: use env var to over-ride
//m_webSocket->open(QUrl("ws://127.0.0.1:7070"));
void WormholeClient::retryConnect() {
QTimer::singleShot(5 * 1000 * pow(2, retryCount), [=]() {
if (retryCount < 10) {
qDebug() << "Retrying websocket connection, count=" << this->retryCount;
this->retryCount++;
connect();
} else {
qDebug() << "Retry count exceeded, will not attempt retry any more";
}
});
}
void WormholeClient::retryConnect() {
/*
void WormholeClient::retryConnect() {
int max_retries = 10;
qDebug() << "Websocket retryConnect, retryCount=" << retryCount;
@ -135,6 +180,7 @@ void WormholeClient::retryConnect() {
qDebug() << "Invalid retryCount=" << retryCount << " detected!";
}
}
*/
// Called when the websocket is closed. If this was closed without our explicitly closing it,
// then we need to try and reconnect
@ -147,30 +193,36 @@ void WormholeClient::closed() {
void WormholeClient::onConnected()
{
qDebug() << "WebSocket connected";
retryCount = 0;
QObject::connect(m_webSocket, &QWebSocket::textMessageReceived,
this, &WormholeClient::onTextMessageReceived);
auto payload = QJsonDocument( QJsonObject {
{"register", code}
}).toJson();
m_webSocket->sendTextMessage(payload);
// On connected, we'll also create a timer to ping it every 4 minutes, since the websocket
// will timeout after 5 minutes
timer = new QTimer(parent);
QObject::connect(timer, &QTimer::timeout, [=]() {
if (!shuttingDown && m_webSocket->isValid()) {
auto payload = QJsonDocument(QJsonObject { {"ping", "ping"} }).toJson();
qint64 bytes = m_webSocket->sendTextMessage(payload);
qDebug() << "Sent ping, " << bytes << " bytes";
}
});
qDebug() << "Starting timer";
timer->start(4 * 60 * 1000); // 4 minutes
qDebug() << "WebSocket connected, retryCount=" << retryCount;
QObject::connect(m_webSocket, &QWebSocket::textMessageReceived, this, &WormholeClient::onTextMessageReceived);
auto payload = QJsonDocument( QJsonObject { {"register", code} }).toJson();
qDebug() << "Sending register";
if (m_webSocket && m_webSocket->isValid()) {
m_webSocket->sendTextMessage(payload);
qDebug() << "Sent registration message with code=" << code;
// On connected, we'll also create a timer to ping it every 4 minutes, since the websocket
// will timeout after 5 minutes
timer = new QTimer(parent);
qDebug() << "Created QTimer";
QObject::connect(timer, &QTimer::timeout, [=]() {
qDebug() << "Timer timeout!";
if (!shuttingDown && m_webSocket && m_webSocket->isValid()) {
auto payload = QJsonDocument(QJsonObject { {"ping", "ping"} }).toJson();
qint64 bytes = m_webSocket->sendTextMessage(payload);
qDebug() << "Sent ping, " << bytes << " bytes";
}
});
unsigned int interval = 4*60*1000;
timer->start(interval); // 4 minutes
qDebug() << "Started timer with interval=" << interval;
} else {
qDebug() << "Invalid websocket object onConnected!";
}
}
void WormholeClient::onTextMessageReceived(QString message)
@ -183,11 +235,12 @@ void WormholeClient::onTextMessageReceived(QString message)
// ==============================
// AppDataServer
// ==============================
AppDataServer* AppDataServer::instance = nullptr;
AppDataServer* AppDataServer::instance = nullptr;
QString AppDataServer::getWormholeCode(QString secretHex) {
qDebug() << "AppDataServer::getWormholeCode";
unsigned char* secret = new unsigned char[crypto_secretbox_KEYBYTES];
sodium_hex2bin(secret, crypto_secretbox_KEYBYTES, secretHex.toStdString().c_str(), crypto_secretbox_KEYBYTES*2,
sodium_hex2bin(secret, crypto_secretbox_KEYBYTES, secretHex.toStdString().c_str(), crypto_secretbox_KEYBYTES*2,
NULL, NULL, NULL);
unsigned char* out1 = new unsigned char[crypto_hash_sha256_BYTES];
@ -197,7 +250,7 @@ QString AppDataServer::getWormholeCode(QString secretHex) {
crypto_hash_sha256(out2, out1, crypto_hash_sha256_BYTES);
char* wmcode = new char[crypto_hash_sha256_BYTES*2 + 1];
sodium_bin2hex(wmcode, crypto_hash_sha256_BYTES*2 + 1, out2, crypto_hash_sha256_BYTES);
sodium_bin2hex(wmcode, crypto_hash_sha256_BYTES*2 + 1, out2, crypto_hash_sha256_BYTES);
QString wmcodehex(wmcode);
@ -206,7 +259,7 @@ QString AppDataServer::getWormholeCode(QString secretHex) {
delete[] out1;
delete[] secret;
qDebug() << "Created wormhole secretHex";
qDebug() << "Created wormhole secretHex=" << wmcodehex;
return wmcodehex;
}
@ -265,17 +318,18 @@ void AppDataServer::connectAppDialog(MainWindow* parent) {
ui = new Ui_MobileAppConnector();
ui->setupUi(&d);
Settings::saveRestore(&d);
qDebug() << "connectAppDialog";
updateUIWithNewQRCode(parent);
updateConnectedUI();
QObject::connect(ui->btnDisconnect, &QPushButton::clicked, [=] () {
qDebug() << "Disconnecting";
QSettings().setValue("mobileapp/connectedname", "");
saveNewSecret("");
updateConnectedUI();
});
QObject::connect(ui->txtConnStr, &QLineEdit::cursorPositionChanged, [=](int, int) {
ui->txtConnStr->selectAll();
});
@ -284,33 +338,39 @@ void AppDataServer::connectAppDialog(MainWindow* parent) {
if (state == Qt::Checked) {
}
qDebug() << "Updating QR";
updateUIWithNewQRCode(parent);
});
// If we're not listening for the app, then start the websockets
if (!parent->isWebsocketListening()) {
qDebug() << "websocket not listening";
QString wormholecode = "";
if (getAllowInternetConnection())
if (getAllowInternetConnection()) {
wormholecode = AppDataServer::getInstance()->getWormholeCode(AppDataServer::getInstance()->getSecretHex());
qDebug() << "Generated wormholecode=" << wormholecode;
}
parent->createWebsocket(wormholecode);
} else {
qDebug() << "no websocket not listening";
}
d.exec();
// If there is nothing connected when the dialog exits, then shutdown the websockets
if (!isAppConnected()) {
qDebug() << "no app connected, stopping websockets";
parent->stopWebsocket();
}
// Cleanup
tempSecret = "";
delete tempWormholeClient;
tempWormholeClient = nullptr;
delete ui;
ui = nullptr;
qDebug() << "Destroyed tempWormholeClient and ui";
}
void AppDataServer::updateUIWithNewQRCode(MainWindow* mainwindow) {
@ -329,9 +389,9 @@ void AppDataServer::updateUIWithNewQRCode(MainWindow* mainwindow) {
if (ipv4Addr.isEmpty())
return;
QString uri = "ws://" + ipv4Addr + ":8777";
qDebug() << "Websocket URI: " << uri;
qDebug() << "Websocket URI: " << uri;
// Get a new secret
unsigned char* secretBin = new unsigned char[crypto_secretbox_KEYBYTES];
@ -350,10 +410,11 @@ void AppDataServer::updateUIWithNewQRCode(MainWindow* mainwindow) {
ui->qrcode->setQrcodeString(codeStr);
ui->txtConnStr->setText(codeStr);
qDebug() << "New QR="<<codeStr;
}
void AppDataServer::registerNewTempSecret(QString tmpSecretHex, bool allowInternet, MainWindow* main) {
qDebug() << "Registering new tempSecret, allowInternet=" << allowInternet;
qDebug() << "Registering new tempSecret, allowInternet=" << allowInternet;
tempSecret = tmpSecretHex;
delete tempWormholeClient;
@ -361,8 +422,8 @@ void AppDataServer::registerNewTempSecret(QString tmpSecretHex, bool allowIntern
if (allowInternet) {
tempWormholeClient = new WormholeClient(main, getWormholeCode(tempSecret));
qDebug() << "Created new wormhole client";
}
qDebug() << "Created new wormhole client";
}
}
QString AppDataServer::connDesc(AppConnectionType t) {
@ -415,6 +476,7 @@ void AppDataServer::saveNonceHex(NonceType nt, QString noncehex) {
// Encrypt an outgoing message with the stored secret key.
QString AppDataServer::encryptOutgoing(QString msg) {
qDebug() << "Encrypting msg";
if (msg.length() % 256 > 0) {
msg = msg + QString(" ").repeated(256 - (msg.length() % 256));
}
@ -454,7 +516,6 @@ QString AppDataServer::encryptOutgoing(QString msg) {
{"payload", QString(encryptedHex)},
{"to", getWormholeCode(getSecretHex())}
});
delete[] noncebin;
delete[] newLocalNonce;
delete[] secret;
@ -470,6 +531,7 @@ QString AppDataServer::encryptOutgoing(QString msg) {
unless the skipNonceCheck = true, which is used when attempting decrtption with a temp secret key.
*/
QString AppDataServer::decryptMessage(QJsonDocument msg, QString secretHex, QString lastRemoteNonceHex) {
qDebug() << "Decrypting message";
// Decrypt and then process
QString noncehex = msg.object().value("nonce").toString();
QString encryptedhex = msg.object().value("payload").toString();
@ -531,12 +593,15 @@ QString AppDataServer::decryptMessage(QJsonDocument msg, QString secretHex, QStr
delete[] noncebin;
delete[] encrypted;
delete[] decrypted;
qDebug() << "Returning decrypted payload="<<payload;
return payload;
}
// Process an incoming text message. The message has to be encrypted with the secret key (or the temporary secret key)
void AppDataServer::processMessage(QString message, MainWindow* mainWindow, std::shared_ptr<ClientWebSocket> pClient, AppConnectionType connType) {
qDebug() << "processMessage message";
//qDebug() << "processMessage message=" << message; // this can log sensitive info
auto replyWithError = [=]() {
auto r = QJsonDocument(QJsonObject{
{"error", "Encryption error"},
@ -620,6 +685,7 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, std:
// Decrypted method will be executed here.
void AppDataServer::processDecryptedMessage(QString message, MainWindow* mainWindow, std::shared_ptr<ClientWebSocket> pClient) {
//qDebug() << "processDecryptedMessage message=" << message;
// First, extract the command from the message
auto msg = QJsonDocument::fromJson(message.toUtf8());
@ -652,7 +718,7 @@ void AppDataServer::processDecryptedMessage(QString message, MainWindow* mainWin
// "sendTx" command. This method will actually send money, so be careful with everything
void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, std::shared_ptr<ClientWebSocket> pClient) {
qDebug() << "processSendTx";
qDebug() << "processSendTx with to=" << sendTx["to"].toString();
auto error = [=](QString reason) {
auto r = QJsonDocument(QJsonObject{
{"errorCode", -1},
@ -681,6 +747,7 @@ void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, st
if (Settings::getInstance()->isSproutAddress(i))
continue;
// Filter out balances that don't have the requisite amount
// TODO: should this be amt+tx.fee?
if (allBalances->value(i) < amt)
continue;

9
src/websockets.h

@ -64,15 +64,14 @@ public:
void connect();
void retryConnect();
void sslerrors(const QList<QSslError> &);
private:
MainWindow* parent = nullptr;
MainWindow* parent = nullptr;
QWebSocket* m_webSocket = nullptr;
QTimer* timer = nullptr;
QString code;
int retryCount = 0;
unsigned int retryCount = 0;
bool shuttingDown = false;
};
@ -175,4 +174,4 @@ private:
#endif // WEBSOCKETS_H
#endif // WEBSOCKETS_H

Loading…
Cancel
Save