aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-05-21 16:15:54 +0000
committerSaturneric <[email protected]>2021-05-21 16:15:54 +0000
commit21f4730e92d088c06dea01684f3f736f3f9beff0 (patch)
treec1dc4dc6836903adc688b03cafabc06fc845743f
parentModified KeyList and Add Usage Support; (diff)
downloadGpgFrontend-21f4730e92d088c06dea01684f3f736f3f9beff0.tar.gz
GpgFrontend-21f4730e92d088c06dea01684f3f736f3f9beff0.zip
Expand Key Details Dialog;
Expand and Improve GpgKey and GpgSubKey; Change Interface getKeyDetails(); Code Modified; Signed-off-by: Saturneric <[email protected]>
Diffstat (limited to '')
-rw-r--r--include/gpg/GpgContext.h2
-rw-r--r--include/gpg/GpgGenKeyInfo.h120
-rw-r--r--include/gpg/GpgKey.h140
-rw-r--r--include/gpg/GpgSubKey.h37
-rw-r--r--include/ui/KeyDetailsDialog.h60
-rw-r--r--include/ui/KeyPairDetailTab.h62
-rw-r--r--src/MainWindow.cpp12
-rw-r--r--src/gpg/GpgContext.cpp19
-rw-r--r--src/gpg/GpgGenKeyInfo.cpp147
-rw-r--r--src/gpg/GpgKey.cpp26
-rw-r--r--src/gpg/GpgSubKey.cpp27
-rw-r--r--src/ui/KeyDetailsDialog.cpp199
-rw-r--r--src/ui/KeyList.cpp21
-rwxr-xr-xsrc/ui/KeyMgmt.cpp16
-rw-r--r--src/ui/KeyPairDetailTab.cpp209
-rw-r--r--src/ui/KeygenDialog.cpp2
-rwxr-xr-xsrc/ui/SettingsDialog.cpp17
17 files changed, 663 insertions, 453 deletions
diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h
index 071fff8b..81ff3152 100644
--- a/include/gpg/GpgContext.h
+++ b/include/gpg/GpgContext.h
@@ -102,7 +102,7 @@ namespace GpgME {
void exportSecretKey(const QString &uid, QByteArray *outBuffer);
- gpgme_key_t getKeyDetails(const QString &uid);
+ void getKeyDetails(const QString &uid, GpgKey& key);
gpgme_signature_t verify(QByteArray *inBuffer, QByteArray *sigBuffer = nullptr);
diff --git a/include/gpg/GpgGenKeyInfo.h b/include/gpg/GpgGenKeyInfo.h
index f4273b05..ee2b0262 100644
--- a/include/gpg/GpgGenKeyInfo.h
+++ b/include/gpg/GpgGenKeyInfo.h
@@ -25,8 +25,7 @@
#ifndef GPG4USB_GPGGENKEYINFO_H
#define GPG4USB_GPGGENKEYINFO_H
-#include <QString>
-#include <QTime>
+#include "GpgFrontend.h"
class GenKeyInfo {
@@ -70,111 +69,35 @@ public:
return algo;
}
- void setAlgo(const QString &m_algo) {
-
- qDebug() << "set algo " << m_algo;
-
- reset_options();
-
- if (!this->subKey) {
- this->setAllowCertification(true);
- this->allowChangeCertification = false;
- }
-
- auto lower_algo = m_algo.toLower();
-
- if(lower_algo == "rsa") {
- /**
- * RSA is the world’s premier asymmetric cryptographic algorithm,
- * and is built on the difficulty of factoring extremely large composites.
- * GnuPG supports RSA with key sizes of between 1024 and 4096 bits.
- */
- suggestMinKeySize = 1024;
- suggestMaxKeySize = 4096;
- suggestSizeAdditionStep = 1024;
- setKeySize(2048);
-
- } else if (lower_algo == "dsa") {
- /**
- * Algorithm (DSA) as a government standard for digital signatures.
- * Originally, it supported key lengths between 512 and 1024 bits.
- * Recently, NIST has declared 512-bit keys obsolete:
- * now, DSA is available in 1024, 2048 and 3072-bit lengths.
- */
- setAllowEncryption(false);
- allowChangeEncryption = false;
-
- suggestMinKeySize = 1024;
- suggestMaxKeySize = 3072;
- suggestSizeAdditionStep = 1024;
- setKeySize(2048);
-
- } else if (lower_algo == "ed25519") {
- /**
- * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths ranging from 1024 to 4096 bits.
- */
-
- setAllowEncryption(false);
- allowChangeEncryption = false;
-
- suggestMinKeySize = -1;
- suggestMaxKeySize = -1;
- suggestSizeAdditionStep = -1;
- setKeySize(-1);
- }
- GenKeyInfo::algo = lower_algo;
- }
-
- [[nodiscard]] QString getKeySizeStr() const {
- if(keySize > 0) {
- return QString::number(keySize);
- }
- else {
- return QString();
- }
+ void setAlgo(const QString &m_algo);
- }
+ [[nodiscard]] QString getKeySizeStr() const;
[[nodiscard]] int getKeySize() const {
return keySize;
}
- void setKeySize(int m_key_size) {
- if (m_key_size < suggestMinKeySize || m_key_size > suggestMaxKeySize) {
- return;
- }
- GenKeyInfo::keySize = m_key_size;
- }
+ void setKeySize(int m_key_size);
[[nodiscard]] const QDateTime &getExpired() const {
return expired;
}
- void setExpired(const QDateTime &m_expired) {
- auto current = QDateTime::currentDateTime();
- if (isNonExpired() && m_expired < current.addYears(2)) {
- GenKeyInfo::expired = m_expired;
- }
- }
+ void setExpired(const QDateTime &m_expired);
[[nodiscard]] bool isNonExpired() const {
return nonExpired;
}
- void setNonExpired(bool m_non_expired) {
- if (!m_non_expired) {
- this->expired = QDateTime(QDateTime::fromTime_t(0));
- }
- GenKeyInfo::nonExpired = m_non_expired;
- }
+ void setNonExpired(bool m_non_expired);
[[nodiscard]] bool isNoPassPhrase() const {
return this->noPassPhrase;
}
void setNonPassPhrase(bool m_non_pass_phrase) {
- GenKeyInfo::noPassPhrase = true;
+ GenKeyInfo::noPassPhrase = m_non_pass_phrase;
}
[[nodiscard]] bool isAllowSigning() const {
@@ -194,19 +117,13 @@ public:
return allowEncryption;
}
- void setAllowEncryption(bool m_allow_encryption) {
- if(allowChangeEncryption)
- GenKeyInfo::allowEncryption = m_allow_encryption;
- }
+ void setAllowEncryption(bool m_allow_encryption);
[[nodiscard]] bool isAllowCertification() const {
return allowCertification;
}
- void setAllowCertification(bool m_allow_certification) {
- if(allowChangeCertification)
- GenKeyInfo::allowCertification = m_allow_certification;
- }
+ void setAllowCertification(bool m_allow_certification);
[[nodiscard]] bool isAllowAuthentication() const {
return allowAuthentication;
@@ -266,24 +183,7 @@ private:
bool allowSigning = true;
bool allowChangeSigning = true;
- void reset_options() {
-
- allowChangeEncryption = true;
- setAllowEncryption(true);
-
- allowChangeCertification = true;
- setAllowCertification(true);
-
- allowChangeSigning = true;
- setAllowSigning(true);
-
- allowChangeAuthentication = true;
- setAllowAuthentication(true);
-
-
- passPhrase.clear();
-
- }
+ void reset_options();
public:
diff --git a/include/gpg/GpgKey.h b/include/gpg/GpgKey.h
index d33bd71d..2dc4f8c8 100644
--- a/include/gpg/GpgKey.h
+++ b/include/gpg/GpgKey.h
@@ -1,6 +1,26 @@
-//
-// Created by eric on 2021/5/21.
-//
+/**
+ * This file is part of GPGFrontend.
+ *
+ * GPGFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
#ifndef GPGFRONTEND_GPGKEY_H
#define GPGFRONTEND_GPGKEY_H
@@ -11,17 +31,20 @@
class GpgKey {
public:
- GpgKey() {
- is_private_key = false;
- }
QString id;
QString name;
QString email;
+ QString comment;
QString fpr;
QString protocol;
- int owner_trust;
+ QString owner_trust;
+ QString pubkey_algo;
QDateTime last_update;
+ QDateTime expires;
+ QDateTime create_time;
+
+ int length;
bool can_encrypt{};
bool can_sign{};
@@ -34,44 +57,81 @@ public:
bool revoked{};
bool disabled{};
- QVector<GpgSubKey> subKeys;
-
- GpgKey(gpgme_key_t key) {
- is_private_key = key->secret;
- fpr = key->fpr;
- protocol = key->protocol;
- expired = (key->expired != 0u);
- revoked = (key->revoked != 0u);
-
- disabled = key->disabled;
-
- can_authenticate = key->can_authenticate;
- can_certify = key->can_certify;
- can_encrypt = key->can_encrypt;
- can_sign = key->can_sign;
-
- last_update = QDateTime(QDateTime::fromTime_t(key->last_update));
- owner_trust = key->owner_trust;
+ bool good = false;
- if (key->uids) {
- name = QString::fromUtf8(key->uids->name);
- email = QString::fromUtf8(key->uids->email);
- }
+ QVector<GpgSubKey> subKeys;
- gpgme_subkey_t next = key->subkeys;
+ explicit GpgKey(gpgme_key_t key) {
+ parse(key);
+ }
- while(next != nullptr) {
- subKeys.push_back(GpgSubKey(next));
- next = next->next;
- }
+ GpgKey() {
+ is_private_key = false;
+ }
- if(!subKeys.isEmpty()) {
- id = subKeys.first().id;
- } else {
- id = "";
+ void parse(gpgme_key_t key) {
+ if(key != nullptr) {
+ good = true;
+ is_private_key = key->secret;
+ fpr = key->fpr;
+ protocol = key->protocol;
+ expired = (key->expired != 0u);
+ revoked = (key->revoked != 0u);
+
+ disabled = key->disabled;
+
+ can_authenticate = key->can_authenticate;
+ can_certify = key->can_certify;
+ can_encrypt = key->can_encrypt;
+ can_sign = key->can_sign;
+
+ last_update = QDateTime(QDateTime::fromTime_t(key->last_update));
+
+ switch (key->owner_trust) {
+ case GPGME_VALIDITY_UNKNOWN:
+ owner_trust = "Unknown";
+ break;
+ case GPGME_VALIDITY_UNDEFINED:
+ owner_trust = "Undefined";
+ break;
+ case GPGME_VALIDITY_NEVER:
+ owner_trust = "Never";
+ break;
+ case GPGME_VALIDITY_MARGINAL:
+ owner_trust = "Marginal";
+ break;
+ case GPGME_VALIDITY_FULL:
+ owner_trust = "FULL";
+ break;
+ case GPGME_VALIDITY_ULTIMATE:
+ owner_trust = "Ultimate";
+ break;
+ }
+
+
+ if (key->uids) {
+ name = QString::fromUtf8(key->uids->name);
+ email = QString::fromUtf8(key->uids->email);
+ comment = QString::fromUtf8(key->uids->comment);
+ }
+
+ gpgme_subkey_t next = key->subkeys;
+
+ while (next != nullptr) {
+ subKeys.push_back(GpgSubKey(next));
+ next = next->next;
+ }
+
+ if (!subKeys.isEmpty()) {
+ id = subKeys.first().id;
+ expires = subKeys.first().expires;
+ pubkey_algo = subKeys.first().pubkey_algo;
+ create_time = subKeys.first().timestamp;
+ length = subKeys.first().length;
+ } else {
+ id = "";
+ }
}
-
-
}
};
diff --git a/include/gpg/GpgSubKey.h b/include/gpg/GpgSubKey.h
index 1c810693..f495c709 100644
--- a/include/gpg/GpgSubKey.h
+++ b/include/gpg/GpgSubKey.h
@@ -1,18 +1,40 @@
-//
-// Created by eric on 2021/5/21.
-//
-
+/**
+ * This file is part of GPGFrontend.
+ *
+ * GPGFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
#ifndef GPGFRONTEND_GPGSUBKEY_H
#define GPGFRONTEND_GPGSUBKEY_H
-
-#include <gpgme.h>
+#include "GpgFrontend.h"
struct GpgSubKey {
QString id;
QString fpr;
+ QString pubkey_algo;
+
+ unsigned int length;
+
bool can_encrypt{};
bool can_sign{};
bool can_certify{};
@@ -33,6 +55,7 @@ struct GpgSubKey {
explicit GpgSubKey(gpgme_subkey_t key) {
id = key->keyid;
+ pubkey_algo = gpgme_pubkey_algo_name(key->pubkey_algo);
fpr = key->fpr;
expired = (key->expired != 0u);
@@ -40,6 +63,8 @@ struct GpgSubKey {
disabled = key->disabled;
+ length = key->length;
+
can_authenticate = key->can_authenticate;
can_certify = key->can_certify;
can_encrypt = key->can_encrypt;
diff --git a/include/ui/KeyDetailsDialog.h b/include/ui/KeyDetailsDialog.h
index 96d707b9..1ad2d133 100644
--- a/include/ui/KeyDetailsDialog.h
+++ b/include/ui/KeyDetailsDialog.h
@@ -26,74 +26,20 @@
#define __KEYDETAILSDIALOG_H__
#include "gpg/GpgContext.h"
+#include "KeyPairDetailTab.h"
#include <gpgme.h>
-QT_BEGIN_NAMESPACE
-class QDateTime;
-
-class QVBoxLayout;
-
-class QHBoxLayout;
-
-class QDialogButtonBox;
-
-class QDialog;
-
-class QGroupBox;
-
-class QLabel;
-
-class QGridLayout;
-
-class QPushButton;
-
-QT_END_NAMESPACE
-
class KeyDetailsDialog : public QDialog {
Q_OBJECT
public:
- KeyDetailsDialog(GpgME::GpgContext *ctx, gpgme_key_t key, QWidget *parent = nullptr);
-
- /**
- * @details Return QString with a space inserted at every fourth character
- *
- * @param fingerprint The fingerprint to be beautified
- */
- static QString beautifyFingerprint(QString fingerprint);
-
-private slots:
-
- /**
- * @details Export the key to a file, which is choosen in a file dialog
- */
- void slotExportPrivateKey();
- /**
- * @details Copy the fingerprint to clipboard
- */
- void slotCopyFingerprint();
+ KeyDetailsDialog(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent = nullptr);
private:
- QString *keyid; /** The id of the key the details should be shown for */
- GpgME::GpgContext *mCtx; /** The current gpg-context */
- QGroupBox *ownerBox; /** Groupbox containing owner information */
- QGroupBox *keyBox; /** Groupbox containing key information */
- QGroupBox *fingerprintBox; /** Groupbox containing fingerprint information */
- QGroupBox *additionalUidBox; /** Groupbox containing information about additional uids */
- QDialogButtonBox *buttonBox; /** Box containing the close button */
+ QTabWidget *tabWidget{};
- QLabel *nameVarLabel; /** Label containng the keys name */
- QLabel *emailVarLabel; /** Label containng the keys email */
- QLabel *commentVarLabel; /** Label containng the keys commment */
- QLabel *keySizeVarLabel; /** Label containng the keys keysize */
- QLabel *expireVarLabel; /** Label containng the keys expiration date */
- QLabel *createdVarLabel; /** Label containng the keys creation date */
- QLabel *algorithmVarLabel; /** Label containng the keys algorithm */
- QLabel *keyidVarLabel; /** Label containng the keys keyid */
- QLabel *fingerPrintVarLabel; /** Label containng the keys fingerprint */
- QLabel *addUserIdsVarLabel; /** Label containng info about keys additional uids */
};
#endif // __KEYDETAILSDIALOG_H__
diff --git a/include/ui/KeyPairDetailTab.h b/include/ui/KeyPairDetailTab.h
new file mode 100644
index 00000000..5ed40dac
--- /dev/null
+++ b/include/ui/KeyPairDetailTab.h
@@ -0,0 +1,62 @@
+//
+// Created by eric on 2021/5/21.
+//
+
+#ifndef GPGFRONTEND_KEYPAIRDETAILTAB_H
+#define GPGFRONTEND_KEYPAIRDETAILTAB_H
+
+#include "GpgFrontend.h"
+#include "gpg/GpgContext.h"
+
+class KeyPairDetailTab : public QWidget {
+ Q_OBJECT
+
+ /**
+ * @details Return QString with a space inserted at every fourth character
+ *
+ * @param fingerprint The fingerprint to be beautified
+ */
+ static QString beautifyFingerprint(QString fingerprint);
+
+private slots:
+
+ /**
+ * @details Export the key to a file, which is choosen in a file dialog
+ */
+ void slotExportPrivateKey();
+
+ /**
+ * @details Copy the fingerprint to clipboard
+ */
+ void slotCopyFingerprint();
+
+private:
+
+ QString *keyid; /** The id of the key the details should be shown for */
+
+ GpgME::GpgContext *mCtx; /** The current gpg-context */
+
+ QGroupBox *ownerBox; /** Groupbox containing owner information */
+ QGroupBox *keyBox; /** Groupbox containing key information */
+ QGroupBox *fingerprintBox; /** Groupbox containing fingerprint information */
+ QGroupBox *additionalUidBox; /** Groupbox containing information about additional uids */
+ QDialogButtonBox *buttonBox; /** Box containing the close button */
+
+ QLabel *nameVarLabel; /** Label containng the keys name */
+ QLabel *emailVarLabel; /** Label containng the keys email */
+ QLabel *commentVarLabel; /** Label containng the keys commment */
+ QLabel *keySizeVarLabel; /** Label containng the keys keysize */
+ QLabel *expireVarLabel; /** Label containng the keys expiration date */
+ QLabel *createdVarLabel; /** Label containng the keys creation date */
+ QLabel *algorithmVarLabel; /** Label containng the keys algorithm */
+ QLabel *keyidVarLabel; /** Label containng the keys keyid */
+ QLabel *fingerPrintVarLabel; /** Label containng the keys fingerprint */
+ QLabel *addUserIdsVarLabel{}; /** Label containng info about keys additional uids */
+ QLabel *usageVarLabel;
+
+public:
+ explicit KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent = nullptr);
+};
+
+
+#endif //GPGFRONTEND_KEYPAIRDETAILTAB_H
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index baa3783d..cf100a14 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -855,10 +855,10 @@ void MainWindow::slotCopyMailAddressToClipboard() {
if (mKeyList->getSelected()->isEmpty()) {
return;
}
-
- gpgme_key_t key = mCtx->getKeyDetails(mKeyList->getSelected()->first());
+ GpgKey key;
+ mCtx->getKeyDetails(mKeyList->getSelected()->first(), key);
QClipboard *cb = QApplication::clipboard();
- QString mail = key->uids->email;
+ QString mail = key.email;
cb->setText(mail);
}
@@ -866,9 +866,9 @@ void MainWindow::slotShowKeyDetails() {
if (mKeyList->getSelected()->isEmpty()) {
return;
}
-
- gpgme_key_t key = mCtx->getKeyDetails(mKeyList->getSelected()->first());
- if (key) {
+ GpgKey key;
+ mCtx->getKeyDetails(mKeyList->getSelected()->first(), key);
+ if (key.good) {
new KeyDetailsDialog(mCtx, key, this);
}
}
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index a423cfbf..f7a7ea5c 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -31,12 +31,6 @@
#include <windows.h>
#endif
-const QVector<QString> GenKeyInfo::SupportedKeyAlgo = {
- "RSA",
- "DSA",
- "ED25519"
-};
-
namespace GpgME {
/** Constructor
@@ -259,16 +253,17 @@ namespace GpgME {
return true;
}
- gpgme_key_t GpgContext::getKeyDetails(const QString& uid) {
- gpgme_key_t key;
+ void GpgContext::getKeyDetails(const QString& uid, GpgKey& key) {
+ gpgme_key_t gpgme_key;
// try secret
- gpgme_get_key(mCtx, uid.toUtf8().constData(), &key, 1);
+ gpgme_get_key(mCtx, uid.toUtf8().constData(), &gpgme_key, 1);
// ok, its a public key
- if (!key) {
- gpgme_get_key(mCtx, uid.toUtf8().constData(), &key, 0);
+ if (!gpgme_key) {
+ gpgme_get_key(mCtx, uid.toUtf8().constData(), &gpgme_key, 0);
}
- return key;
+
+ key.parse(gpgme_key);
}
/** List all availabe Keys (VERY much like kgpgme)
diff --git a/src/gpg/GpgGenKeyInfo.cpp b/src/gpg/GpgGenKeyInfo.cpp
new file mode 100644
index 00000000..9532e876
--- /dev/null
+++ b/src/gpg/GpgGenKeyInfo.cpp
@@ -0,0 +1,147 @@
+/**
+ * This file is part of GPGFrontend.
+ *
+ * GPGFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "gpg/GpgGenKeyInfo.h"
+
+const QVector<QString> GenKeyInfo::SupportedKeyAlgo = {
+ "RSA",
+ "DSA",
+ "ED25519"
+};
+
+void GenKeyInfo::setAlgo(const QString &m_algo) {
+
+ qDebug() << "set algo " << m_algo;
+
+ reset_options();
+
+ if (!this->subKey) {
+ this->setAllowCertification(true);
+ this->allowChangeCertification = false;
+ }
+
+ auto lower_algo = m_algo.toLower();
+
+ if(lower_algo == "rsa") {
+ /**
+ * RSA is the world’s premier asymmetric cryptographic algorithm,
+ * and is built on the difficulty of factoring extremely large composites.
+ * GnuPG supports RSA with key sizes of between 1024 and 4096 bits.
+ */
+ suggestMinKeySize = 1024;
+ suggestMaxKeySize = 4096;
+ suggestSizeAdditionStep = 1024;
+ setKeySize(2048);
+
+ } else if (lower_algo == "dsa") {
+ /**
+ * Algorithm (DSA) as a government standard for digital signatures.
+ * Originally, it supported key lengths between 512 and 1024 bits.
+ * Recently, NIST has declared 512-bit keys obsolete:
+ * now, DSA is available in 1024, 2048 and 3072-bit lengths.
+ */
+ setAllowEncryption(false);
+ allowChangeEncryption = false;
+
+ suggestMinKeySize = 1024;
+ suggestMaxKeySize = 3072;
+ suggestSizeAdditionStep = 1024;
+ setKeySize(2048);
+
+ } else if (lower_algo == "ed25519") {
+ /**
+ * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths ranging from 1024 to 4096 bits.
+ */
+
+ setAllowEncryption(false);
+ allowChangeEncryption = false;
+
+ suggestMinKeySize = -1;
+ suggestMaxKeySize = -1;
+ suggestSizeAdditionStep = -1;
+ setKeySize(-1);
+ }
+ GenKeyInfo::algo = lower_algo;
+}
+
+void GenKeyInfo::reset_options() {
+
+ allowChangeEncryption = true;
+ setAllowEncryption(true);
+
+ allowChangeCertification = true;
+ setAllowCertification(true);
+
+ allowChangeSigning = true;
+ setAllowSigning(true);
+
+ allowChangeAuthentication = true;
+ setAllowAuthentication(true);
+
+
+ passPhrase.clear();
+
+}
+
+QString GenKeyInfo::getKeySizeStr() const {
+ if(keySize > 0) {
+ return QString::number(keySize);
+ }
+ else {
+ return QString();
+ }
+
+}
+
+void GenKeyInfo::setKeySize(int m_key_size) {
+ if (m_key_size < suggestMinKeySize || m_key_size > suggestMaxKeySize) {
+ return;
+ }
+ GenKeyInfo::keySize = m_key_size;
+}
+
+void GenKeyInfo::setExpired(const QDateTime &m_expired) {
+ auto current = QDateTime::currentDateTime();
+ if (isNonExpired() && m_expired < current.addYears(2)) {
+ GenKeyInfo::expired = m_expired;
+ }
+}
+
+void GenKeyInfo::setNonExpired(bool m_non_expired) {
+ if (!m_non_expired) {
+ this->expired = QDateTime(QDateTime::fromTime_t(0));
+ }
+ GenKeyInfo::nonExpired = m_non_expired;
+}
+
+void GenKeyInfo::setAllowEncryption(bool m_allow_encryption) {
+ if(allowChangeEncryption)
+ GenKeyInfo::allowEncryption = m_allow_encryption;
+}
+
+void GenKeyInfo::setAllowCertification(bool m_allow_certification) {
+ if(allowChangeCertification)
+ GenKeyInfo::allowCertification = m_allow_certification;
+}
+
diff --git a/src/gpg/GpgKey.cpp b/src/gpg/GpgKey.cpp
index c2454807..5d474327 100644
--- a/src/gpg/GpgKey.cpp
+++ b/src/gpg/GpgKey.cpp
@@ -1,5 +1,25 @@
-//
-// Created by eric on 2021/5/21.
-//
+/**
+ * This file is part of GPGFrontend.
+ *
+ * GPGFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
#include "gpg/GpgKey.h"
diff --git a/src/gpg/GpgSubKey.cpp b/src/gpg/GpgSubKey.cpp
index 6b0ee3ca..e63c3139 100644
--- a/src/gpg/GpgSubKey.cpp
+++ b/src/gpg/GpgSubKey.cpp
@@ -1,5 +1,24 @@
-//
-// Created by eric on 2021/5/21.
-//
-
+/**
+ * This file is part of GPGFrontend.
+ *
+ * GPGFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
#include "gpg/GpgSubKey.h"
diff --git a/src/ui/KeyDetailsDialog.cpp b/src/ui/KeyDetailsDialog.cpp
index c124ef02..b181ff7b 100644
--- a/src/ui/KeyDetailsDialog.cpp
+++ b/src/ui/KeyDetailsDialog.cpp
@@ -24,205 +24,20 @@
#include "ui/KeyDetailsDialog.h"
-KeyDetailsDialog::KeyDetailsDialog(GpgME::GpgContext *ctx, gpgme_key_t key, QWidget *parent)
+KeyDetailsDialog::KeyDetailsDialog(GpgME::GpgContext *ctx, const GpgKey& key, QWidget *parent)
: QDialog(parent) {
- mCtx = ctx;
- keyid = new QString(key->subkeys->keyid);
- ownerBox = new QGroupBox(tr("Owner details"));
- keyBox = new QGroupBox(tr("Key details"));
- fingerprintBox = new QGroupBox(tr("Fingerprint"));
- additionalUidBox = new QGroupBox(tr("Additional Uids"));
- buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
- nameVarLabel = new QLabel(QString::fromUtf8(key->uids->name));
- nameVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- emailVarLabel = new QLabel(QString::fromUtf8(key->uids->email));
- emailVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ tabWidget = new QTabWidget(this);
+ tabWidget->addTab(new KeyPairDetailTab(ctx, key, this), tr("KeyPair Details"));
- commentVarLabel = new QLabel(QString::fromUtf8(key->uids->comment));
- commentVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- keyidVarLabel = new QLabel(key->subkeys->keyid);
- keyidVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ auto *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(tabWidget);
- QString keySizeVal, keyExpireVal, keyCreatedVal, keyAlgoVal;
-
- if (key->subkeys->expires == 0) {
- keyExpireVal = tr("Never");
- } else {
- keyExpireVal = QDateTime::fromTime_t(key->subkeys->expires).toString("dd. MMM. yyyy");
- }
-
- keyAlgoVal = gpgme_pubkey_algo_name(key->subkeys->pubkey_algo);
- keyCreatedVal = QDateTime::fromTime_t(key->subkeys->timestamp).toString("dd. MMM. yyyy");
-
- // have el-gamal key?
- if (key->subkeys->next) {
- keySizeVal.sprintf("%d / %d", int(key->subkeys->length), int(key->subkeys->next->length));
- if (key->subkeys->next->expires == 0) {
- keyExpireVal += tr(" / Never");
- } else {
- keyExpireVal += " / " + QDateTime::fromTime_t(key->subkeys->next->expires).toString("dd. MMM. yyyy");
- }
- keyAlgoVal.append(" / ").append(gpgme_pubkey_algo_name(key->subkeys->next->pubkey_algo));
- keyCreatedVal += " / " + QDateTime::fromTime_t(key->subkeys->next->timestamp).toString("dd. MMM. yyyy");
- } else {
- keySizeVal.setNum(int(key->subkeys->length));
- }
-
- keySizeVarLabel = new QLabel(keySizeVal);
- expireVarLabel = new QLabel(keyExpireVal);
- createdVarLabel = new QLabel(keyCreatedVal);
- algorithmVarLabel = new QLabel(keyAlgoVal);
-
- auto *mvbox = new QVBoxLayout();
- auto *vboxKD = new QGridLayout();
- auto *vboxOD = new QGridLayout();
-
- vboxOD->addWidget(new QLabel(tr("Name:")), 0, 0);
- vboxOD->addWidget(new QLabel(tr("E-Mailaddress:")), 1, 0);
- vboxOD->addWidget(new QLabel(tr("Comment:")), 2, 0);
- vboxOD->addWidget(nameVarLabel, 0, 1);
- vboxOD->addWidget(emailVarLabel, 1, 1);
- vboxOD->addWidget(commentVarLabel, 2, 1);
-
- vboxKD->addWidget(new QLabel(tr("Key size:")), 0, 0);
- vboxKD->addWidget(new QLabel(tr("Expires on: ")), 1, 0);
- vboxKD->addWidget(new QLabel(tr("Algorithm: ")), 3, 0);
- vboxKD->addWidget(new QLabel(tr("Created on: ")), 4, 0);
- vboxKD->addWidget(new QLabel(tr("Key ID: ")), 5, 0);
- vboxKD->addWidget(keySizeVarLabel, 0, 1);
- vboxKD->addWidget(expireVarLabel, 1, 1);
- vboxKD->addWidget(algorithmVarLabel, 3, 1);
- vboxKD->addWidget(createdVarLabel, 4, 1);
- vboxKD->addWidget(keyidVarLabel, 5, 1);
-
- ownerBox->setLayout(vboxOD);
- mvbox->addWidget(ownerBox);
-
- keyBox->setLayout(vboxKD);
- mvbox->addWidget(keyBox);
-
- fingerPrintVarLabel = new QLabel(beautifyFingerprint(key->subkeys->fpr));
- fingerPrintVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- fingerPrintVarLabel->setStyleSheet("margin-left: 20; margin-right: 20;");
- auto *hboxFP = new QHBoxLayout();
-
- hboxFP->addWidget(fingerPrintVarLabel);
- QIcon ico(":button_copy.png");
-
- QPushButton copyFingerprintButton(QIcon(ico.pixmap(12, 12)), "");
- //copyFingerprintButton.setStyleSheet("QPushButton {border: 0px; } QPushButton:Pressed {} ");
- copyFingerprintButton.setFlat(true);
- copyFingerprintButton.setToolTip(tr("copy fingerprint to clipboard"));
- connect(&copyFingerprintButton, SIGNAL(clicked()), this, SLOT(slotCopyFingerprint()));
-
- hboxFP->addWidget(&copyFingerprintButton);
-
- fingerprintBox->setLayout(hboxFP);
- mvbox->addWidget(fingerprintBox);
-
- // If key has more than primary uid, also show the other uids
- gpgme_user_id_t addUserIds = key->uids->next;
- if (addUserIds != nullptr) {
- auto *vboxUID = new QVBoxLayout();
- while (addUserIds != nullptr) {
- addUserIdsVarLabel = new QLabel(
- QString::fromUtf8(addUserIds->name) + QString(" <") + addUserIds->email + ">");
- addUserIdsVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- vboxUID->addWidget(addUserIdsVarLabel);
- addUserIds = addUserIds->next;
- }
- additionalUidBox->setLayout(vboxUID);
- mvbox->addWidget(additionalUidBox);
- }
-
- if (key->secret) {
- auto *privKeyBox = new QGroupBox(tr("Private Key"));
- auto *vboxPK = new QVBoxLayout();
-
- auto *exportButton = new QPushButton(tr("Export Private Key"));
- vboxPK->addWidget(exportButton);
- connect(exportButton, SIGNAL(clicked()), this, SLOT(slotExportPrivateKey()));
-
- privKeyBox->setLayout(vboxPK);
- mvbox->addWidget(privKeyBox);
- }
-
- if ((key->expired) || (key->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) {
- expLabel->setText(tr("Warning: Key expired"));
- }
- if (key->revoked) {
- expLabel->setText(tr("Warning: Key revoked"));
- }
-
- iconLabel->setPixmap(pixmap);
- QFont font = expLabel->font();
- font.setBold(true);
- expLabel->setFont(font);
- expBox->addWidget(iconLabel);
- expBox->addWidget(expLabel);
- mvbox->addLayout(expBox);
- }
-
- mvbox->addWidget(buttonBox);
-
- this->setLayout(mvbox);
+ this->setLayout(mainLayout);
this->setWindowTitle(tr("Keydetails"));
this->setModal(true);
this->show();
exec();
-}
-
-void KeyDetailsDialog::slotExportPrivateKey() {
- // Show a information box with explanation about private key
- int ret = QMessageBox::information(this, tr("Exporting private Key"),
- tr("You are about to export your private key.\n"
- "This is NOT your public key, so don't give it away.\n"
- "Make sure you keep it save."
- "Do you really want to export your private key?"),
- QMessageBox::Cancel | QMessageBox::Ok);
-
- // export key, if ok was clicked
- if (ret == QMessageBox::Ok) {
- auto *keyArray = new QByteArray();
- mCtx->exportSecretKey(*keyid, keyArray);
- gpgme_key_t key = mCtx->getKeyDetails(*keyid);
- QString fileString = QString::fromUtf8(key->uids->name) + " " + QString::fromUtf8(key->uids->email) + "(" +
- QString(key->subkeys->keyid) + ")_pub_sec.asc";
- QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), fileString,
- tr("Key Files") + " (*.asc *.txt);;All Files (*)");
- QFile file(fileName);
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- QMessageBox::critical(nullptr, tr("Export error"), tr("Couldn't open %1 for writing").arg(fileName));
- return;
- }
- QTextStream stream(&file);
- stream << *keyArray;
- file.close();
- delete keyArray;
- }
-}
-
-QString KeyDetailsDialog::beautifyFingerprint(QString fingerprint) {
- uint len = fingerprint.length();
- if ((len > 0) && (len % 4 == 0))
- for (uint n = 0; 4 * (n + 1) < len; ++n)
- fingerprint.insert(static_cast<int>(5u * n + 4u), ' ');
- return fingerprint;
-}
-
-void KeyDetailsDialog::slotCopyFingerprint() {
- QString fpr = fingerPrintVarLabel->text().trimmed().replace(" ", "");
- QClipboard *cb = QApplication::clipboard();
- cb->setText(fpr);
-}
+} \ No newline at end of file
diff --git a/src/ui/KeyList.cpp b/src/ui/KeyList.cpp
index ab812b22..a561b738 100644
--- a/src/ui/KeyList.cpp
+++ b/src/ui/KeyList.cpp
@@ -48,7 +48,7 @@ KeyList::KeyList(GpgME::GpgContext *ctx, QWidget *parent)
mKeyList->setAlternatingRowColors(true);
QStringList labels;
- labels << "" << tr("Type") << tr("Name") << tr("Email Address")
+ labels << tr("Select") << tr("Type") << tr("Name") << tr("Email Address")
<< tr("Usage") << tr("Validity") << tr("Finger Print");
mKeyList->setHorizontalHeaderLabels(labels);
mKeyList->horizontalHeader()->setStretchLastSection(true);
@@ -84,8 +84,9 @@ void KeyList::slotRefresh()
buffered_keys.push_back(*it);
- auto *tmp0 = new QTableWidgetItem();
+ auto *tmp0 = new QTableWidgetItem(QString::number(row));
tmp0->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ tmp0->setTextAlignment(Qt::AlignCenter);
tmp0->setCheckState(Qt::Unchecked);
mKeyList->setItem(row, 0, tmp0);
@@ -124,10 +125,16 @@ void KeyList::slotRefresh()
usage_steam << "A";
auto *temp_usage = new QTableWidgetItem(usage);
- mKeyList->setToolTip(usage);
temp_usage->setTextAlignment(Qt::AlignCenter);
mKeyList->setItem(row, 4, temp_usage);
+ auto *temp_validity = new QTableWidgetItem(it->owner_trust);
+ temp_validity->setTextAlignment(Qt::AlignCenter);
+ mKeyList->setItem(row, 5, temp_validity);
+
+ auto *temp_fpr = new QTableWidgetItem(it->fpr);
+ temp_fpr->setTextAlignment(Qt::AlignCenter);
+ mKeyList->setItem(row, 6, temp_fpr);
it++;
++row;
@@ -152,7 +159,7 @@ QStringList *KeyList::getAllPrivateKeys()
auto *ret = new QStringList();
for (int i = 0; i < mKeyList->rowCount(); i++) {
if (mKeyList->item(i, 1)) {
- *ret << mKeyList->item(i, 4)->text();
+ *ret << buffered_keys[i].id;
}
}
return ret;
@@ -163,7 +170,7 @@ QStringList *KeyList::getPrivateChecked()
auto *ret = new QStringList();
for (int i = 0; i < mKeyList->rowCount(); i++) {
if ((mKeyList->item(i, 0)->checkState() == Qt::Checked) && (mKeyList->item(i, 1))) {
- *ret << mKeyList->item(i, 4)->text();
+ *ret << buffered_keys[i].id;
}
}
return ret;
@@ -173,7 +180,7 @@ void KeyList::setChecked(QStringList *keyIds)
{
if (!keyIds->isEmpty()) {
for (int i = 0; i < mKeyList->rowCount(); i++) {
- if (keyIds->contains(mKeyList->item(i, 4)->text())) {
+ if (keyIds->contains(buffered_keys[i].id)) {
mKeyList->item(i, 0)->setCheckState(Qt::Checked);
}
}
@@ -186,7 +193,7 @@ QStringList *KeyList::getSelected()
for (int i = 0; i < mKeyList->rowCount(); i++) {
if (mKeyList->item(i, 0)->isSelected() == 1) {
- *ret << mKeyList->item(i, 4)->text();
+ *ret << buffered_keys[i].id;
}
}
return ret;
diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp
index 2904dd0c..1078778e 100755
--- a/src/ui/KeyMgmt.cpp
+++ b/src/ui/KeyMgmt.cpp
@@ -234,9 +234,11 @@ void KeyMgmt::deleteKeysWithWarning(QStringList *uidList)
}
QString keynames;
foreach (QString uid, *uidList) {
- keynames.append(QString::fromUtf8(mCtx->getKeyDetails(uid)->uids->name));
+ GpgKey key;
+ mCtx->getKeyDetails(uid, key);
+ keynames.append(key.name);
keynames.append("<i> &lt;");
- keynames.append(QString::fromUtf8(mCtx->getKeyDetails(uid)->uids->email));
+ keynames.append(key.email);
keynames.append("&gt; </i><br/>");
}
@@ -256,8 +258,9 @@ void KeyMgmt::slotShowKeyDetails()
return;
}
- // TODO: first...?
- gpgme_key_t key = mCtx->getKeyDetails(mKeyList->getSelected()->first());
+ GpgKey key;
+
+ mCtx->getKeyDetails(mKeyList->getSelected()->first(), key);
new KeyDetailsDialog(mCtx, key);
}
@@ -268,8 +271,9 @@ void KeyMgmt::slotExportKeyToFile()
if (!mCtx->exportKeys(mKeyList->getChecked(), keyArray)) {
return;
}
- gpgme_key_t key = mCtx->getKeyDetails(mKeyList->getChecked()->first());
- QString fileString = QString::fromUtf8(key->uids->name) + " " + QString::fromUtf8(key->uids->email) + "(" + QString(key->subkeys->keyid)+ ")_pub.asc";
+ GpgKey key;
+ mCtx->getKeyDetails(mKeyList->getChecked()->first(), key);
+ QString fileString = key.name + " " + key.email+ "(" + key.id+ ")_pub.asc";
QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), fileString, tr("Key Files") + " (*.asc *.txt);;All Files (*)");
QFile file(fileName);
diff --git a/src/ui/KeyPairDetailTab.cpp b/src/ui/KeyPairDetailTab.cpp
new file mode 100644
index 00000000..30be2a77
--- /dev/null
+++ b/src/ui/KeyPairDetailTab.cpp
@@ -0,0 +1,209 @@
+//
+// Created by eric on 2021/5/21.
+//
+
+#include "ui/KeyPairDetailTab.h"
+
+KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : QWidget(parent) {
+
+ mCtx = ctx;
+ keyid = new QString(key.id);
+
+ ownerBox = new QGroupBox(tr("Owner details"));
+ keyBox = new QGroupBox(tr("Key details"));
+ fingerprintBox = new QGroupBox(tr("Fingerprint"));
+ additionalUidBox = new QGroupBox(tr("Additional Uids"));
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
+
+ nameVarLabel = new QLabel(key.name);
+ nameVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ emailVarLabel = new QLabel(key.email);
+ emailVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+
+ commentVarLabel = new QLabel(key.comment);
+ commentVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ keyidVarLabel = new QLabel(key.id);
+ keyidVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+
+ QString usage;
+ QTextStream usage_steam(&usage);
+
+ if(key.can_certify)
+ usage_steam << "Cert ";
+ if(key.can_encrypt)
+ usage_steam << "Encr ";
+ if(key.can_sign)
+ usage_steam << "Sign ";
+ if(key.can_authenticate)
+ usage_steam << "Auth ";
+
+ usageVarLabel = new QLabel(usage);
+
+ QString keySizeVal, keyExpireVal, keyCreateTimeVal, keyAlgoVal;
+
+ keySizeVal = QString::number(key.length);
+
+ if (key.expires.toTime_t() == 0) {
+ keyExpireVal = tr("Never");
+ } else {
+ keyExpireVal = key.expires.toString();
+ }
+
+ keyAlgoVal = key.pubkey_algo;
+ keyCreateTimeVal = key.create_time.toString();
+
+ keySizeVarLabel = new QLabel(keySizeVal);
+ expireVarLabel = new QLabel(keyExpireVal);
+ createdVarLabel = new QLabel(keyCreateTimeVal);
+ algorithmVarLabel = new QLabel(keyAlgoVal);
+
+ auto *mvbox = new QVBoxLayout();
+ auto *vboxKD = new QGridLayout();
+ auto *vboxOD = new QGridLayout();
+
+ vboxOD->addWidget(new QLabel(tr("Name:")), 0, 0);
+ vboxOD->addWidget(new QLabel(tr("Email Address:")), 1, 0);
+ vboxOD->addWidget(new QLabel(tr("Comment:")), 2, 0);
+ vboxOD->addWidget(nameVarLabel, 0, 1);
+ vboxOD->addWidget(emailVarLabel, 1, 1);
+ vboxOD->addWidget(commentVarLabel, 2, 1);
+
+ vboxKD->addWidget(new QLabel(tr("Key size:")), 0, 0);
+ vboxKD->addWidget(new QLabel(tr("Expires on: ")), 1, 0);
+ vboxKD->addWidget(new QLabel(tr("Algorithm: ")), 3, 0);
+ vboxKD->addWidget(new QLabel(tr("Last Update: ")), 4, 0);
+ vboxKD->addWidget(new QLabel(tr("Key ID: ")), 5, 0);
+ vboxKD->addWidget(new QLabel(tr("Usage: ")), 6, 0);
+ vboxKD->addWidget(keySizeVarLabel, 0, 1);
+ vboxKD->addWidget(expireVarLabel, 1, 1);
+ vboxKD->addWidget(algorithmVarLabel, 3, 1);
+ vboxKD->addWidget(createdVarLabel, 4, 1);
+ vboxKD->addWidget(keyidVarLabel, 5, 1);
+ vboxKD->addWidget(usageVarLabel, 6, 1);
+
+ ownerBox->setLayout(vboxOD);
+ mvbox->addWidget(ownerBox);
+
+ keyBox->setLayout(vboxKD);
+ mvbox->addWidget(keyBox);
+
+ fingerPrintVarLabel = new QLabel(beautifyFingerprint(key.fpr));
+ fingerPrintVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ fingerPrintVarLabel->setStyleSheet("margin-left: 20; margin-right: 20;");
+ auto *hboxFP = new QHBoxLayout();
+
+ hboxFP->addWidget(fingerPrintVarLabel);
+ QIcon ico(":button_copy.png");
+
+ QPushButton copyFingerprintButton(QIcon(ico.pixmap(12, 12)), "");
+ //copyFingerprintButton.setStyleSheet("QPushButton {border: 0px; } QPushButton:Pressed {} ");
+ copyFingerprintButton.setFlat(true);
+ copyFingerprintButton.setToolTip(tr("copy fingerprint to clipboard"));
+ connect(&copyFingerprintButton, SIGNAL(clicked()), this, SLOT(slotCopyFingerprint()));
+
+ hboxFP->addWidget(&copyFingerprintButton);
+
+ fingerprintBox->setLayout(hboxFP);
+ mvbox->addWidget(fingerprintBox);
+
+ // If key has more than primary uid, also show the other uids
+// gpgme_user_id_t addUserIds = key->uids->next;
+// if (addUserIds != nullptr) {
+// auto *vboxUID = new QVBoxLayout();
+// while (addUserIds != nullptr) {
+// addUserIdsVarLabel = new QLabel(
+// QString::fromUtf8(addUserIds->name) + QString(" <") + addUserIds->email + ">");
+// addUserIdsVarLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+// vboxUID->addWidget(addUserIdsVarLabel);
+// addUserIds = addUserIds->next;
+// }
+// additionalUidBox->setLayout(vboxUID);
+// mvbox->addWidget(additionalUidBox);
+// }
+
+ if (key.is_private_key) {
+ auto *privKeyBox = new QGroupBox(tr("Private Key"));
+ auto *vboxPK = new QVBoxLayout();
+
+ auto *exportButton = new QPushButton(tr("Export Private Key"));
+ vboxPK->addWidget(exportButton);
+ connect(exportButton, SIGNAL(clicked()), this, SLOT(slotExportPrivateKey()));
+
+ privKeyBox->setLayout(vboxPK);
+ mvbox->addWidget(privKeyBox);
+ }
+
+ if ((key.expired) || (key.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) {
+ expLabel->setText(tr("Warning: Key expired"));
+ }
+ if (key.revoked) {
+ expLabel->setText(tr("Warning: Key revoked"));
+ }
+
+ iconLabel->setPixmap(pixmap);
+ QFont font = expLabel->font();
+ font.setBold(true);
+ expLabel->setFont(font);
+ expBox->addWidget(iconLabel);
+ expBox->addWidget(expLabel);
+ mvbox->addLayout(expBox);
+ }
+
+ mvbox->addWidget(buttonBox);
+
+ setLayout(mvbox);
+}
+
+void KeyPairDetailTab::slotExportPrivateKey() {
+ // Show a information box with explanation about private key
+ int ret = QMessageBox::information(this, tr("Exporting private Key"),
+ tr("You are about to export your private key.\n"
+ "This is NOT your public key, so don't give it away.\n"
+ "Make sure you keep it save."
+ "Do you really want to export your private key?"),
+ QMessageBox::Cancel | QMessageBox::Ok);
+
+ // export key, if ok was clicked
+ if (ret == QMessageBox::Ok) {
+ auto *keyArray = new QByteArray();
+ mCtx->exportSecretKey(*keyid, keyArray);
+ GpgKey key;
+ mCtx->getKeyDetails(*keyid, key);
+ QString fileString = key.name + " " +key.email + "(" +
+ key.id + ")_pub_sec.asc";
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), fileString,
+ tr("Key Files") + " (*.asc *.txt);;All Files (*)");
+ QFile file(fileName);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ QMessageBox::critical(nullptr, tr("Export error"), tr("Couldn't open %1 for writing").arg(fileName));
+ return;
+ }
+ QTextStream stream(&file);
+ stream << *keyArray;
+ file.close();
+ delete keyArray;
+ }
+}
+
+QString KeyPairDetailTab::beautifyFingerprint(QString fingerprint) {
+ uint len = fingerprint.length();
+ if ((len > 0) && (len % 4 == 0))
+ for (uint n = 0; 4 * (n + 1) < len; ++n)
+ fingerprint.insert(static_cast<int>(5u * n + 4u), ' ');
+ return fingerprint;
+}
+
+void KeyPairDetailTab::slotCopyFingerprint() {
+ QString fpr = fingerPrintVarLabel->text().trimmed().replace(" ", "");
+ QClipboard *cb = QApplication::clipboard();
+ cb->setText(fpr);
+}
+
diff --git a/src/ui/KeygenDialog.cpp b/src/ui/KeygenDialog.cpp
index 1ebe45f3..2b9fb88e 100644
--- a/src/ui/KeygenDialog.cpp
+++ b/src/ui/KeygenDialog.cpp
@@ -69,7 +69,7 @@ void KeyGenDialog::generateKeyDialog() {
auto *vbox1 = new QGridLayout;
vbox1->addWidget(new QLabel(tr("Name:")), 0, 0);
- vbox1->addWidget(new QLabel(tr("E-Mail:")), 1, 0);
+ vbox1->addWidget(new QLabel(tr("Email Address:")), 1, 0);
vbox1->addWidget(new QLabel(tr("Comment:")), 2, 0);
vbox1->addWidget(new QLabel(tr("Expiration Date:")), 3, 0);
vbox1->addWidget(new QLabel(tr("Never Expire")), 3, 3);
diff --git a/src/ui/SettingsDialog.cpp b/src/ui/SettingsDialog.cpp
index 1a1b090c..f7cd0c50 100755
--- a/src/ui/SettingsDialog.cpp
+++ b/src/ui/SettingsDialog.cpp
@@ -183,18 +183,19 @@ GeneralTab::GeneralTab(GpgME::GpgContext *ctx, QWidget *parent)
// Fill the keyid hashmap
keyIds.insert("", tr("<none>"));
- foreach (QString keyid, *mKeyList->getAllPrivateKeys()) {
- gpgme_key_t key = mCtx->getKeyDetails(keyid);
+ foreach (QString keyid, *mKeyList->getAllPrivateKeys()) {
+ GpgKey key;
+ mCtx->getKeyDetails(keyid, key);
QString newKey = " (" + keyid + ")";
- if (!QString(key->uids->email).isEmpty()) {
- newKey.prepend(" <" + QString::fromUtf8(key->uids->email) + ">");
+ if (!QString(key.email).isEmpty()) {
+ newKey.prepend(" <" + key.email + ">");
}
- if (!QString(key->uids->name).isEmpty()) {
- newKey.prepend(" " + QString::fromUtf8(key->uids->name));
+ if (!QString(key.name).isEmpty()) {
+ newKey.prepend(" " + key.name);
}
- keyIds.insert(key->uids->uid, newKey);
+ keyIds.insert(key.id, newKey);
}
- foreach(QString k, keyIds) {
+ foreach(QString k, keyIds) {
ownKeySelectBox->addItem(k);
}
connect(ownKeySelectBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotOwnKeyIdChanged()));