removed debug output, add application log, improve UI
parent
db79a91afa
commit
d56ffc34e7
|
|
@ -16,13 +16,15 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onAppFolderSelect_click();
|
void onAppFolderSelect_click();
|
||||||
void onPublicKeySelect_click();
|
|
||||||
|
|
||||||
void onSign_click();
|
void onSign_click();
|
||||||
void onVerify_click();
|
void onVerify_click();
|
||||||
|
|
||||||
|
void log(const QString &msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Ui::MainWindow> ui;
|
std::shared_ptr<Ui::MainWindow> ui;
|
||||||
|
|
||||||
const QString checkPublicKey(const QString &path);
|
bool publicKeyAvailable(const QString &path);
|
||||||
|
bool hashFileAvailable(const QString &path);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ bool IntegretyCheck::loadKeyFile(const std::string &app) {
|
||||||
bool IntegretyCheck::saveKeyFile(const std::string &app) {
|
bool IntegretyCheck::saveKeyFile(const std::string &app) {
|
||||||
///@todo https://github.com/noloader/cryptopp-pem
|
///@todo https://github.com/noloader/cryptopp-pem
|
||||||
fs::path appPath(app);
|
fs::path appPath(app);
|
||||||
std::cout << (appPath / KEY_FILE).string() << std::endl;
|
|
||||||
CryptoPP::FileSink output((appPath / KEY_FILE).c_str());
|
CryptoPP::FileSink output((appPath / KEY_FILE).c_str());
|
||||||
m_publicKey.DEREncode(output);
|
m_publicKey.DEREncode(output);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -157,7 +156,6 @@ void IntegretyCheck::signHashList(std::string &hashList) {
|
||||||
signature_length =
|
signature_length =
|
||||||
signer.SignMessage(rng, (const CryptoPP::byte *)hashList.c_str(),
|
signer.SignMessage(rng, (const CryptoPP::byte *)hashList.c_str(),
|
||||||
hashList.length(), signature);
|
hashList.length(), signature);
|
||||||
std::cerr << signature_length << std::endl;
|
|
||||||
signature.resize(signature_length);
|
signature.resize(signature_length);
|
||||||
|
|
||||||
// transfrom binary signature to base64 encoded string
|
// transfrom binary signature to base64 encoded string
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QTime>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -20,50 +21,93 @@ AppWindow::AppWindow() : QMainWindow(nullptr), ui(new Ui::MainWindow()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppWindow::onAppFolderSelect_click() {
|
void AppWindow::onAppFolderSelect_click() {
|
||||||
|
ui->btnSign->setEnabled(false);
|
||||||
|
ui->btnVerify->setEnabled(false);
|
||||||
auto basePath =
|
auto basePath =
|
||||||
QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first();
|
QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first();
|
||||||
QString dir = QFileDialog::getExistingDirectory(
|
QString dir = QFileDialog::getExistingDirectory(
|
||||||
this, tr("Open Directory"), basePath,
|
this, tr("Open Directory"), basePath,
|
||||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||||
ui->txtFolderPath->setText(dir);
|
ui->txtFolderPath->setText(dir);
|
||||||
|
log("select AppPath '" + dir + "'");
|
||||||
|
ui->btnSign->setEnabled(true);
|
||||||
|
if (publicKeyAvailable(dir) && hashFileAvailable(dir)) {
|
||||||
|
ui->btnVerify->setEnabled(true);
|
||||||
|
log("App is already signed, public key and hashfile exist.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppWindow::onSign_click() {
|
void AppWindow::onSign_click() {
|
||||||
std::string dir = ui->txtFolderPath->text().toStdString();
|
std::string dir = ui->txtFolderPath->text().toStdString();
|
||||||
IntegretyCheck integretyCheck(dir, true);
|
IntegretyCheck integretyCheck(dir, true);
|
||||||
|
log("key pair is generated");
|
||||||
|
|
||||||
integretyCheck.saveKeyFile(dir);
|
integretyCheck.saveKeyFile(dir);
|
||||||
|
log("public key is saved to '" +
|
||||||
|
QString::fromStdString(IntegretyCheck::KEY_FILE) + "'");
|
||||||
|
|
||||||
std::string hList = integretyCheck.generateHashList(dir);
|
std::string hList = integretyCheck.generateHashList(dir);
|
||||||
|
log("generated hash list");
|
||||||
|
|
||||||
integretyCheck.signHashList(hList);
|
integretyCheck.signHashList(hList);
|
||||||
std::cout << hList << std::endl;
|
log("signed generated hash list");
|
||||||
|
|
||||||
integretyCheck.saveHashList(dir, hList);
|
integretyCheck.saveHashList(dir, hList);
|
||||||
|
log("public key is saved to '" +
|
||||||
|
QString::fromStdString(IntegretyCheck::HASH_FILE) + "'");
|
||||||
|
|
||||||
|
if (publicKeyAvailable(ui->txtFolderPath->text()) &&
|
||||||
|
hashFileAvailable(ui->txtFolderPath->text())) {
|
||||||
|
ui->btnVerify->setEnabled(true);
|
||||||
|
}
|
||||||
|
log("Application successful signed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppWindow::onVerify_click() {
|
void AppWindow::onVerify_click() {
|
||||||
|
|
||||||
std::string dir = ui->txtFolderPath->text().toStdString();
|
std::string dir = ui->txtFolderPath->text().toStdString();
|
||||||
IntegretyCheck integretyCheck(dir, false);
|
IntegretyCheck integretyCheck(dir, false);
|
||||||
|
///@todo check for key file and create log msg
|
||||||
|
|
||||||
std::string newHashList, hList;
|
std::string newHashList, hList;
|
||||||
hList = integretyCheck.loadHashList(dir);
|
hList = integretyCheck.loadHashList(dir);
|
||||||
std::cout << hList << std::endl;
|
if (hList.empty()) {
|
||||||
if (integretyCheck.verifyHashList(hList, newHashList)) {
|
log("App modified, unable to load '" +
|
||||||
if (integretyCheck.checkHashList(newHashList, dir)) {
|
QString::fromStdString(IntegretyCheck::HASH_FILE) + "'");
|
||||||
std::cout << "App verified!" << std::endl;
|
return;
|
||||||
} else {
|
|
||||||
std::cerr << "/!\\ App modified, one or more hashes invalid!"
|
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
|
log("loaded hash file");
|
||||||
|
|
||||||
|
if (integretyCheck.verifyHashList(hList, newHashList)) {
|
||||||
|
log("signature and data verified");
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "/!\\ App modified, signature invalid!" << std::endl;
|
log("App modified, signature invalid!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (integretyCheck.checkHashList(newHashList, dir)) {
|
||||||
|
log("App verified!");
|
||||||
|
} else {
|
||||||
|
log("App modified, one or more hashes invalid!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString AppWindow::checkPublicKey(const QString &path) {
|
void AppWindow::log(const QString &msg) {
|
||||||
|
QTime t = QTime::currentTime();
|
||||||
|
QString logMsg = t.toString("hh:mm:ss.zzz") + " | " + msg;
|
||||||
|
ui->listWidget->addItem(logMsg);
|
||||||
|
ui->listWidget->scrollToBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppWindow::publicKeyAvailable(const QString &path) {
|
||||||
QString pubKeyFile = path + QDir::separator() +
|
QString pubKeyFile = path + QDir::separator() +
|
||||||
QString::fromStdString(IntegretyCheck::KEY_FILE);
|
QString::fromStdString(IntegretyCheck::KEY_FILE);
|
||||||
if (!QFileInfo::exists(pubKeyFile)) {
|
return QFileInfo::exists(pubKeyFile);
|
||||||
pubKeyFile = "";
|
}
|
||||||
}
|
|
||||||
return pubKeyFile;
|
bool AppWindow::hashFileAvailable(const QString &path) {
|
||||||
|
QString hashFile = path + QDir::separator() +
|
||||||
|
QString::fromStdString(IntegretyCheck::HASH_FILE);
|
||||||
|
return QFileInfo::exists(hashFile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue