aboutsummaryrefslogtreecommitdiff
path: root/lib/pluginloader/pluginloader.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-01-26 23:14:53 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2020-01-27 15:58:31 +0200
commit0bf5450365934c39ed0bb480712adaab2fa54386 (patch)
tree15b90e626ca7f29c9fa219addf17e9cf618b6496 /lib/pluginloader/pluginloader.cpp
parentMove compiler flags to meson.build from pkgbuild (diff)
downloadsmolbote-0bf5450365934c39ed0bb480712adaab2fa54386.tar.xz
pluginloader: add test for PluginLoader::verify
Diffstat (limited to 'lib/pluginloader/pluginloader.cpp')
-rw-r--r--lib/pluginloader/pluginloader.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/lib/pluginloader/pluginloader.cpp b/lib/pluginloader/pluginloader.cpp
index c8358bf..e5c4b89 100644
--- a/lib/pluginloader/pluginloader.cpp
+++ b/lib/pluginloader/pluginloader.cpp
@@ -12,17 +12,21 @@
#include <openssl/pem.h>
#include "publicKey.h"
-PluginLoader::PluginLoader(const QString &fileName, const VerifyState sigLevel, QObject *parent)
+PluginLoader::PluginLoader(const QString &fileName, PluginLoader::SignatureState state, QObject *parent)
: QPluginLoader(fileName, parent)
- , requiredSignatureLevel(sigLevel)
+ , m_state(state)
{
}
-PluginLoader::VerifyState PluginLoader::verify(const char *hashName) const
+bool PluginLoader::verify(const char *hashName)
{
const QString sigName = this->fileName() + ".sig";
if(!QFile::exists(sigName)) {
- return SignatureMissing;
+ if(m_state.ignored || m_state.checked)
+ return true;
+
+ m_sigError = tr("A signature is required, but none was found.");
+ return false;
}
auto *bio = BIO_new_mem_buf(publicKey_pem, publicKey_pem_len);
@@ -39,7 +43,8 @@ PluginLoader::VerifyState PluginLoader::verify(const char *hashName) const
int rc = EVP_DigestVerifyInit(ctx, NULL, md, NULL, key);
if(rc != 1) {
- return SignatureMismatched;
+ m_sigError = tr("Failed to compute signature (stage=init)");
+ return false;
}
// read plugin into DigestVerifyUpdate
@@ -53,8 +58,10 @@ PluginLoader::VerifyState PluginLoader::verify(const char *hashName) const
len -= read;
rc = EVP_DigestVerifyUpdate(ctx, buf, read);
- if(rc != 1)
- return SignatureComputeFailed;
+ if(rc != 1) {
+ m_sigError = tr("Failed to compute signature (staga=update)");
+ return false;
+ }
}
delete[] buf;
plugin.close();
@@ -74,20 +81,13 @@ PluginLoader::VerifyState PluginLoader::verify(const char *hashName) const
delete sig;
if(rc == 1)
- return SignatureMatched;
+ return true;
else {
- return SignatureMismatched;
- }
-}
-/*
-bool PluginLoader::load()
-{
- if(signature == SignatureUnverified)
- signature = this->verify();
+ if(m_state.ignored)
+ return true;
- if(signature > requiredSignatureLevel)
- return QPluginLoader::load();
- else
+ m_sigError = tr("Signature does not match");
return false;
+ }
}
-*/
+