Skip to content

Commit

Permalink
Export Secret Key Fixed.
Browse files Browse the repository at this point in the history
Start Wizard Modified.
Another Bugs Fixed.
  • Loading branch information
saturneric committed Jul 1, 2021
1 parent c337ff3 commit 0de1cf6
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 74 deletions.
2 changes: 1 addition & 1 deletion include/gpg/GpgContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions include/ui/KeyUploadDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -41,6 +45,8 @@ private slots:

private:

GpgME::GpgContext *mCtx;
const QVector<GpgKey> &mKeys;
QString appPath;
QSettings settings;
QByteArray mKeyData;
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
37 changes: 21 additions & 16 deletions src/gpg/GpgContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand Down Expand Up @@ -1241,4 +1246,4 @@ namespace GpgME {
}
return true;
}
}
}
5 changes: 2 additions & 3 deletions src/ui/KeyImportDetailDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/ui/KeyServerImportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ KeyServerImportDialog::KeyServerImportDialog(GpgME::GpgContext *ctx, KeyList *ke
}
}



this->setModal(true);
}

Expand Down
45 changes: 23 additions & 22 deletions src/ui/KeyUploadDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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() {
Expand Down
55 changes: 34 additions & 21 deletions src/ui/Wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}

Expand All @@ -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."));
Expand All @@ -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);
Expand Down
14 changes: 10 additions & 4 deletions src/ui/keypair_details/KeyPairDetailTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down Expand Up @@ -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";
Expand Down
5 changes: 3 additions & 2 deletions src/ui/keypair_details/KeyPairSubkeyTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -232,6 +232,7 @@ void KeyPairSubkeyTab::createSubkeyOperaMenu() {
}

void KeyPairSubkeyTab::slotEditSubkey() {
qDebug() << "Slot Edit Subkry";
auto *subkey = getSelectedSubkey();
if(subkey == buffered_subkeys[0]) {
subkey = nullptr;
Expand All @@ -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());
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/ui/main_window/MainWindowSlotFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "MainWindow.h"

void MainWindow::slotEncrypt() {

if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) {
return;
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 0de1cf6

Please sign in to comment.