Allow internet connections checkbox
This commit is contained in:
@@ -106,18 +106,25 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
restoreSavedStates();
|
restoreSavedStates();
|
||||||
|
|
||||||
if (AppDataServer::getInstance()->isAppConnected()) {
|
if (AppDataServer::getInstance()->isAppConnected()) {
|
||||||
createWebsocket();
|
auto ads = AppDataServer::getInstance();
|
||||||
|
|
||||||
|
QString wormholecode = "";
|
||||||
|
if (ads->getAllowInternetConnection())
|
||||||
|
wormholecode = ads->getWormholeCode(ads->getSecretHex());
|
||||||
|
|
||||||
|
createWebsocket(wormholecode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createWebsocket() {
|
void MainWindow::createWebsocket(QString wormholecode) {
|
||||||
qDebug() << "Listening for app connections on port 8237";
|
qDebug() << "Listening for app connections on port 8237";
|
||||||
// Create the websocket server, for listening to direct connections
|
// Create the websocket server, for listening to direct connections
|
||||||
wsserver = new WSServer(8237, false, this);
|
wsserver = new WSServer(8237, false, this);
|
||||||
|
|
||||||
// Connect to the wormhole service
|
if (!wormholecode.isEmpty()) {
|
||||||
wormhole = new WormholeClient(this, AppDataServer::getInstance()->getWormholeCode(
|
// Connect to the wormhole service
|
||||||
AppDataServer::getInstance()->getSecretHex()));
|
wormhole = new WormholeClient(this, wormholecode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::stopWebsocket() {
|
void MainWindow::stopWebsocket() {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
|
|
||||||
void replaceWormholeClient(WormholeClient* newClient);
|
void replaceWormholeClient(WormholeClient* newClient);
|
||||||
bool isWebsocketListening();
|
bool isWebsocketListening();
|
||||||
void createWebsocket();
|
void createWebsocket(QString wormholecode);
|
||||||
void stopWebsocket();
|
void stopWebsocket();
|
||||||
|
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>532</width>
|
<width>800</width>
|
||||||
<height>400</height>
|
<height>530</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -43,6 +43,25 @@
|
|||||||
<string>QR Code</string>
|
<string>QR Code</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Connection String</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLineEdit" name="txtConnStr">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>9</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QRCodeLabel" name="qrcode">
|
<widget class="QRCodeLabel" name="qrcode">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@@ -59,17 +78,10 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QCheckBox" name="chkInternetConn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Connection String</string>
|
<string>Allow connections over the internet</string>
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLineEdit" name="txtConnStr">
|
|
||||||
<property name="readOnly">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -117,12 +117,6 @@ void WormholeClient::onTextMessageReceived(QString message)
|
|||||||
// ==============================
|
// ==============================
|
||||||
AppDataServer* AppDataServer::instance = nullptr;
|
AppDataServer* AppDataServer::instance = nullptr;
|
||||||
|
|
||||||
QString AppDataServer::getSecretHex() {
|
|
||||||
QSettings s;
|
|
||||||
|
|
||||||
return s.value("mobileapp/secret", "").toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString AppDataServer::getWormholeCode(QString secretHex) {
|
QString AppDataServer::getWormholeCode(QString secretHex) {
|
||||||
unsigned char* secret = new unsigned char[crypto_secretbox_KEYBYTES];
|
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,
|
||||||
@@ -147,11 +141,25 @@ QString AppDataServer::getWormholeCode(QString secretHex) {
|
|||||||
return wmcodehex;
|
return wmcodehex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppDataServer::saveNewSecret(QString secretHex) {
|
QString AppDataServer::getSecretHex() {
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.setValue("mobileapp/secret", secretHex);
|
|
||||||
|
|
||||||
s.sync();
|
return s.value("mobileapp/secret", "").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppDataServer::saveNewSecret(QString secretHex) {
|
||||||
|
QSettings().setValue("mobileapp/secret", secretHex);
|
||||||
|
|
||||||
|
if (secretHex.isEmpty())
|
||||||
|
setAllowInternetConnection(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppDataServer::getAllowInternetConnection() {
|
||||||
|
return QSettings().value("mobileapp/allowinternet", false).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppDataServer::setAllowInternetConnection(bool allow) {
|
||||||
|
QSettings().setValue("mobileapp/allowinternet", allow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppDataServer::saveLastConnectedOver(AppConnectionType type) {
|
void AppDataServer::saveLastConnectedOver(AppConnectionType type) {
|
||||||
@@ -203,9 +211,20 @@ void AppDataServer::connectAppDialog(MainWindow* parent) {
|
|||||||
ui->txtConnStr->selectAll();
|
ui->txtConnStr->selectAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QObject::connect(ui->chkInternetConn, &QCheckBox::stateChanged, [=] (int state) {
|
||||||
|
if (state == Qt::Checked) {
|
||||||
|
|
||||||
|
}
|
||||||
|
updateUIWithNewQRCode(parent);
|
||||||
|
});
|
||||||
|
|
||||||
// If we're not listening for the app, then start the websockets
|
// If we're not listening for the app, then start the websockets
|
||||||
if (!parent->isWebsocketListening()) {
|
if (!parent->isWebsocketListening()) {
|
||||||
parent->createWebsocket();
|
QString wormholecode = "";
|
||||||
|
if (getAllowInternetConnection())
|
||||||
|
wormholecode = AppDataServer::getInstance()->getWormholeCode(AppDataServer::getInstance()->getSecretHex());
|
||||||
|
|
||||||
|
parent->createWebsocket(wormholecode);
|
||||||
}
|
}
|
||||||
|
|
||||||
d.exec();
|
d.exec();
|
||||||
@@ -217,7 +236,10 @@ void AppDataServer::connectAppDialog(MainWindow* parent) {
|
|||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
tempSecret = "";
|
tempSecret = "";
|
||||||
|
|
||||||
delete tempWormholeClient;
|
delete tempWormholeClient;
|
||||||
|
tempWormholeClient = nullptr;
|
||||||
|
|
||||||
delete ui;
|
delete ui;
|
||||||
ui = nullptr;
|
ui = nullptr;
|
||||||
}
|
}
|
||||||
@@ -248,18 +270,26 @@ void AppDataServer::updateUIWithNewQRCode(MainWindow* mainwindow) {
|
|||||||
sodium_bin2hex(secretHex, crypto_secretbox_KEYBYTES*2+1, secretBin, crypto_secretbox_KEYBYTES);
|
sodium_bin2hex(secretHex, crypto_secretbox_KEYBYTES*2+1, secretBin, crypto_secretbox_KEYBYTES);
|
||||||
|
|
||||||
QString secretStr(secretHex);
|
QString secretStr(secretHex);
|
||||||
registerNewTempSecret(secretStr, mainwindow);
|
|
||||||
|
|
||||||
QString codeStr = uri + "," + secretStr;
|
QString codeStr = uri + "," + secretStr;
|
||||||
|
|
||||||
|
if (ui->chkInternetConn->isChecked()) {
|
||||||
|
codeStr = codeStr + ",1";
|
||||||
|
}
|
||||||
|
|
||||||
|
registerNewTempSecret(secretStr, ui->chkInternetConn->isChecked(), mainwindow);
|
||||||
|
|
||||||
ui->qrcode->setQrcodeString(codeStr);
|
ui->qrcode->setQrcodeString(codeStr);
|
||||||
ui->txtConnStr->setText(codeStr);
|
ui->txtConnStr->setText(codeStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppDataServer::registerNewTempSecret(QString tmpSecretHex, MainWindow* main) {
|
void AppDataServer::registerNewTempSecret(QString tmpSecretHex, bool allowInternet, MainWindow* main) {
|
||||||
tempSecret = tmpSecretHex;
|
tempSecret = tmpSecretHex;
|
||||||
|
|
||||||
tempWormholeClient = new WormholeClient(main, getWormholeCode(tempSecret));
|
delete tempWormholeClient;
|
||||||
|
tempWormholeClient = nullptr;
|
||||||
|
|
||||||
|
if (allowInternet)
|
||||||
|
tempWormholeClient = new WormholeClient(main, getWormholeCode(tempSecret));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AppDataServer::connDesc(AppConnectionType t) {
|
QString AppDataServer::connDesc(AppConnectionType t) {
|
||||||
@@ -473,6 +503,7 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
|
|||||||
// This is a new connection. So, update the the secret. Note the last seen remote nonce has already been updated by
|
// This is a new connection. So, update the the secret. Note the last seen remote nonce has already been updated by
|
||||||
// decryptMessage()
|
// decryptMessage()
|
||||||
saveNewSecret(tempSecret);
|
saveNewSecret(tempSecret);
|
||||||
|
setAllowInternetConnection(tempWormholeClient != nullptr);
|
||||||
|
|
||||||
// Swap out the wormhole connection
|
// Swap out the wormhole connection
|
||||||
mainWindow->replaceWormholeClient(tempWormholeClient);
|
mainWindow->replaceWormholeClient(tempWormholeClient);
|
||||||
|
|||||||
@@ -91,11 +91,14 @@ public:
|
|||||||
QString getSecretHex();
|
QString getSecretHex();
|
||||||
void saveNewSecret(QString secretHex);
|
void saveNewSecret(QString secretHex);
|
||||||
|
|
||||||
void registerNewTempSecret(QString tmpSecretHex, MainWindow* main);
|
void registerNewTempSecret(QString tmpSecretHex, bool allowInternet, MainWindow* main);
|
||||||
|
|
||||||
QString getNonceHex(NonceType nt);
|
QString getNonceHex(NonceType nt);
|
||||||
void saveNonceHex(NonceType nt, QString noncehex);
|
void saveNonceHex(NonceType nt, QString noncehex);
|
||||||
|
|
||||||
|
bool getAllowInternetConnection();
|
||||||
|
void setAllowInternetConnection(bool allow);
|
||||||
|
|
||||||
void saveLastSeenTime();
|
void saveLastSeenTime();
|
||||||
QDateTime getLastSeenTime();
|
QDateTime getLastSeenTime();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user