From 728bc6457a9b25de8db1098f2df5edbcd2ccab71 Mon Sep 17 00:00:00 2001 From: Arne Schroeder Date: Sat, 7 Sep 2019 13:41:24 +0200 Subject: [PATCH] add functionality to sign and verify buttons --- inc/mainwindow.h | 4 +++- src/mainwindow.cpp | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/inc/mainwindow.h b/inc/mainwindow.h index a3cf7c3..13534f8 100644 --- a/inc/mainwindow.h +++ b/inc/mainwindow.h @@ -18,9 +18,11 @@ public slots: void onAppFolderSelect_click(); void onPublicKeySelect_click(); + void onSign_click(); + void onVerify_click(); + private: std::shared_ptr ui; const QString checkPublicKey(const QString &path); - IntegretyCheck integretyCheck; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 871d4ba..678c3f7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -16,6 +16,9 @@ AppWindow::AppWindow() : QMainWindow(nullptr), ui(new Ui::MainWindow()) { &AppWindow::onAppFolderSelect_click); connect(ui->btnSelectPublicKey, &QToolButton::clicked, this, &AppWindow::onPublicKeySelect_click); + connect(ui->btnSign, &QPushButton::clicked, this, &AppWindow::onSign_click); + connect(ui->btnVerify, &QPushButton::clicked, this, + &AppWindow::onVerify_click); } void AppWindow::onAppFolderSelect_click() { @@ -29,14 +32,6 @@ void AppWindow::onAppFolderSelect_click() { if (!pubKey.isEmpty()) { ui->txtPublicKey->setText(pubKey); } - - integretyCheck.generateKeyPair(); - integretyCheck.saveKeyFile(dir.toStdString()); - std::string hList = integretyCheck.generateHashList(dir.toStdString()); - integretyCheck.signHashList(hList); - std::cout << hList << std::endl; - - integretyCheck.verifyHashList(hList); } void AppWindow::onPublicKeySelect_click() { @@ -49,6 +44,36 @@ void AppWindow::onPublicKeySelect_click() { ui->txtPublicKey->setText(fileName); } +void AppWindow::onSign_click() { + std::string dir = ui->txtFolderPath->text().toStdString(); + IntegretyCheck integretyCheck(dir, true); + + integretyCheck.saveKeyFile(dir); + std::string hList = integretyCheck.generateHashList(dir); + integretyCheck.signHashList(hList); + std::cout << hList << std::endl; + integretyCheck.saveHashList(dir, hList); +} + +void AppWindow::onVerify_click() { + std::string dir = ui->txtFolderPath->text().toStdString(); + IntegretyCheck integretyCheck(dir, false); + + std::string newHashList, hList; + hList = integretyCheck.loadHashList(dir); + std::cout << hList << std::endl; + if (integretyCheck.verifyHashList(hList, newHashList)) { + if (integretyCheck.checkHashList(newHashList, dir)) { + std::cout << "App verified!" << std::endl; + } else { + std::cerr << "/!\\ App modified, one or more hashes invalid!" + << std::endl; + } + } else { + std::cerr << "/!\\ App modified, signature invalid!" << std::endl; + } +} + const QString AppWindow::checkPublicKey(const QString &path) { QString pubKeyFile = path + QDir::separator() + QString::fromStdString(IntegretyCheck::KEY_FILE);