aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-07-01 18:07:42 +0000
committerSaturneric <[email protected]>2021-07-01 18:07:42 +0000
commitbf033884a652f32c207046b0f3dcdcc0d225150c (patch)
tree8c89d964c51cebc7333e6cbe829dc343425958ca
parentMerge branch 'develop-ci' (diff)
downloadGpgFrontend-bf033884a652f32c207046b0f3dcdcc0d225150c.tar.gz
GpgFrontend-bf033884a652f32c207046b0f3dcdcc0d225150c.zip
Export Secret Key Fixed.
Start Wizard Modified. Another Bugs Fixed.
-rw-r--r--include/gpg/GpgContext.h2
-rw-r--r--include/ui/KeyUploadDialog.h6
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/gpg/GpgContext.cpp37
-rw-r--r--src/ui/KeyImportDetailDialog.cpp5
-rw-r--r--src/ui/KeyServerImportDialog.cpp2
-rw-r--r--src/ui/KeyUploadDialog.cpp45
-rw-r--r--src/ui/Wizard.cpp55
-rw-r--r--src/ui/keypair_details/KeyPairDetailTab.cpp14
-rw-r--r--src/ui/keypair_details/KeyPairSubkeyTab.cpp5
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp5
11 files changed, 106 insertions, 74 deletions
diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h
index 1e5334d1..e243cc53 100644
--- a/include/gpg/GpgContext.h
+++ b/include/gpg/GpgContext.h
@@ -99,7 +99,7 @@ namespace GpgME {
void clearPasswordCache();
- void exportSecretKey(const QString &uid, QByteArray *outBuffer);
+ bool exportSecretKey(const GpgKey &key, QByteArray *outBuffer);
void getSigners(QVector<GpgKey> &signer);
diff --git a/include/ui/KeyUploadDialog.h b/include/ui/KeyUploadDialog.h
index 013c0b72..b41ced6b 100644
--- a/include/ui/KeyUploadDialog.h
+++ b/include/ui/KeyUploadDialog.h
@@ -33,6 +33,10 @@ Q_OBJECT
public:
KeyUploadDialog(GpgME::GpgContext *ctx, const QVector<GpgKey> &keys, QWidget *parent = nullptr);
+public slots:
+
+ void slotUpload();
+
private slots:
void uploadKeyToServer(QByteArray &keys);
@@ -41,6 +45,8 @@ private slots:
private:
+ GpgME::GpgContext *mCtx;
+ const QVector<GpgKey> &mKeys;
QString appPath;
QSettings settings;
QByteArray mKeyData;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0121dc71..97fae047 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -21,8 +21,8 @@ if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
if(APPLE)
set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources)
elseif(LINUX)
- file(COPY ${CMAKE_SOURCE_DIR}/resource/gpgfrontend DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN)
- set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gpgfrontend/usr/share)
+ file(COPY ${CMAKE_SOURCE_DIR}/resource/gpgfrontend DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ FOLLOW_SYMLINK_CHAIN)
+ set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gpgfrontend/usr/share)
endif()
else()
set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index 603ad90b..67bae907 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -653,22 +653,27 @@ namespace GpgME {
return QString::fromUtf8(gpgme_strerror(err));
}
-/** export private key, TODO errohandling, e.g. like in seahorse (seahorse-gpg-op.c) **/
-
- void GpgContext::exportSecretKey(const QString &uid, QByteArray *outBuffer) {
- qDebug() << *outBuffer;
+ bool GpgContext::exportSecretKey(const GpgKey &key, QByteArray *outBuffer) {
+ qDebug() << "Export Secret Key" << key.id;
+ gpgme_key_t target_key[2] = {
+ key.key_refer,
+ nullptr
+ };
+
+ gpgme_data_t dataOut;
+ gpgme_data_new(&dataOut);
// export private key to outBuffer
- QStringList arguments;
- arguments << "--armor" << "--export-secret-key" << uid;
- auto *p_errArray = new QByteArray();
- executeGpgCommand(arguments, outBuffer, p_errArray);
-
- // append public key to outBuffer
- auto *pubKey = new QByteArray();
- QStringList keyList;
- keyList.append(uid);
- exportKeys(&keyList, pubKey);
- outBuffer->append(*pubKey);
+ gpgme_error_t error = gpgme_op_export_keys(mCtx, target_key,GPGME_EXPORT_MODE_SECRET, dataOut);
+
+ if(gpgme_err_code(error) != GPG_ERR_NO_ERROR) {
+ checkErr(error);
+ gpgme_data_release(dataOut);
+ return false;
+ }
+
+ readToBuffer(dataOut, outBuffer);
+ gpgme_data_release(dataOut);
+ return true;
}
/** return type should be gpgme_error_t*/
@@ -1241,4 +1246,4 @@ namespace GpgME {
}
return true;
}
-} \ No newline at end of file
+}
diff --git a/src/ui/KeyImportDetailDialog.cpp b/src/ui/KeyImportDetailDialog.cpp
index 3d8d1cdc..8d303886 100644
--- a/src/ui/KeyImportDetailDialog.cpp
+++ b/src/ui/KeyImportDetailDialog.cpp
@@ -26,9 +26,8 @@
KeyImportDetailDialog::KeyImportDetailDialog(GpgME::GpgContext *ctx, GpgImportInformation result, bool automatic,
QWidget *parent)
- : QDialog(parent) {
- mCtx = ctx;
- mResult = std::move(result);
+ : QDialog(parent), mCtx(ctx), mResult(std::move(result)) {
+
// If no key for import found, just show a message
if (mResult.considered == 0) {
if(automatic)
diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp
index 384e4582..ec740691 100644
--- a/src/ui/KeyServerImportDialog.cpp
+++ b/src/ui/KeyServerImportDialog.cpp
@@ -120,8 +120,6 @@ KeyServerImportDialog::KeyServerImportDialog(GpgME::GpgContext *ctx, KeyList *ke
}
}
-
-
this->setModal(true);
}
diff --git a/src/ui/KeyUploadDialog.cpp b/src/ui/KeyUploadDialog.cpp
index c9213e08..e28b4230 100644
--- a/src/ui/KeyUploadDialog.cpp
+++ b/src/ui/KeyUploadDialog.cpp
@@ -27,10 +27,27 @@
#include <utility>
KeyUploadDialog::KeyUploadDialog(GpgME::GpgContext *ctx, const QVector<GpgKey> &keys, QWidget *parent)
-: appPath(qApp->applicationDirPath()),
-settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat),
-QDialog(parent) {
- ctx->exportKeys(keys, mKeyData);
+ : appPath(qApp->applicationDirPath()),
+ settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat),
+ mCtx(ctx),
+ mKeys(keys),
+ QDialog(parent) {
+
+
+ auto *pb = new QProgressBar();
+ pb->setRange(0, 0);
+
+ auto *layout = new QVBoxLayout();
+ layout->addWidget(pb);
+ this->setLayout(layout);
+
+ this->setModal(true);
+ this->setWindowTitle(tr("Uploading Public Key"));
+ this->setFixedSize(240, 42);
+}
+
+void KeyUploadDialog::slotUpload() {
+ mCtx->exportKeys(mKeys, mKeyData);
uploadKeyToServer(mKeyData);
}
@@ -66,30 +83,14 @@ void KeyUploadDialog::uploadKeyToServer(QByteArray &keys) {
this, SLOT(slotUploadFinished()));
- // A Waiting Dialog
- auto *dialog = new QDialog(this, Qt::CustomizeWindowHint | Qt::WindowTitleHint);
- dialog->setModal(true);
- dialog->setWindowTitle(tr("Uploading Public Key"));
- dialog->setFixedSize(200, 42);
-
- auto *pb = new QProgressBar();
- pb->setRange(0, 0);
-
- auto *layout = new QVBoxLayout(dialog);
- layout->addWidget(pb);
- dialog->setLayout(layout);
-
-
- dialog->show();
-
// Keep Waiting
while(reply->isRunning()) {
QApplication::processEvents();
}
// Done
- dialog->hide();
- dialog->close();
+ this->hide();
+ this->close();
}
void KeyUploadDialog::slotUploadFinished() {
diff --git a/src/ui/Wizard.cpp b/src/ui/Wizard.cpp
index b3236cfc..456e8c52 100644
--- a/src/ui/Wizard.cpp
+++ b/src/ui/Wizard.cpp
@@ -162,27 +162,34 @@ ChoosePage::ChoosePage(QWidget *parent)
setSubTitle(tr("...by clicking on the appropriate link."));
auto *keygenLabel = new QLabel(tr("If you have never used GPGFrontend before and also don't own a gpg key yet you "
- "may possibly want to ") + "<a href=""Wizard::Page_GenKey"">"
+ "may possibly want to read how to") + "<a href=\"https://saturneric.github.io/GpgFrontend/index.html#/manual/generate-key\">"
+ tr("create a new keypair") + "</a><hr>");
+ keygenLabel->setTextFormat(Qt::RichText);
+ keygenLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ keygenLabel->setOpenExternalLinks(true);
keygenLabel->setWordWrap(true);
- // connect(keygenLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotJumpPage(Qtring)));
- auto *importGpg4usbLabel = new QLabel(tr("If you upgrade from an older version of GPGFrontend you may want to ")
- + "<a href=""Wizard::Page_ImportFromGpg4usb"">"
- + tr("import settings and/or keys from GPGFrontend") + "</a>");
- importGpg4usbLabel->setWordWrap(true);
- connect(importGpg4usbLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotJumpPage(QString)));
+ auto *encrDecyTextLabel = new QLabel(tr("If you want to learn how to encrypt and decrypt text, you can read ")
+ + "<a href=\"https://saturneric.github.io/GpgFrontend/index.html#/manual/encrypt-decrypt-text\">"
+ + tr("this document") + "</a><hr>");
- auto *importGnupgLabel = new QLabel(tr("If you are already using GnuPG you may want to ")
- + "<a href=""Wizard::Page_ImportFromGnupg"">"
- + tr("import keys from GnuPG") + "</a><hr>");
- importGnupgLabel->setWordWrap(true);
- connect(importGnupgLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotJumpPage(QString)));
+ encrDecyTextLabel->setTextFormat(Qt::RichText);
+ encrDecyTextLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ encrDecyTextLabel->setOpenExternalLinks(true);
+ encrDecyTextLabel->setWordWrap(true);
+
+ auto *signVerifyTextLabel = new QLabel(tr("If you want to sign and verify text, you can read ")
+ + "<a href=\"https://saturneric.github.io/GpgFrontend/index.html#/manual/sign-verify-text\">"
+ + tr("this document") + "</a>");
+ signVerifyTextLabel->setTextFormat(Qt::RichText);
+ signVerifyTextLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ signVerifyTextLabel->setOpenExternalLinks(true);
+ signVerifyTextLabel->setWordWrap(true);
auto *layout = new QVBoxLayout();
layout->addWidget(keygenLabel);
- layout->addWidget(importGnupgLabel);
- layout->addWidget(importGpg4usbLabel);
+ layout->addWidget(encrDecyTextLabel);
+ layout->addWidget(signVerifyTextLabel);
setLayout(layout);
nextPage = Wizard::Page_Conclusion;
}
@@ -369,7 +376,7 @@ KeyGenPage::KeyGenPage(GpgME::GpgContext *ctx, QWidget *parent)
layout->addWidget(topLabel);
layout->addWidget(linkLabel);
layout->addWidget(createKeyButtonBox);
- connect(createKeyButton, SIGNAL(clicked()), this, SLOT(slotGenerateKeyDialog()));
+ connect(createKeyButton, SIGNAL(clicked(bool)), this, SLOT(slotGenerateKeyDialog()));
setLayout(layout);
}
@@ -379,8 +386,9 @@ int KeyGenPage::nextId() const {
}
void KeyGenPage::slotGenerateKeyDialog() {
+ qDebug() << "Try Opening KeyGenDialog";
auto *keyGenDialog = new KeyGenDialog(mCtx, this);
- keyGenDialog->exec();
+ keyGenDialog->show();
wizard()->next();
}
@@ -389,9 +397,14 @@ ConclusionPage::ConclusionPage(QWidget *parent)
setTitle(tr("Ready."));
setSubTitle(tr("Have fun with GPGFrontend!"));
- auto *bottomLabel = new QLabel(tr("You are ready to use GPGFrontend now.<br><br>"
- "The offline help will get you started with GPGFrontend. "
- "It will open in the main window.<br>"));
+ auto *bottomLabel = new QLabel(tr("You are ready to use GPGFrontend now.<br><br>")+
+ "<a href=\"https://saturneric.github.io/GpgFrontend/index.html#/overview\">"
+ + tr("The Online Document") + "</a>"
+ + tr(" will get you started with GPGFrontend. It will open in the main window.<br>"));
+
+ bottomLabel->setTextFormat(Qt::RichText);
+ bottomLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ bottomLabel->setOpenExternalLinks(true);
bottomLabel->setWordWrap(true);
openHelpCheckBox = new QCheckBox(tr("Open offline help."));
@@ -401,11 +414,11 @@ ConclusionPage::ConclusionPage(QWidget *parent)
dontShowWizardCheckBox->setChecked(Qt::Checked);
registerField("showWizard", dontShowWizardCheckBox);
- registerField("openHelp", openHelpCheckBox);
+ // registerField("openHelp", openHelpCheckBox);
auto *layout = new QVBoxLayout;
layout->addWidget(bottomLabel);
- layout->addWidget(openHelpCheckBox);
+ // layout->addWidget(openHelpCheckBox);
layout->addWidget(dontShowWizardCheckBox);
setLayout(layout);
setVisible(true);
diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp
index c72a7685..013d8e11 100644
--- a/src/ui/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/keypair_details/KeyPairDetailTab.cpp
@@ -131,16 +131,17 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, Q
auto *privKeyBox = new QGroupBox(tr("Operations"));
auto *vboxPK = new QVBoxLayout();
- auto *exportButton = new QPushButton(tr("Export Private Key"));
+ auto *exportButton = new QPushButton(tr("Export Private Key (Include Subkeys)"));
vboxPK->addWidget(exportButton);
connect(exportButton, SIGNAL(clicked()), this, SLOT(slotExportPrivateKey()));
if(mKey.has_master_key) {
- auto *editExpiresButton = new QPushButton(tr("Modify Expiration Datetime"));
+ auto *editExpiresButton = new QPushButton(tr("Modify Expiration Datetime (Master Key)"));
vboxPK->addWidget(editExpiresButton);
connect(editExpiresButton, SIGNAL(clicked()), this, SLOT(slotModifyEditDatetime()));
- auto *keyServerOperaButton = new QPushButton(tr("Key Server Operation"));
+ auto *keyServerOperaButton = new QPushButton(tr("Key Server Operation (Pubkey)"));
+ keyServerOperaButton->setStyleSheet("text-align:center;");
vboxPK->addWidget(keyServerOperaButton);
connect(keyServerOperaButton, SIGNAL(clicked()), this, SLOT(slotModifyEditDatetime()));
@@ -197,7 +198,12 @@ void KeyPairDetailTab::slotExportPrivateKey() {
// export key, if ok was clicked
if (ret == QMessageBox::Ok) {
auto *keyArray = new QByteArray();
- mCtx->exportSecretKey(*keyid, keyArray);
+
+ if(!mCtx->exportSecretKey(mKey, keyArray)) {
+ QMessageBox::critical(this, "Error", "An error occurred during the export operation.");
+ return;
+ }
+
auto &key = mCtx->getKeyById(*keyid);
QString fileString = key.name + " " +key.email + "(" +
key.id + ")_secret.asc";
diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp
index c5647553..70c7e4b8 100644
--- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp
@@ -222,7 +222,7 @@ void KeyPairSubkeyTab::slotRefreshSubkeyDetail() {
}
void KeyPairSubkeyTab::createSubkeyOperaMenu() {
- subkeyOperaMenu = new QMenu();
+ subkeyOperaMenu = new QMenu(this);
// auto *revokeSubkeyAct = new QAction(tr("Revoke Subkey"));
auto *editSubkeyAct = new QAction(tr("Edit Expire Date"));
connect(editSubkeyAct, SIGNAL(triggered(bool)), this, SLOT(slotEditSubkey()));
@@ -232,6 +232,7 @@ void KeyPairSubkeyTab::createSubkeyOperaMenu() {
}
void KeyPairSubkeyTab::slotEditSubkey() {
+ qDebug() << "Slot Edit Subkry";
auto *subkey = getSelectedSubkey();
if(subkey == buffered_subkeys[0]) {
subkey = nullptr;
@@ -245,7 +246,7 @@ void KeyPairSubkeyTab::slotRevokeSubkey() {
}
void KeyPairSubkeyTab::contextMenuEvent(QContextMenuEvent *event) {
- if (subkeyList->selectedItems().length() > 0) {
+ if (!subkeyList->selectedItems().isEmpty()) {
subkeyOperaMenu->exec(event->globalPos());
}
}
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 60c33d83..9c5d500a 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -25,6 +25,7 @@
#include "MainWindow.h"
void MainWindow::slotEncrypt() {
+
if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) {
return;
}
@@ -241,7 +242,9 @@ void MainWindow::refreshKeysFromKeyserver() {
void MainWindow::uploadKeyToServer() {
QVector<GpgKey> keys;
keys.append(mKeyList->getSelectedKey());
- auto *dialog = new KeyUploadDialog(mCtx, keys);
+ auto *dialog = new KeyUploadDialog(mCtx, keys, this);
+ dialog->show();
+ dialog->slotUpload();
}
void MainWindow::slotFileEncrypt() {