diff options
Diffstat (limited to 'src/ui/function')
-rw-r--r-- | src/ui/function/GenerateRevokeCertification.cpp | 89 | ||||
-rw-r--r-- | src/ui/function/GenerateRevokeCertification.h | 44 | ||||
-rw-r--r-- | src/ui/function/RaisePinentry.cpp | 122 | ||||
-rw-r--r-- | src/ui/function/RaisePinentry.h | 60 | ||||
-rw-r--r-- | src/ui/function/SetOwnerTrustLevel.cpp | 96 | ||||
-rw-r--r-- | src/ui/function/SetOwnerTrustLevel.h | 55 |
6 files changed, 466 insertions, 0 deletions
diff --git a/src/ui/function/GenerateRevokeCertification.cpp b/src/ui/function/GenerateRevokeCertification.cpp new file mode 100644 index 00000000..b4a6c934 --- /dev/null +++ b/src/ui/function/GenerateRevokeCertification.cpp @@ -0,0 +1,89 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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. + * + * GpgFrontend 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 GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "GenerateRevokeCertification.h" + +#include "core/function/gpg/GpgCommandExecutor.h" +#include "core/model/GpgKey.h" +#include "core/module/ModuleManager.h" + +namespace GpgFrontend::UI { + +GenerateRevokeCertification::GenerateRevokeCertification(QWidget* parent) + : QWidget(parent) {} + +auto GenerateRevokeCertification::Exec(const GpgKey& key, + const QString& output_path) -> int { + const auto app_path = Module::RetrieveRTValueTypedOrDefault<>( + "core", "gpgme.ctx.app_path", QString{}); + // get all components + GpgCommandExecutor::ExecuteSync( + {app_path, + QStringList{"--command-fd", "0", "--status-fd", "1", "--no-tty", "-o", + output_path, "--gen-revoke", key.GetFingerprint()}, + [=](int exit_code, const QString& p_out, const QString& p_err) { + if (exit_code != 0) { + GF_UI_LOG_ERROR( + "gnupg gen revoke execute error, process stderr: {}, process " + "stdout: {}", + p_err, p_out); + } else { + GF_UI_LOG_DEBUG( + "gnupg gen revoke exit_code: {}, process stdout size: {}", + exit_code, p_out.size()); + } + }, + nullptr, + [](QProcess* proc) -> void { + // Code From Gpg4Win + while (proc->canReadLine()) { + const QString line = QString::fromUtf8(proc->readLine()).trimmed(); + GF_UI_LOG_DEBUG("line: {}", line.toStdString()); + if (line == QLatin1String("[GNUPG:] GET_BOOL gen_revoke.okay")) { + proc->write("y\n"); + } else if (line == QLatin1String("[GNUPG:] GET_LINE " + "ask_revocation_reason.code")) { + proc->write("0\n"); + } else if (line == QLatin1String("[GNUPG:] GET_LINE " + "ask_revocation_reason.text")) { + proc->write("\n"); + } else if (line == + QLatin1String( + "[GNUPG:] GET_BOOL openfile.overwrite.okay")) { + // We asked before + proc->write("y\n"); + } else if (line == QLatin1String("[GNUPG:] GET_BOOL " + "ask_revocation_reason.okay")) { + proc->write("y\n"); + } + } + }}); + return 0; +} + +} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/function/GenerateRevokeCertification.h b/src/ui/function/GenerateRevokeCertification.h new file mode 100644 index 00000000..edc0161b --- /dev/null +++ b/src/ui/function/GenerateRevokeCertification.h @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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. + * + * GpgFrontend 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 GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "core/GpgModel.h" +#include "ui/GpgFrontendUI.h" + +namespace GpgFrontend::UI { + +class GenerateRevokeCertification : public QWidget { + Q_OBJECT + public: + explicit GenerateRevokeCertification(QWidget* parent); + + auto Exec(const GpgKey& key, const QString& output_path) -> int; +}; + +} // namespace GpgFrontend::UI diff --git a/src/ui/function/RaisePinentry.cpp b/src/ui/function/RaisePinentry.cpp new file mode 100644 index 00000000..64e10c48 --- /dev/null +++ b/src/ui/function/RaisePinentry.cpp @@ -0,0 +1,122 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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. + * + * GpgFrontend 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 GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "RaisePinentry.h" + +#include "core/function/CoreSignalStation.h" +#include "core/model/GpgPassphraseContext.h" +#include "core/utils/CacheUtils.h" +#include "pinentry/pinentrydialog.h" + +namespace GpgFrontend::UI { + +auto FindTopMostWindow(QWidget* fallback) -> QWidget* { + QList<QWidget*> top_widgets = QApplication::topLevelWidgets(); + foreach (QWidget* widget, top_widgets) { + if (widget->isActiveWindow()) { + GF_UI_LOG_TRACE("find a topmost widget, address: {}", + static_cast<void*>(widget)); + return widget; + } + } + return fallback; +} + +RaisePinentry::RaisePinentry(QWidget* parent, + QSharedPointer<GpgPassphraseContext> context) + : QWidget(parent), context_(std::move(context)) {} + +auto RaisePinentry::Exec() -> int { + GF_UI_LOG_DEBUG( + "setting pinetry's arguments, context uids: {}, passphrase info: {}, " + "prev_was_bad: {}", + context_->GetUidsInfo().toStdString(), + context_->GetPassphraseInfo().toStdString(), context_->IsPreWasBad()); + + bool ask_for_new = context_->IsAskForNew() && + context_->GetPassphraseInfo().isEmpty() && + context_->GetUidsInfo().isEmpty(); + + auto* pinentry = + new PinEntryDialog(FindTopMostWindow(this), 0, 15, true, ask_for_new, + ask_for_new ? tr("Repeat PIN:") : QString(), + tr("Show passphrase"), tr("Hide passphrase")); + + if (context_->IsPreWasBad()) { + pinentry->setError(tr("Given PIN was wrong. Please retry.")); + } + + pinentry->setPrompt(tr("PIN:")); + + if (!context_->GetUidsInfo().isEmpty()) { + pinentry->setDescription(QString("Please provide PIN of Key:\n%1\n") + .arg(context_->GetUidsInfo())); + } + + struct pinentry pinentry_info; + pinentry->setPinentryInfo(pinentry_info); + + pinentry->setRepeatErrorText(tr("Passphrases do not match")); + pinentry->setGenpinLabel(QString("")); + pinentry->setGenpinTT(QString("")); + pinentry->setCapsLockHint(tr("Caps Lock is on")); + pinentry->setFormattedPassphrase({false, QString()}); + pinentry->setConstraintsOptions({false, QString(), QString(), QString()}); + + pinentry->setWindowTitle(tr("Buddled Pinentry")); + + /* If we reuse the same dialog window. */ + pinentry->setPin(QString()); + pinentry->setOkText(tr("Confirm")); + pinentry->setCancelText(tr("Cancel")); + + GF_UI_LOG_DEBUG("buddled pinentry is ready to start..."); + connect(pinentry, &PinEntryDialog::finished, this, + [pinentry, this](int result) { + bool ret = result != 0; + GF_UI_LOG_DEBUG("buddled pinentry finished, ret: {}", ret); + + if (!ret) { + emit CoreSignalStation::GetInstance() + ->SignalUserInputPassphraseCallback({}); + return -1; + } + + auto pin = pinentry->pin().toUtf8(); + + context_->SetPassphrase(pin); + emit CoreSignalStation::GetInstance() + ->SignalUserInputPassphraseCallback(context_); + return 0; + }); + connect(pinentry, &PinEntryDialog::finished, this, &QWidget::deleteLater); + + pinentry->open(); + return 0; +} +} // namespace GpgFrontend::UI diff --git a/src/ui/function/RaisePinentry.h b/src/ui/function/RaisePinentry.h new file mode 100644 index 00000000..40175dfd --- /dev/null +++ b/src/ui/function/RaisePinentry.h @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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. + * + * GpgFrontend 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 GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "ui/GpgFrontendUI.h" + +namespace GpgFrontend { +class GpgPassphraseContext; +} + +namespace GpgFrontend::UI { + +class RaisePinentry : public QWidget { + Q_OBJECT + public: + /** + * @brief Construct a new Raise Pinentry object + * + * @param parent + */ + explicit RaisePinentry(QWidget *parent, QSharedPointer<GpgPassphraseContext>); + + /** + * @brief + * + * @return int + */ + auto Exec() -> int; + + private: + QSharedPointer<GpgPassphraseContext> context_; +}; + +} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/function/SetOwnerTrustLevel.cpp b/src/ui/function/SetOwnerTrustLevel.cpp new file mode 100644 index 00000000..360abfce --- /dev/null +++ b/src/ui/function/SetOwnerTrustLevel.cpp @@ -0,0 +1,96 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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. + * + * GpgFrontend 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 GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "SetOwnerTrustLevel.h" + +#include "core/GpgModel.h" +#include "core/function/gpg/GpgKeyGetter.h" +#include "core/function/gpg/GpgKeyManager.h" +#include "ui/UISignalStation.h" + +namespace GpgFrontend::UI { + +SetOwnerTrustLevel::SetOwnerTrustLevel(QWidget* parent) : QWidget(parent) {} + +auto SetOwnerTrustLevel::Exec(const QString& key_id) -> bool { + if (key_id.isEmpty()) { + return false; + } + + auto key = GpgKeyGetter::GetInstance().GetKey(key_id); + + QStringList items; + + items << tr("Unknown") << tr("Undefined") << tr("Never") << tr("Marginal") + << tr("Full") << tr("Ultimate"); + bool ok; + QString item = QInputDialog::getItem(this, tr("Modify Owner Trust Level"), + tr("Trust for the Key Pair:"), items, + key.GetOwnerTrustLevel(), false, &ok); + + if (ok && !item.isEmpty()) { + GF_UI_LOG_DEBUG("selected owner trust policy: {}", item.toStdString()); + int trust_level = 0; // Unknown Level + if (item == tr("Ultimate")) { + trust_level = 5; + } else if (item == tr("Full")) { + trust_level = 4; + } else if (item == tr("Marginal")) { + trust_level = 3; + } else if (item == tr("Never")) { + trust_level = 2; + } else if (item == tr("Undefined")) { + trust_level = 1; + } + + if (trust_level == 0) { + QMessageBox::warning( + this, tr("Warning"), + QString( + tr("Owner Trust Level cannot set to Unknown level, automately " + "changing it into Undefined level."))); + trust_level = 1; + } + + bool status = + GpgKeyManager::GetInstance().SetOwnerTrustLevel(key, trust_level); + if (!status) { + QMessageBox::critical(this, tr("Failed"), + tr("Modify Owner Trust Level failed.")); + return false; + } + + // update key database and refresh ui + emit UISignalStation::GetInstance()->SignalKeyDatabaseRefresh(); + return true; + } + + return false; +} + +} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/function/SetOwnerTrustLevel.h b/src/ui/function/SetOwnerTrustLevel.h new file mode 100644 index 00000000..e33f787b --- /dev/null +++ b/src/ui/function/SetOwnerTrustLevel.h @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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. + * + * GpgFrontend 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 GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "GpgFrontendUI.h" + +namespace GpgFrontend::UI { + +class SetOwnerTrustLevel : public QWidget { + Q_OBJECT + public: + /** + * @brief Set the Owner Trust Level object + * + * @param parent + */ + explicit SetOwnerTrustLevel(QWidget* parent); + + /** + * @brief + * + * @param key_id + * @return true + * @return false + */ + auto Exec(const QString& key_id) -> bool; +}; + +} // namespace GpgFrontend::UI
\ No newline at end of file |