Fixed
1. Fixed Known Issues.
This commit is contained in:
parent
1e3f1d13a6
commit
1a8626dfb3
@ -93,21 +93,43 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::SetExpire(
|
|||||||
*/
|
*/
|
||||||
void GpgFrontend::GpgKeyOpera::GenerateRevokeCert(
|
void GpgFrontend::GpgKeyOpera::GenerateRevokeCert(
|
||||||
const GpgKey& key, const std::string& output_file_name) {
|
const GpgKey& key, const std::string& output_file_name) {
|
||||||
auto args = std::vector<std::string>{"--command-fd", "0",
|
auto args = std::vector<std::string>{
|
||||||
"--status-fd", "1",
|
"--no-tty", "--command-fd", "0", "--status-fd", "1", "-o",
|
||||||
"-o", output_file_name.c_str(),
|
output_file_name, "--gen-revoke", key.fpr()};
|
||||||
"--gen-revoke", key.fpr().c_str()};
|
|
||||||
|
|
||||||
|
using boost::asio::async_write;
|
||||||
using boost::process::async_pipe;
|
using boost::process::async_pipe;
|
||||||
GpgCommandExecutor::GetInstance().Execute(
|
GpgCommandExecutor::GetInstance().Execute(
|
||||||
args, [](async_pipe& in, async_pipe& out) -> void {
|
args, [](async_pipe& in, async_pipe& out) -> void {
|
||||||
boost::asio::streambuf buff;
|
boost::asio::streambuf buff;
|
||||||
boost::asio::read_until(in, buff, '\n');
|
boost::asio::read_until(in, buff, '\n');
|
||||||
|
|
||||||
std::string line;
|
|
||||||
std::istream is(&buff);
|
std::istream is(&buff);
|
||||||
|
|
||||||
|
while (!is.eof()) {
|
||||||
|
std::string line;
|
||||||
is >> line;
|
is >> line;
|
||||||
// Code From Gpg4Win
|
LOG(INFO) << "line" << line;
|
||||||
|
boost::algorithm::trim(line);
|
||||||
|
if (line == std::string("[GNUPG:] GET_BOOL gen_revoke.okay")) {
|
||||||
|
|
||||||
|
} else if (line ==
|
||||||
|
std::string(
|
||||||
|
"[GNUPG:] GET_LINE ask_revocation_reason.code")) {
|
||||||
|
|
||||||
|
} else if (line ==
|
||||||
|
std::string(
|
||||||
|
"[GNUPG:] GET_LINE ask_revocation_reason.text")) {
|
||||||
|
|
||||||
|
} else if (line ==
|
||||||
|
std::string("[GNUPG:] GET_BOOL openfile.overwrite.okay")) {
|
||||||
|
|
||||||
|
} else if (line ==
|
||||||
|
std::string(
|
||||||
|
"[GNUPG:] GET_BOOL ask_revocation_reason.okay")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class GpgKeyOpera : public SingletonFunctionObject<GpgKeyOpera> {
|
|||||||
GpgError SetExpire(const GpgKey& key, const SubkeyId& subkey_fpr,
|
GpgError SetExpire(const GpgKey& key, const SubkeyId& subkey_fpr,
|
||||||
std::unique_ptr<boost::gregorian::date>& expires);
|
std::unique_ptr<boost::gregorian::date>& expires);
|
||||||
|
|
||||||
void GenerateRevokeCert(const GpgKey& key,
|
static void GenerateRevokeCert(const GpgKey& key,
|
||||||
const std::string& output_file_name);
|
const std::string& output_file_name);
|
||||||
|
|
||||||
GpgFrontend::GpgError GenerateKey(const std::unique_ptr<GenKeyInfo>& params);
|
GpgFrontend::GpgError GenerateKey(const std::unique_ptr<GenKeyInfo>& params);
|
||||||
|
@ -125,4 +125,47 @@ void CommonUtils::slotImportKeyFromClipboard(QWidget* parent) {
|
|||||||
cb->text(QClipboard::Clipboard).toUtf8().toStdString());
|
cb->text(QClipboard::Clipboard).toUtf8().toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommonUtils::slotExecuteGpgCommand(
|
||||||
|
const QStringList& arguments,
|
||||||
|
const std::function<void(QProcess*)>& interact_func) {
|
||||||
|
QEventLoop looper;
|
||||||
|
auto dialog = new WaitingDialog(_("Processing"), nullptr);
|
||||||
|
dialog->show();
|
||||||
|
auto* gpgProcess = new QProcess(&looper);
|
||||||
|
gpgProcess->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
|
||||||
|
connect(gpgProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished),
|
||||||
|
&looper, &QEventLoop::quit);
|
||||||
|
connect(gpgProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished),
|
||||||
|
dialog, &WaitingDialog::deleteLater);
|
||||||
|
connect(gpgProcess, &QProcess::errorOccurred, &looper, &QEventLoop::quit);
|
||||||
|
connect(gpgProcess, &QProcess::started,
|
||||||
|
[]() -> void { LOG(ERROR) << "Gpg Process Started Success"; });
|
||||||
|
connect(gpgProcess, &QProcess::readyReadStandardOutput,
|
||||||
|
[interact_func, gpgProcess]() { interact_func(gpgProcess); });
|
||||||
|
connect(gpgProcess, &QProcess::errorOccurred, this, [=]() -> void {
|
||||||
|
LOG(ERROR) << "Error in Process";
|
||||||
|
dialog->close();
|
||||||
|
QMessageBox::critical(nullptr, _("Failure"),
|
||||||
|
_("Failed to execute command."));
|
||||||
|
});
|
||||||
|
connect(gpgProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished),
|
||||||
|
this, [=](int, QProcess::ExitStatus status) {
|
||||||
|
dialog->close();
|
||||||
|
if (status == QProcess::NormalExit)
|
||||||
|
QMessageBox::information(nullptr, _("Success"),
|
||||||
|
_("Succeed in executing command."));
|
||||||
|
else
|
||||||
|
QMessageBox::information(nullptr, _("Warning"),
|
||||||
|
_("Finished executing command."));
|
||||||
|
});
|
||||||
|
|
||||||
|
gpgProcess->setProgram(GpgContext::GetInstance().GetInfo().AppPath.c_str());
|
||||||
|
gpgProcess->setArguments(arguments);
|
||||||
|
gpgProcess->start();
|
||||||
|
looper.exec();
|
||||||
|
dialog->close();
|
||||||
|
dialog->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace GpgFrontend::UI
|
} // namespace GpgFrontend::UI
|
@ -69,9 +69,12 @@ class CommonUtils : public QWidget {
|
|||||||
|
|
||||||
void slotImportKeyFromClipboard(QWidget* parent);
|
void slotImportKeyFromClipboard(QWidget* parent);
|
||||||
|
|
||||||
|
void slotExecuteGpgCommand(
|
||||||
|
const QStringList& arguments,
|
||||||
|
const std::function<void(QProcess*)>& interact_func);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::unique_ptr<CommonUtils> _instance;
|
static std::unique_ptr<CommonUtils> _instance;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend::UI
|
} // namespace GpgFrontend::UI
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "gpg/function/GpgKeyGetter.h"
|
#include "gpg/function/GpgKeyGetter.h"
|
||||||
#include "gpg/function/GpgKeyImportExportor.h"
|
#include "gpg/function/GpgKeyImportExportor.h"
|
||||||
#include "ui/SignalStation.h"
|
#include "ui/SignalStation.h"
|
||||||
|
#include "ui/UserInterfaceUtils.h"
|
||||||
#include "ui/WaitingDialog.h"
|
#include "ui/WaitingDialog.h"
|
||||||
|
|
||||||
namespace GpgFrontend::UI {
|
namespace GpgFrontend::UI {
|
||||||
@ -228,8 +229,9 @@ void KeyPairDetailTab::slotExportPrivateKey() {
|
|||||||
ByteArrayPtr keyArray = nullptr;
|
ByteArrayPtr keyArray = nullptr;
|
||||||
|
|
||||||
if (!GpgKeyImportExportor::GetInstance().ExportSecretKey(mKey, keyArray)) {
|
if (!GpgKeyImportExportor::GetInstance().ExportSecretKey(mKey, keyArray)) {
|
||||||
QMessageBox::critical(this, "Error",
|
QMessageBox::critical(
|
||||||
"An error occurred during the export operation.");
|
this, _("Error"),
|
||||||
|
_("An error occurred during the export operation."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,15 +358,47 @@ void KeyPairDetailTab::slotUpdateKeyToServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KeyPairDetailTab::slotGenRevokeCert() {
|
void KeyPairDetailTab::slotGenRevokeCert() {
|
||||||
auto mOutputFileName = QFileDialog::getSaveFileName(
|
auto literal = QStringLiteral("%1 (*.rev)").arg(_("Revocation Certificates"));
|
||||||
this, _("Generate revocation certificate"), QString(),
|
QString m_output_file_name;
|
||||||
QStringLiteral("%1 (*.rev)").arg(_("Revocation Certificates")));
|
|
||||||
|
|
||||||
// if (!mOutputFileName.isEmpty())
|
QFileDialog dialog(this, "Generate revocation certificate", QString(),
|
||||||
// mCtx->generateRevokeCert(mKey, mOutputFileName);
|
literal);
|
||||||
|
dialog.setDefaultSuffix(".rev");
|
||||||
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||||
|
|
||||||
|
if (dialog.exec()) m_output_file_name = dialog.selectedFiles().front();
|
||||||
|
|
||||||
|
if (!m_output_file_name.isEmpty())
|
||||||
|
CommonUtils::GetInstance()->slotExecuteGpgCommand(
|
||||||
|
{"--command-fd", "0", "--status-fd", "1", "--no-tty", "-o",
|
||||||
|
m_output_file_name, "--gen-revoke", mKey.fpr().c_str()},
|
||||||
|
[](QProcess* proc) -> void {
|
||||||
|
// Code From Gpg4Win
|
||||||
|
while (proc->canReadLine()) {
|
||||||
|
const QString line = QString::fromUtf8(proc->readLine()).trimmed();
|
||||||
|
LOG(INFO) << "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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
void KeyPairDetailTab::slotRefreshKey() {
|
void KeyPairDetailTab::slotRefreshKey() {
|
||||||
LOG(INFO) << "KeyPairDetailTab::slotRefreshKey Called";
|
LOG(INFO) << _("Called");
|
||||||
this->mKey = GpgKeyGetter::GetInstance().GetKey(mKey.id());
|
this->mKey = GpgKeyGetter::GetInstance().GetKey(mKey.id());
|
||||||
this->slotRefreshKeyInfo();
|
this->slotRefreshKeyInfo();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user