aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/gpg/GpgContext.h25
-rwxr-xr-xinclude/ui/FileEncryptionDialog.h2
-rwxr-xr-xinclude/ui/KeyMgmt.h2
-rw-r--r--include/ui/KeyServerImportDialog.h2
-rwxr-xr-xinclude/ui/SettingsDialog.h2
-rw-r--r--include/ui/VerifyKeyDetailBox.h2
-rw-r--r--include/ui/widgets/KeyList.h (renamed from include/ui/KeyList.h)37
-rw-r--r--src/gpg/GpgContext.cpp104
-rw-r--r--src/ui/CMakeLists.txt3
-rwxr-xr-xsrc/ui/FileEncryptionDialog.cpp5
-rw-r--r--src/ui/widgets/KeyList.cpp (renamed from src/ui/KeyList.cpp)37
11 files changed, 151 insertions, 70 deletions
diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h
index e8ae9feb..92a8200c 100644
--- a/include/gpg/GpgContext.h
+++ b/include/gpg/GpgContext.h
@@ -60,14 +60,14 @@ public:
}
int considered;
- [[maybe_unused]] int no_user_id;
+ int no_user_id;
int imported;
- [[maybe_unused]] int imported_rsa;
+ int imported_rsa;
int unchanged;
- [[maybe_unused]] int new_user_ids;
- [[maybe_unused]] int new_sub_keys;
- [[maybe_unused]] int new_signatures;
- [[maybe_unused]] int new_revocations;
+ int new_user_ids;
+ int new_sub_keys;
+ int new_signatures;
+ int new_revocations;
int secret_read;
int secret_imported;
int secret_unchanged;
@@ -81,13 +81,13 @@ namespace GpgME {
Q_OBJECT
public:
- GpgContext(); // Constructor
+ GpgContext();
- ~GpgContext() override; // Destructor
+ ~GpgContext() override;
GpgImportInformation importKey(QByteArray inBuffer);
- const GpgKeyList &getKeys() const;
+ [[nodiscard]] const GpgKeyList &getKeys() const;
bool exportKeys(QStringList *uidList, QByteArray *outBuffer);
@@ -106,6 +106,8 @@ namespace GpgME {
void getKeyDetails(const QString &uid, GpgKey& key);
+ void getSigners(QVector<GpgKey> &signer);
+
void signKey(const QVector<GpgKey> &signer, const GpgKey &target, const QString& uid);
gpgme_signature_t verify(QByteArray *inBuffer, QByteArray *sigBuffer = nullptr);
@@ -151,16 +153,17 @@ namespace GpgME {
private:
gpgme_ctx_t mCtx{};
gpgme_data_t in{};
- [[maybe_unused]] gpgme_data_t out{};
gpgme_error_t err;
+ bool debug;
static gpgme_error_t readToBuffer(gpgme_data_t dataIn, QByteArray *outBuffer);
QByteArray mPasswordCache;
QSettings settings;
- [[maybe_unused]] bool debug;
GpgKeyList mKeyList;
+ QMap<QString, GpgKey> mKeyMap;
+
void fetch_keys();
static void checkErr(gpgme_error_t gpgmeError);
diff --git a/include/ui/FileEncryptionDialog.h b/include/ui/FileEncryptionDialog.h
index 52ef523e..f4adb18f 100755
--- a/include/ui/FileEncryptionDialog.h
+++ b/include/ui/FileEncryptionDialog.h
@@ -26,7 +26,7 @@
#define __FILEENCRYPTIONDIALOG_H__
#include "gpg/GpgContext.h"
-#include "KeyList.h"
+#include "ui/widgets/KeyList.h"
#include "VerifyDetailsDialog.h"
diff --git a/include/ui/KeyMgmt.h b/include/ui/KeyMgmt.h
index d98bf084..c709fa86 100755
--- a/include/ui/KeyMgmt.h
+++ b/include/ui/KeyMgmt.h
@@ -25,7 +25,7 @@
#ifndef __KEYMGMT_H__
#define __KEYMGMT_H__
-#include "KeyList.h"
+#include "ui/widgets/KeyList.h"
#include "KeygenThread.h"
#include "ui/keypair_details/KeyDetailsDialog.h"
#include "KeyImportDetailDialog.h"
diff --git a/include/ui/KeyServerImportDialog.h b/include/ui/KeyServerImportDialog.h
index ef83bc7e..f514368b 100644
--- a/include/ui/KeyServerImportDialog.h
+++ b/include/ui/KeyServerImportDialog.h
@@ -27,7 +27,7 @@
#include "gpg/GpgContext.h"
#include "KeyImportDetailDialog.h"
-#include "KeyList.h"
+#include "ui/widgets/KeyList.h"
class KeyServerImportDialog : public QDialog {
diff --git a/include/ui/SettingsDialog.h b/include/ui/SettingsDialog.h
index 55c74064..b3a70976 100755
--- a/include/ui/SettingsDialog.h
+++ b/include/ui/SettingsDialog.h
@@ -25,7 +25,7 @@
#ifndef __SETTINGSDIALOG_H__
#define __SETTINGSDIALOG_H__
-#include "ui/KeyList.h"
+#include "ui/widgets/KeyList.h"
class GeneralTab : public QWidget {
Q_OBJECT
diff --git a/include/ui/VerifyKeyDetailBox.h b/include/ui/VerifyKeyDetailBox.h
index 220b810b..b0452e43 100644
--- a/include/ui/VerifyKeyDetailBox.h
+++ b/include/ui/VerifyKeyDetailBox.h
@@ -25,7 +25,7 @@
#ifndef __VERIFYKEYDETAILBOX_H__
#define __VERIFYKEYDETAILBOX_H__
-#include "ui/KeyList.h"
+#include "ui/widgets/KeyList.h"
#include "ui/KeyServerImportDialog.h"
class VerifyKeyDetailBox : public QGroupBox {
diff --git a/include/ui/KeyList.h b/include/ui/widgets/KeyList.h
index 71bdfe6b..6af54518 100644
--- a/include/ui/KeyList.h
+++ b/include/ui/widgets/KeyList.h
@@ -26,14 +26,42 @@
#define __KEYLIST_H__
#include "gpg/GpgContext.h"
-#include "KeyImportDetailDialog.h"
+#include "ui/KeyImportDetailDialog.h"
+
+
+struct KeyListRow {
+
+ using KeyType = unsigned int;
+
+ static const KeyType SECRET_OR_PUBLIC_KEY = 0;
+ static const KeyType ONLY_SECRET_KEY = 1;
+
+};
+
+struct KeyListColumn {
+
+ using InfoType = unsigned int;
+
+ static constexpr InfoType ALL = ~0;
+ static constexpr InfoType TYPE = 1 << 0;
+ static constexpr InfoType NAME = 1 << 1;
+ static constexpr InfoType EmailAddress = 1 << 2;
+ static constexpr InfoType Usage = 1 << 3;
+ static constexpr InfoType Validity = 1 << 4;
+ static constexpr InfoType FingerPrint = 1 << 5;
+
+};
class KeyList : public QWidget {
Q_OBJECT
public:
- explicit KeyList(GpgME::GpgContext *ctx, QWidget *parent = nullptr);
+
+ explicit KeyList(GpgME::GpgContext *ctx,
+ KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY,
+ KeyListColumn::InfoType infoType = KeyListColumn::ALL,
+ QWidget *parent = nullptr);
void setColumnWidth(int row, int size);
@@ -67,13 +95,16 @@ private:
QTableWidget *mKeyList;
QMenu *popupMenu;
QNetworkAccessManager *qnam{};
-
QVector<GpgKey> buffered_keys;
+ KeyListRow::KeyType mSelectType;
+ KeyListColumn::InfoType mInfoType;
+
private slots:
void uploadFinished();
+
protected:
void contextMenuEvent(QContextMenuEvent *event) override;
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index 2ca2f625..91602a70 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -275,18 +275,20 @@ namespace GpgME {
gpgme_key_t key;
- GpgKeyList keys;
+ mKeyList.clear();
+ mKeyMap.clear();
+
+ auto &keys = mKeyList;
+ auto &keys_map = mKeyMap;
- //TODO dont run the loop more often than necessary
- // list all keys ( the 0 is for all )
gpgmeError = gpgme_set_keylist_mode(mCtx, GPGME_KEYLIST_MODE_LOCAL | GPGME_KEYLIST_MODE_WITH_SECRET);
- if (gpgmeError != GPG_ERR_NO_ERROR) {
+ if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) {
checkErr(gpgmeError);
return;
}
gpgmeError = gpgme_op_keylist_start(mCtx, nullptr, 0);
- if (gpgmeError != GPG_ERR_NO_ERROR) {
+ if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) {
checkErr(gpgmeError);
return;
}
@@ -295,53 +297,56 @@ namespace GpgME {
if (!key->subkeys)
continue;
- keys.append(GpgKey(key));
+ GpgKey gpg_key(key);
+
+ keys_map.insert(gpg_key.id, gpg_key);
gpgme_key_unref(key);
}
-// if (gpgmeError != GPG_ERR_EOF) {
-// checkErr(gpgmeError);
-// return;
-// }
-
- gpgmeError = gpgme_op_keylist_end(mCtx);
- if (gpgmeError != GPG_ERR_NO_ERROR) {
+ if (gpg_err_code(gpgmeError) != GPG_ERR_EOF) {
checkErr(gpgmeError);
return;
}
- // list only private keys ( the 1 does )
- gpgmeError = gpgme_op_keylist_start(mCtx, nullptr, 1);
- if (gpgmeError != GPG_ERR_NO_ERROR) {
+ gpgmeError = gpgme_op_keylist_end(mCtx);
+ if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) {
checkErr(gpgmeError);
return;
}
- while ((gpgmeError = gpgme_op_keylist_next(mCtx, &key)) == GPG_ERR_NO_ERROR) {
- if (!key->subkeys)
- continue;
- // iterate keys, mark privates
- GpgKeyList::iterator it = keys.begin();
- while (it != keys.end()) {
- if (key->subkeys->keyid == it->id.toStdString())
- it->is_private_key = true;
- it++;
- }
- gpgme_key_unref(key);
- }
-
-// if (gpgmeError != GPG_ERR_EOF) {
+// list only private keys ( the 1 does )
+// gpgmeError = gpgme_op_keylist_start(mCtx, nullptr, 1);
+// if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) {
+// checkErr(gpgmeError);
+// return;
+// }
+//
+// while ((gpgmeError = gpgme_op_keylist_next(mCtx, &key)) == GPG_ERR_NO_ERROR) {
+// if (key->subkeys) {
+// auto it = keys_map.find(key->subkeys->keyid);
+// if (it != keys_map.end()) {
+// it->is_private_key = true;
+// }
+// }
+// gpgme_key_unref(key);
+// }
+//
+// if (gpg_err_code(gpgmeError) != GPG_ERR_EOF) {
// checkErr(gpgmeError);
// return;
// }
gpgmeError = gpgme_op_keylist_end(mCtx);
- if (gpgmeError != GPG_ERR_NO_ERROR) {
+ if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) {
checkErr(gpgmeError);
return;
}
+ for(auto &gpg_key : keys_map) {
+ keys.append(gpg_key);
+ }
+
mKeyList = keys;
}
@@ -546,6 +551,7 @@ namespace GpgME {
QString passwordDialogMessage;
QString gpgHint = QString::fromUtf8(uid_hint);
bool result;
+
#ifdef _WIN32
DWORD written;
HANDLE hd = (HANDLE)fd;
@@ -807,11 +813,11 @@ namespace GpgME {
return (gpgmeError == GPG_ERR_NO_ERROR);
}
-/*
- * if there is no '\n' before the PGP-Begin-Block, but for example a whitespace,
- * GPGME doesn't recognise the Message as encrypted. This function adds '\n'
- * before the PGP-Begin-Block, if missing.
- */
+ /*
+ * if there is no '\n' before the PGP-Begin-Block, but for example a whitespace,
+ * GPGME doesn't recognise the Message as encrypted. This function adds '\n'
+ * before the PGP-Begin-Block, if missing.
+ */
void GpgContext::preventNoDataErr(QByteArray *in) {
int block_start = in->indexOf(GpgConstants::PGP_CRYPT_BEGIN);
if (block_start > 0 && in->at(block_start - 1) != '\n') {
@@ -823,12 +829,12 @@ namespace GpgME {
}
}
-/*
- * isSigned returns:
- * - 0, if text isn't signed at all
- * - 1, if text is partially signed
- * - 2, if text is completly signed
- */
+ /*
+ * isSigned returns:
+ * - 0, if text isn't signed at all
+ * - 1, if text is partially signed
+ * - 2, if text is completly signed
+ */
int GpgContext::textIsSigned(const QByteArray &text) {
if (text.trimmed().startsWith(GpgConstants::PGP_SIGNED_BEGIN) &&
text.trimmed().endsWith(GpgConstants::PGP_SIGNED_END)) {
@@ -891,6 +897,20 @@ namespace GpgME {
return mKeyList;
}
+ void GpgContext::getSigners(QVector<GpgKey> &signer) {
+ auto count = gpgme_signers_count(mCtx);
+ signer.clear();
+ for(auto i = 0; i < count; i++){
+ auto key = gpgme_signers_enum(mCtx, i);
+ auto it = mKeyMap.find(key->subkeys->keyid);
+ if(it == mKeyMap.end()) {
+ signer.push_back(GpgKey(key));
+ } else {
+ signer.push_back(*it);
+ }
+ }
+ }
+
}
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index c319b294..5456c2a4 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -1,5 +1,6 @@
aux_source_directory(. QTUI_SOURCE)
-aux_source_directory(./keypair_details QTUI_KEYPAIR_DETAILS_SOURCE)
+aux_source_directory(./keypair_details QTUI_SOURCE)
+aux_source_directory(./widgets QTUI_SOURCE)
add_library(qtui STATIC ${QTUI_SOURCE} ${QTUI_KEYPAIR_DETAILS_SOURCE})
diff --git a/src/ui/FileEncryptionDialog.cpp b/src/ui/FileEncryptionDialog.cpp
index 49d012f4..97e0d357 100755
--- a/src/ui/FileEncryptionDialog.cpp
+++ b/src/ui/FileEncryptionDialog.cpp
@@ -87,10 +87,7 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k
groupBox1->setLayout(gLayout);
/*Setup KeyList*/
- mKeyList = new KeyList(mCtx);
- mKeyList->hide();
- mKeyList->setColumnWidth(2, 150);
- mKeyList->setColumnWidth(3, 150);
+ mKeyList = new KeyList(mCtx, KeyListRow::ONLY_SECRET_KEY, KeyListColumn::NAME | KeyListColumn::EmailAddress);
mKeyList->setChecked(&keyList);
statusLabel = new QLabel();
diff --git a/src/ui/KeyList.cpp b/src/ui/widgets/KeyList.cpp
index c21a41ff..337c1fc5 100644
--- a/src/ui/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -22,12 +22,15 @@
*
*/
-#include "ui/KeyList.h"
+#include "ui/widgets/KeyList.h"
#include <utility>
-KeyList::KeyList(GpgME::GpgContext *ctx, QWidget *parent)
- : QWidget(parent)
+KeyList::KeyList(GpgME::GpgContext *ctx,
+ KeyListRow::KeyType selectType,
+ KeyListColumn::InfoType infoType,
+ QWidget *parent)
+ : QWidget(parent), mSelectType(selectType), mInfoType(infoType)
{
mCtx = ctx;
@@ -47,9 +50,30 @@ KeyList::KeyList(GpgME::GpgContext *ctx, QWidget *parent)
mKeyList->setAlternatingRowColors(true);
+ // Hidden Column For Purpose
+ if(!(mInfoType & KeyListColumn::TYPE)) {
+ mKeyList->setColumnHidden(1, true);
+ }
+ if(!(mInfoType & KeyListColumn::NAME)) {
+ mKeyList->setColumnHidden(2, true);
+ }
+ if(!(mInfoType & KeyListColumn::EmailAddress)) {
+ mKeyList->setColumnHidden(3, true);
+ }
+ if(!(mInfoType & KeyListColumn::Usage)) {
+ mKeyList->setColumnHidden(4, true);
+ }
+ if(!(mInfoType & KeyListColumn::Validity)) {
+ mKeyList->setColumnHidden(5, true);
+ }
+ if(!(mInfoType & KeyListColumn::FingerPrint)) {
+ mKeyList->setColumnHidden(6, true);
+ }
+
QStringList labels;
labels << tr("Select") << tr("Type") << tr("Name") << tr("Email Address")
- << tr("Usage") << tr("Validity") << tr("Finger Print");
+ << tr("Usage") << tr("Validity") << tr("Finger Print");
+
mKeyList->setHorizontalHeaderLabels(labels);
mKeyList->horizontalHeader()->setStretchLastSection(true);
@@ -82,6 +106,11 @@ void KeyList::slotRefresh()
while (it != keys.end()) {
+ if(mSelectType == KeyListRow::ONLY_SECRET_KEY && !it->is_private_key) {
+ it++;
+ continue;
+ }
+
buffered_keys.push_back(*it);
auto *tmp0 = new QTableWidgetItem(QString::number(row));