refactor: new fingerprintdialog
This commit is contained in:
@ -80,6 +80,9 @@ add_executable(${target} WIN32 MACOSX_BUNDLE
|
||||
dialogs/AddClientDialog.cpp
|
||||
dialogs/AddClientDialog.h
|
||||
dialogs/AddClientDialog.ui
|
||||
dialogs/FingerprintDialog.h
|
||||
dialogs/FingerprintDialog.cpp
|
||||
dialogs/FingerprintDialog.ui
|
||||
dialogs/HotkeyDialog.cpp
|
||||
dialogs/HotkeyDialog.h
|
||||
dialogs/HotkeyDialog.ui
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include "ui_MainWindow.h"
|
||||
|
||||
#include "dialogs/AboutDialog.h"
|
||||
#include "dialogs/FingerprintDialog.h"
|
||||
#include "dialogs/ServerConfigDialog.h"
|
||||
#include "dialogs/SettingsDialog.h"
|
||||
|
||||
@ -25,8 +26,6 @@
|
||||
#include "gui/style_utils.h"
|
||||
#include "gui/styles.h"
|
||||
#include "net/FingerprintDatabase.h"
|
||||
#include "net/SecureUtils.h"
|
||||
|
||||
#include "platform/wayland.h"
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
@ -36,7 +35,6 @@
|
||||
#include <QApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QFont>
|
||||
#include <QLocalServer>
|
||||
#include <QLocalSocket>
|
||||
#include <QMenu>
|
||||
@ -485,31 +483,12 @@ void MainWindow::showMyFingerprint()
|
||||
return;
|
||||
}
|
||||
|
||||
QString message = QStringLiteral("\n");
|
||||
for (const auto &fingerprint : db.fingerprints()) {
|
||||
if (fingerprint.algorithm == "sha1") {
|
||||
message.append(
|
||||
QStringLiteral("\nSHA1\n%1\n").arg(QString::fromStdString(deskflow::formatSSLFingerprint(fingerprint.data)))
|
||||
);
|
||||
}
|
||||
QList<deskflow::FingerprintData> fingerprints;
|
||||
fingerprints.reserve(db.fingerprints().size());
|
||||
std::copy(db.fingerprints().begin(), db.fingerprints().end(), std::back_inserter(fingerprints));
|
||||
|
||||
if (fingerprint.algorithm == "sha256") {
|
||||
message.append(QStringLiteral("\nSHA256\n%1\n%2\n")
|
||||
.arg(
|
||||
QString::fromStdString(deskflow::formatSSLFingerprintColumns(fingerprint.data)),
|
||||
QString::fromStdString(deskflow::generateFingerprintArt(fingerprint.data))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO This dialog better in the future
|
||||
QMessageBox mbox(this);
|
||||
mbox.setWindowTitle(tr("Your Fingerprints"));
|
||||
auto font = new QFont("Monospace");
|
||||
font->setStyleHint(QFont::TypeWriter);
|
||||
mbox.setFont(*font);
|
||||
mbox.setText(message);
|
||||
mbox.exec();
|
||||
FingerprintDialog fingerprintDialog(this, fingerprints);
|
||||
fingerprintDialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::setModeServer()
|
||||
@ -722,7 +701,6 @@ void MainWindow::checkFingerprint(const QString &line)
|
||||
deskflow::string::fromHex(match.captured(2).toStdString())
|
||||
};
|
||||
|
||||
|
||||
// Only Save the sha256
|
||||
auto localPath = QStringLiteral("%1/%2").arg(getTlsPath(), kFingerprintTrustedServersFilename).toStdString();
|
||||
deskflow::FingerprintDatabase db;
|
||||
@ -731,39 +709,13 @@ void MainWindow::checkFingerprint(const QString &line)
|
||||
return;
|
||||
}
|
||||
|
||||
static bool messageBoxAlreadyShown = false;
|
||||
|
||||
if (!messageBoxAlreadyShown) {
|
||||
m_coreProcess.stop();
|
||||
|
||||
messageBoxAlreadyShown = true;
|
||||
QMessageBox::StandardButton fingerprintReply = QMessageBox::information(
|
||||
this, tr("Security question"),
|
||||
tr("<p>You are connecting to a server.</p>"
|
||||
"<p>Here is it's TLS fingerprint:</p>\n\n"
|
||||
"<p>SHA256:%1\n"
|
||||
"<p>%2\n\n"
|
||||
"<p>SHA1(Obsolete): Compare for old versions only: %3</p>"
|
||||
"<p>Compare this fingerprint to the one on your server's screen. "
|
||||
"If the two don't match exactly, then it's probably not the server "
|
||||
"you're expecting (it could be a malicious user).</p>"
|
||||
"<p>Do you want to trust this fingerprint for future "
|
||||
"connections? If you don't, a connection cannot be made.</p>")
|
||||
.arg(
|
||||
QString::fromStdString(deskflow::formatSSLFingerprint(sha256.data)),
|
||||
QString::fromStdString(deskflow::generateFingerprintArt(sha256.data)),
|
||||
QString::fromStdString(deskflow::formatSSLFingerprint(sha1.data))
|
||||
),
|
||||
QMessageBox::Yes | QMessageBox::No
|
||||
);
|
||||
|
||||
if (fingerprintReply == QMessageBox::Yes) {
|
||||
db.addTrusted(sha256);
|
||||
db.write(localPath);
|
||||
m_coreProcess.start();
|
||||
}
|
||||
|
||||
messageBoxAlreadyShown = false;
|
||||
m_coreProcess.stop();
|
||||
const QList<deskflow::FingerprintData> fingerprints{sha1, sha256};
|
||||
FingerprintDialog fingerprintDialog(this, fingerprints, FingerprintDialogMode::Remote);
|
||||
if (fingerprintDialog.exec() == QDialog::Accepted) {
|
||||
db.addTrusted(sha256);
|
||||
db.write(localPath);
|
||||
m_coreProcess.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
71
src/apps/deskflow-gui/dialogs/FingerprintDialog.cpp
Normal file
71
src/apps/deskflow-gui/dialogs/FingerprintDialog.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "FingerprintDialog.h"
|
||||
#include "ui_FingerprintDialog.h"
|
||||
|
||||
#include "net/SecureUtils.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QPushButton>
|
||||
|
||||
FingerprintDialog::FingerprintDialog(
|
||||
QWidget *parent, const QList<deskflow::FingerprintData> &fingerprints, FingerprintDialogMode mode
|
||||
)
|
||||
: QDialog(parent),
|
||||
ui{new Ui::FingerprintDialog}
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if (mode == FingerprintDialogMode::Remote) {
|
||||
setWindowTitle(tr("Security Question"));
|
||||
ui->lblBody->setText(tr("<p>You are connecting to a server.</p>"
|
||||
"<p>Compare the fingerprints below to the ones on your server. "
|
||||
"If the two don't match exactly, then it's probably not the server "
|
||||
"you're expecting (it could be a malicious user).\n</p>"));
|
||||
|
||||
ui->lblFooter->setText(tr("<p>Do you want to trust this fingerprint for future "
|
||||
"connections? If you don't, a connection cannot be made.</p>"));
|
||||
ui->buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
|
||||
connect(ui->buttonBox->button(QDialogButtonBox::Yes), &QPushButton::clicked, this, &QDialog::accept);
|
||||
connect(ui->buttonBox->button(QDialogButtonBox::No), &QPushButton::clicked, this, &QDialog::reject);
|
||||
} else {
|
||||
setWindowTitle(tr("Your Fingerprints"));
|
||||
ui->lblBody->setText(tr("These are the fingerprints for this computer"));
|
||||
ui->lblFooter->setVisible(false);
|
||||
}
|
||||
|
||||
for (const auto &fingerprint : fingerprints) {
|
||||
if (fingerprint.algorithm == "sha1") {
|
||||
ui->lblSHA1->setText(QString::fromStdString(deskflow::formatSSLFingerprint(fingerprint.data)));
|
||||
}
|
||||
|
||||
if (fingerprint.algorithm == "sha256") {
|
||||
ui->lblSHA256->setText(QString::fromStdString(deskflow::formatSSLFingerprintColumns(fingerprint.data)));
|
||||
ui->lblSha256Art->setText(QString::fromStdString(deskflow::generateFingerprintArt(fingerprint.data)));
|
||||
}
|
||||
}
|
||||
|
||||
QFont f = font();
|
||||
f.setFamilies({"Hack", "Liberation Mono", "Monospace", "Andale Mono"});
|
||||
f.setStyleHint(QFont::Monospace);
|
||||
ui->lblSha256Art->setFont(f);
|
||||
|
||||
if (ui->lblSHA1->text().isEmpty()) {
|
||||
ui->sha1Frame->setVisible(false);
|
||||
}
|
||||
|
||||
if (ui->lblSHA256->text().isEmpty()) {
|
||||
ui->sha256Frame->setVisible(false);
|
||||
}
|
||||
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
FingerprintDialog::~FingerprintDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
37
src/apps/deskflow-gui/dialogs/FingerprintDialog.h
Normal file
37
src/apps/deskflow-gui/dialogs/FingerprintDialog.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "net/FingerprintData.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
namespace Ui {
|
||||
class FingerprintDialog;
|
||||
}
|
||||
|
||||
enum FingerprintDialogMode
|
||||
{
|
||||
Local,
|
||||
Remote
|
||||
};
|
||||
|
||||
class FingerprintDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FingerprintDialog(
|
||||
QWidget *parent = nullptr, const QList<deskflow::FingerprintData> &fingerprints = {},
|
||||
FingerprintDialogMode mode = FingerprintDialogMode::Local
|
||||
);
|
||||
~FingerprintDialog();
|
||||
|
||||
private:
|
||||
Ui::FingerprintDialog *ui = nullptr;
|
||||
};
|
||||
255
src/apps/deskflow-gui/dialogs/FingerprintDialog.ui
Normal file
255
src/apps/deskflow-gui/dialogs/FingerprintDialog.ui
Normal file
@ -0,0 +1,255 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FingerprintDialog</class>
|
||||
<widget class="QDialog" name="FingerprintDialog">
|
||||
<layout class="QVBoxLayout" name="_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblBody">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>sha256Frame</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Policy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="_3">
|
||||
<item>
|
||||
<widget class="QFrame" name="sha1Frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="_4">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>SHA1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblSHA1">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>lblSHA1</string>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="sha256Frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="_5">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>SHA256</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblSHA256">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignHCenter|Qt::AlignmentFlag::AlignTop</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblSha256Art">
|
||||
<property name="text">
|
||||
<string>sha ART</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Policy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblFooter">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>FingerprintDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>FingerprintDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user