aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
11 files changed, 456 insertions, 239 deletions
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()));