aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/gpg/GpgContext.h46
-rw-r--r--include/ui/keypair_details/EditSubKeyDialog.h14
-rw-r--r--include/ui/keypair_details/KeyPairDetailTab.h8
-rw-r--r--include/ui/keypair_details/KeyPairSubkeyTab.h10
-rw-r--r--include/ui/keypair_details/KeySetExpireDateDialog.h33
-rw-r--r--src/gpg/GpgContext.cpp25
-rw-r--r--src/ui/keypair_details/EditSubKeyDialog.cpp5
-rw-r--r--src/ui/keypair_details/KeyPairDetailTab.cpp97
-rw-r--r--src/ui/keypair_details/KeyPairSubkeyTab.cpp21
-rw-r--r--src/ui/keypair_details/KeySetExpireDateDialog.cpp54
10 files changed, 260 insertions, 53 deletions
diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h
index af390ff1..3d3f2ffa 100644
--- a/include/gpg/GpgContext.h
+++ b/include/gpg/GpgContext.h
@@ -43,35 +43,21 @@ typedef QLinkedList<GpgImportedKey> GpgImportedKeyList;
class GpgImportInformation {
public:
- GpgImportInformation() {
- considered = 0;
- no_user_id = 0;
- imported = 0;
- imported_rsa = 0;
- unchanged = 0;
- new_user_ids = 0;
- new_sub_keys = 0;
- new_signatures = 0;
- new_revocations = 0;
- secret_read = 0;
- secret_imported = 0;
- secret_unchanged = 0;
- not_imported = 0;
- }
-
- int considered;
- int no_user_id;
- int imported;
- int imported_rsa;
- int unchanged;
- int new_user_ids;
- int new_sub_keys;
- int new_signatures;
- int new_revocations;
- int secret_read;
- int secret_imported;
- int secret_unchanged;
- int not_imported;
+ GpgImportInformation() = default;
+
+ int considered = 0;
+ int no_user_id = 0;
+ int imported = 0;
+ int imported_rsa = 0;
+ int unchanged = 0;
+ int new_user_ids = 0;
+ int new_sub_keys = 0;
+ int new_signatures = 0;
+ int new_revocations = 0;
+ int secret_read = 0;
+ int secret_imported = 0;
+ int secret_unchanged = 0;
+ int not_imported = 0;
GpgImportedKeyList importedKeys;
};
@@ -124,6 +110,8 @@ namespace GpgME {
bool setPrimaryUID(const GpgKey &key, const UID &uid);
+ bool setExpire(const GpgKey &key, const GpgSubKey *subkey, QDateTime *expires);
+
/**
* @details If text contains PGP-message, put a linebreak before the message,
* so that gpgme can decrypt correctly
diff --git a/include/ui/keypair_details/EditSubKeyDialog.h b/include/ui/keypair_details/EditSubKeyDialog.h
new file mode 100644
index 00000000..be926be7
--- /dev/null
+++ b/include/ui/keypair_details/EditSubKeyDialog.h
@@ -0,0 +1,14 @@
+//
+// Created by eric on 2021/6/2.
+//
+
+#ifndef GPGFRONTEND_EDITSUBKEY_H
+#define GPGFRONTEND_EDITSUBKEY_H
+
+
+class EditSubKeyDialog {
+
+};
+
+
+#endif //GPGFRONTEND_EDITSUBKEY_H
diff --git a/include/ui/keypair_details/KeyPairDetailTab.h b/include/ui/keypair_details/KeyPairDetailTab.h
index d6f1b4e1..6b3bc2f0 100644
--- a/include/ui/keypair_details/KeyPairDetailTab.h
+++ b/include/ui/keypair_details/KeyPairDetailTab.h
@@ -27,6 +27,7 @@
#include "GpgFrontend.h"
#include "gpg/GpgContext.h"
+#include "KeySetExpireDateDialog.h"
class KeyPairDetailTab : public QWidget {
Q_OBJECT
@@ -50,11 +51,16 @@ private slots:
*/
void slotCopyFingerprint();
+ void slotModifyEditDatetime();
+
+ void slotRefreshKeyInfo();
+
private:
QString *keyid; /** The id of the key the details should be shown for */
GpgME::GpgContext *mCtx; /** The current gpg-context */
+ const GpgKey &mKey;
QGroupBox *ownerBox; /** Groupbox containing owner information */
QGroupBox *keyBox; /** Groupbox containing key information */
@@ -73,7 +79,7 @@ private:
QLabel *usageVarLabel;
public:
- explicit KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent = nullptr);
+ explicit KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey& mKey, QWidget *parent = nullptr);
};
diff --git a/include/ui/keypair_details/KeyPairSubkeyTab.h b/include/ui/keypair_details/KeyPairSubkeyTab.h
index 45abe7a1..ae954968 100644
--- a/include/ui/keypair_details/KeyPairSubkeyTab.h
+++ b/include/ui/keypair_details/KeyPairSubkeyTab.h
@@ -39,7 +39,9 @@ public:
private:
- void creatSubkeyList();
+ void createSubkeyList();
+
+ void createSubkeyOperaMenu();
GpgME::GpgContext *mCtx;
const GpgKey &mKey;
@@ -49,6 +51,8 @@ private:
QGroupBox *listBox;
QGroupBox *detailBox;
+ QMenu *subkeyOperaMenu;
+
QLabel *keySizeVarLabel; /** Label containng the keys keysize */
QLabel *expireVarLabel; /** Label containng the keys expiration date */
@@ -67,6 +71,10 @@ private slots:
void slotRefreshSubkeyDetail();
+ void slotEditSubkey();
+
+ void slotRevokeSubkey();
+
};
diff --git a/include/ui/keypair_details/KeySetExpireDateDialog.h b/include/ui/keypair_details/KeySetExpireDateDialog.h
new file mode 100644
index 00000000..d0206402
--- /dev/null
+++ b/include/ui/keypair_details/KeySetExpireDateDialog.h
@@ -0,0 +1,33 @@
+//
+// Created by eric on 2021/6/3.
+//
+
+#ifndef GPGFRONTEND_KEYSETEXPIREDATEDIALOG_H
+#define GPGFRONTEND_KEYSETEXPIREDATEDIALOG_H
+
+#include "GpgFrontend.h"
+#include "gpg/GpgContext.h"
+#include "gpg/GpgKey.h"
+#include "gpg/GpgSubKey.h"
+
+class KeySetExpireDateDialog : public QDialog {
+Q_OBJECT
+public:
+ explicit KeySetExpireDateDialog(GpgME::GpgContext *ctx, const GpgKey &key, const GpgSubKey *subkey, QWidget *parent = nullptr);
+
+private:
+ GpgME::GpgContext *mCtx;
+ const GpgKey &mKey;
+ const GpgSubKey *mSubkey;
+
+ QDateTimeEdit *dateTimeEdit{};
+ QPushButton *confirmButton{};
+ QCheckBox *nonExpiredCheck{};
+
+private slots:
+ void slotConfirm();
+ void slotNonExpiredChecked(int state);
+};
+
+
+#endif //GPGFRONTEND_KEYSETEXPIREDATEDIALOG_H
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index d4736249..d6211616 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -1048,6 +1048,31 @@ namespace GpgME {
}
}
+ bool GpgContext::setExpire(const GpgKey &key, const GpgSubKey *subkey, QDateTime *expires) {
+ unsigned long expires_time = 0;
+ if(expires != nullptr) {
+ qDebug() << "Expire Datetime" << expires->toString();
+ expires_time = QDateTime::currentDateTime().secsTo(*expires);
+ }
+
+ const char *subfprs = nullptr;
+
+ if(subkey != nullptr) {
+ subfprs = subkey->fpr.toUtf8().constData();
+ }
+
+ auto gpgmeError = gpgme_op_setexpire(mCtx, key.key_refer,
+ expires_time, subfprs, 0);
+ if(gpgmeError == GPG_ERR_NO_ERROR) {
+ emit signalKeyUpdated(key.id);
+ return true;
+ }
+ else {
+ checkErr(gpgmeError);
+ return false;
+ }
+ }
+
}
diff --git a/src/ui/keypair_details/EditSubKeyDialog.cpp b/src/ui/keypair_details/EditSubKeyDialog.cpp
new file mode 100644
index 00000000..5e26a098
--- /dev/null
+++ b/src/ui/keypair_details/EditSubKeyDialog.cpp
@@ -0,0 +1,5 @@
+//
+// Created by eric on 2021/6/2.
+//
+
+#include "ui/keypair_details/EditSubKeyDialog.h"
diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp
index 66d01dfc..15dfb661 100644
--- a/src/ui/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/keypair_details/KeyPairDetailTab.cpp
@@ -24,52 +24,52 @@
#include "ui/keypair_details/KeyPairDetailTab.h"
-KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : QWidget(parent) {
+KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, QWidget *parent) : mKey(mKey), QWidget(parent) {
mCtx = ctx;
- keyid = new QString(key.id);
+ keyid = new QString(mKey.id);
ownerBox = new QGroupBox(tr("Owner details"));
keyBox = new QGroupBox(tr("Key details"));
fingerprintBox = new QGroupBox(tr("Fingerprint"));
additionalUidBox = new QGroupBox(tr("Additional Uids"));
- nameVarLabel = new QLabel(key.name);
+ nameVarLabel = new QLabel(mKey.name);
nameVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- emailVarLabel = new QLabel(key.email);
+ emailVarLabel = new QLabel(mKey.email);
emailVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- commentVarLabel = new QLabel(key.comment);
+ commentVarLabel = new QLabel(mKey.comment);
commentVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- keyidVarLabel = new QLabel(key.id);
+ keyidVarLabel = new QLabel(mKey.id);
keyidVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
QString usage;
QTextStream usage_steam(&usage);
- if(key.can_certify)
+ if(mKey.can_certify)
usage_steam << "Cert ";
- if(key.can_encrypt)
+ if(mKey.can_encrypt)
usage_steam << "Encr ";
- if(key.can_sign)
+ if(mKey.can_sign)
usage_steam << "Sign ";
- if(key.can_authenticate)
+ if(mKey.can_authenticate)
usage_steam << "Auth ";
usageVarLabel = new QLabel(usage);
QString keySizeVal, keyExpireVal, keyCreateTimeVal, keyAlgoVal;
- keySizeVal = QString::number(key.length);
+ keySizeVal = QString::number(mKey.length);
- if (key.expires.toTime_t() == 0) {
+ if (mKey.expires.toTime_t() == 0) {
keyExpireVal = tr("Never Expired");
} else {
- keyExpireVal = key.expires.toString();
+ keyExpireVal = mKey.expires.toString();
}
- keyAlgoVal = key.pubkey_algo;
- keyCreateTimeVal = key.create_time.toString();
+ keyAlgoVal = mKey.pubkey_algo;
+ keyCreateTimeVal = mKey.create_time.toString();
keySizeVarLabel = new QLabel(keySizeVal);
expireVarLabel = new QLabel(keyExpireVal);
@@ -107,7 +107,7 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
keyBox->setLayout(vboxKD);
mvbox->addWidget(keyBox);
- fingerPrintVarLabel = new QLabel(beautifyFingerprint(key.fpr));
+ fingerPrintVarLabel = new QLabel(beautifyFingerprint(mKey.fpr));
fingerPrintVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
fingerPrintVarLabel->setStyleSheet("margin-left: 0; margin-right: 5;");
auto *hboxFP = new QHBoxLayout();
@@ -125,7 +125,7 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
mvbox->addWidget(fingerprintBox);
mvbox->addStretch();
- if (key.is_private_key) {
+ if (mKey.is_private_key) {
auto *privKeyBox = new QGroupBox(tr("Operations"));
auto *vboxPK = new QVBoxLayout();
@@ -133,21 +133,27 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
vboxPK->addWidget(exportButton);
connect(exportButton, SIGNAL(clicked()), this, SLOT(slotExportPrivateKey()));
+ auto *editExpiresButton = new QPushButton(tr("Modify Expiration Datetime"));
+ vboxPK->addWidget(editExpiresButton);
+ connect(editExpiresButton, SIGNAL(clicked()), this, SLOT(slotModifyEditDatetime()));
+
privKeyBox->setLayout(vboxPK);
mvbox->addWidget(privKeyBox);
+
+
}
- if ((key.expired) || (key.revoked)) {
+ if ((mKey.expired) || (mKey.revoked)) {
auto *expBox = new QHBoxLayout();
QIcon icon = QIcon::fromTheme("dialog-warning");
QPixmap pixmap = icon.pixmap(QSize(32, 32), QIcon::Normal, QIcon::On);
auto *expLabel = new QLabel();
auto *iconLabel = new QLabel();
- if (key.expired) {
+ if (mKey.expired) {
expLabel->setText(tr("Warning: Key expired"));
}
- if (key.revoked) {
+ if (mKey.revoked) {
expLabel->setText(tr("Warning: Key revoked"));
}
@@ -160,6 +166,8 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
mvbox->addLayout(expBox);
}
+ connect(mCtx, SIGNAL(signalKeyInfoChanged()), this, SLOT(slotRefreshKeyInfo()));
+
setAttribute(Qt::WA_DeleteOnClose, true);
setLayout(mvbox);
}
@@ -208,3 +216,52 @@ void KeyPairDetailTab::slotCopyFingerprint() {
cb->setText(fpr);
}
+void KeyPairDetailTab::slotModifyEditDatetime() {
+ auto dialog = new KeySetExpireDateDialog(mCtx, mKey, nullptr, this);
+ dialog->show();
+}
+
+void KeyPairDetailTab::slotRefreshKeyInfo() {
+
+ nameVarLabel->setText(mKey.name);
+ emailVarLabel->setText(mKey.email);
+
+ commentVarLabel->setText(mKey.comment);
+ keyidVarLabel->setText(mKey.id);
+
+ QString usage;
+ QTextStream usage_steam(&usage);
+
+ if(mKey.can_certify)
+ usage_steam << "Cert ";
+ if(mKey.can_encrypt)
+ usage_steam << "Encr ";
+ if(mKey.can_sign)
+ usage_steam << "Sign ";
+ if(mKey.can_authenticate)
+ usage_steam << "Auth ";
+
+ usageVarLabel->setText(usage);
+
+ QString keySizeVal, keyExpireVal, keyCreateTimeVal, keyAlgoVal;
+
+ keySizeVal = QString::number(mKey.length);
+
+ if (mKey.expires.toTime_t() == 0) {
+ keyExpireVal = tr("Never Expired");
+ } else {
+ keyExpireVal = mKey.expires.toString();
+ }
+
+ keyAlgoVal = mKey.pubkey_algo;
+ keyCreateTimeVal = mKey.create_time.toString();
+
+ keySizeVarLabel->setText(keySizeVal);
+ expireVarLabel->setText(keyExpireVal);
+ createdVarLabel->setText(keyCreateTimeVal);
+ algorithmVarLabel->setText(keyAlgoVal);
+
+ fingerPrintVarLabel->setText(beautifyFingerprint(mKey.fpr));
+
+}
+
diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp
index f3edfe09..75bd50f5 100644
--- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp
@@ -26,7 +26,7 @@
KeyPairSubkeyTab::KeyPairSubkeyTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : mCtx(ctx), mKey(key), QWidget(parent) {
- creatSubkeyList();
+ createSubkeyList();
listBox = new QGroupBox("Subkey List");
detailBox = new QGroupBox("Detail of Selected Subkey");
@@ -88,7 +88,7 @@ KeyPairSubkeyTab::KeyPairSubkeyTab(GpgME::GpgContext *ctx, const GpgKey &key, QW
}
-void KeyPairSubkeyTab::creatSubkeyList() {
+void KeyPairSubkeyTab::createSubkeyList() {
subkeyList = new QTableWidget(this);
subkeyList->setColumnCount(5);
@@ -194,3 +194,20 @@ void KeyPairSubkeyTab::slotRefreshSubkeyDetail() {
usageVarLabel->setText(usage);
}
+
+void KeyPairSubkeyTab::createSubkeyOperaMenu() {
+ subkeyOperaMenu = new QMenu();
+ auto *revokeSubkeyAct = new QAction(tr("Revoke Subkey"));
+ auto *editSubkeyAct = new QAction(tr("Edit Subkey"));
+
+ subkeyOperaMenu->addAction(revokeSubkeyAct);
+ subkeyOperaMenu->addAction(editSubkeyAct);
+}
+
+void KeyPairSubkeyTab::slotEditSubkey() {
+
+}
+
+void KeyPairSubkeyTab::slotRevokeSubkey() {
+
+}
diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/keypair_details/KeySetExpireDateDialog.cpp
new file mode 100644
index 00000000..f9b05dea
--- /dev/null
+++ b/src/ui/keypair_details/KeySetExpireDateDialog.cpp
@@ -0,0 +1,54 @@
+//
+// Created by eric on 2021/6/3.
+//
+
+#include "ui/keypair_details/KeySetExpireDateDialog.h"
+
+KeySetExpireDateDialog::KeySetExpireDateDialog(GpgME::GpgContext *ctx, const GpgKey &key, const GpgSubKey *subkey, QWidget *parent) :
+QDialog(parent), mKey(key), mSubkey(subkey), mCtx(ctx) {
+
+ QDateTime maxDateTime = QDateTime::currentDateTime().addYears(2);
+ dateTimeEdit = new QDateTimeEdit(maxDateTime);
+ dateTimeEdit->setMinimumDateTime(QDateTime::currentDateTime());
+ dateTimeEdit->setMaximumDateTime(maxDateTime);
+ nonExpiredCheck = new QCheckBox();
+ nonExpiredCheck->setTristate(false);
+ confirmButton = new QPushButton(tr("Confirm"));
+
+ auto *gridLayout = new QGridLayout();
+ gridLayout->addWidget(dateTimeEdit, 0, 0, 1, 2);
+ gridLayout->addWidget(nonExpiredCheck, 1, 0, 1, 1, Qt::AlignRight);
+ gridLayout->addWidget(new QLabel(tr("Never Expire")));
+ gridLayout->addWidget(confirmButton, 2, 0);
+
+ connect(nonExpiredCheck, SIGNAL(stateChanged(int)), this, SLOT(slotNonExpiredChecked(int)));
+ connect(confirmButton, SIGNAL(clicked(bool)), this, SLOT(slotConfirm()));
+
+ this->setLayout(gridLayout);
+ this->setWindowTitle("Edit Expire Datetime");
+ this->setModal(true);
+ this->setAttribute(Qt::WA_DeleteOnClose, true);
+}
+
+void KeySetExpireDateDialog::slotConfirm() {
+ QDateTime *expires = nullptr;
+ if(this->nonExpiredCheck->checkState() == Qt::Unchecked) {
+ expires = new QDateTime(this->dateTimeEdit->dateTime());
+ }
+
+ if(!mCtx->setExpire(mKey, mSubkey, expires)) {
+ QMessageBox::critical(nullptr,
+ tr("Operation Failed"),
+ tr("An error occurred during the operation."));
+ }
+ delete expires;
+ this->close();
+}
+
+void KeySetExpireDateDialog::slotNonExpiredChecked(int state) {
+ if(state == 0) {
+ this->dateTimeEdit->setDisabled(false);
+ } else {
+ this->dateTimeEdit->setDisabled(true);
+ }
+}