removed debug output, add application log, improve UI
parent
db79a91afa
commit
d56ffc34e7
|
|
@ -16,13 +16,15 @@ public:
|
|||
|
||||
public slots:
|
||||
void onAppFolderSelect_click();
|
||||
void onPublicKeySelect_click();
|
||||
|
||||
void onSign_click();
|
||||
void onVerify_click();
|
||||
|
||||
void log(const QString &msg);
|
||||
|
||||
private:
|
||||
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) {
|
||||
///@todo https://github.com/noloader/cryptopp-pem
|
||||
fs::path appPath(app);
|
||||
std::cout << (appPath / KEY_FILE).string() << std::endl;
|
||||
CryptoPP::FileSink output((appPath / KEY_FILE).c_str());
|
||||
m_publicKey.DEREncode(output);
|
||||
return true;
|
||||
|
|
@ -157,7 +156,6 @@ void IntegretyCheck::signHashList(std::string &hashList) {
|
|||
signature_length =
|
||||
signer.SignMessage(rng, (const CryptoPP::byte *)hashList.c_str(),
|
||||
hashList.length(), signature);
|
||||
std::cerr << signature_length << std::endl;
|
||||
signature.resize(signature_length);
|
||||
|
||||
// transfrom binary signature to base64 encoded string
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QStandardPaths>
|
||||
#include <QTime>
|
||||
|
||||
#include <QDebug>
|
||||
#include <iostream>
|
||||
|
|
@ -20,50 +21,93 @@ AppWindow::AppWindow() : QMainWindow(nullptr), ui(new Ui::MainWindow()) {
|
|||
}
|
||||
|
||||
void AppWindow::onAppFolderSelect_click() {
|
||||
ui->btnSign->setEnabled(false);
|
||||
ui->btnVerify->setEnabled(false);
|
||||
auto basePath =
|
||||
QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first();
|
||||
QString dir = QFileDialog::getExistingDirectory(
|
||||
this, tr("Open Directory"), basePath,
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
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() {
|
||||
std::string dir = ui->txtFolderPath->text().toStdString();
|
||||
IntegretyCheck integretyCheck(dir, true);
|
||||
log("key pair is generated");
|
||||
|
||||
integretyCheck.saveKeyFile(dir);
|
||||
log("public key is saved to '" +
|
||||
QString::fromStdString(IntegretyCheck::KEY_FILE) + "'");
|
||||
|
||||
std::string hList = integretyCheck.generateHashList(dir);
|
||||
log("generated hash list");
|
||||
|
||||
integretyCheck.signHashList(hList);
|
||||
std::cout << hList << std::endl;
|
||||
log("signed generated hash list");
|
||||
|
||||
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() {
|
||||
|
||||
std::string dir = ui->txtFolderPath->text().toStdString();
|
||||
IntegretyCheck integretyCheck(dir, false);
|
||||
///@todo check for key file and create log msg
|
||||
|
||||
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;
|
||||
if (hList.empty()) {
|
||||
log("App modified, unable to load '" +
|
||||
QString::fromStdString(IntegretyCheck::HASH_FILE) + "'");
|
||||
return;
|
||||
}
|
||||
log("loaded hash file");
|
||||
|
||||
if (integretyCheck.verifyHashList(hList, newHashList)) {
|
||||
log("signature and data verified");
|
||||
} 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::fromStdString(IntegretyCheck::KEY_FILE);
|
||||
if (!QFileInfo::exists(pubKeyFile)) {
|
||||
pubKeyFile = "";
|
||||
return QFileInfo::exists(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