Compare commits
3 Commits
e8efa4d104
...
c1d0552cb3
Author | SHA1 | Date | |
---|---|---|---|
c1d0552cb3 | |||
8bb3bf646e | |||
0a61ccd17a |
@ -57,5 +57,6 @@ const QString kGnuPGInfoGatheringModuleID =
|
||||
"com.bktus.gpgfrontend.module.gnupg_info_gathering";
|
||||
const QString kVersionCheckingModuleID =
|
||||
"com.bktus.gpgfrontend.module.version_checking";
|
||||
const QString kPinentryModuleID = "com.bktus.gpgfrontend.module.pinentry";
|
||||
|
||||
} // namespace GpgFrontend
|
||||
|
@ -93,31 +93,24 @@ class GpgContext::Impl {
|
||||
static auto TestPassphraseCb(void *opaque, const char *uid_hint,
|
||||
const char *passphrase_info, int last_was_bad,
|
||||
int fd) -> gpgme_error_t {
|
||||
size_t res;
|
||||
#ifdef QT5_BUILD
|
||||
QString pass_qstr = "abcdefg\n";
|
||||
QByteArray pass = pass_qstr.toUtf8();
|
||||
#else
|
||||
QString pass = "abcdefg\n";
|
||||
#endif
|
||||
QString passphrase = "abcdefg";
|
||||
auto pass_bytes = passphrase.toLatin1();
|
||||
auto pass_size = pass_bytes.size();
|
||||
const auto *p_pass_bytes = pass_bytes.constData();
|
||||
|
||||
auto passphrase_size = pass.size();
|
||||
size_t off = 0;
|
||||
|
||||
do {
|
||||
#ifdef QT5_BUILD
|
||||
const char *p_pass = pass.data();
|
||||
res = gpgme_io_write(fd, &p_pass[off], passpahrase_size - off);
|
||||
#else
|
||||
res = gpgme_io_write(fd, &pass[off], passphrase_size - off);
|
||||
#endif
|
||||
if (res > 0) off += res;
|
||||
} while (res > 0 && static_cast<long long>(off) != passphrase_size);
|
||||
ssize_t res = 0;
|
||||
if (pass_size > 0) {
|
||||
ssize_t off = 0;
|
||||
ssize_t ret = 0;
|
||||
do {
|
||||
ret = gpgme_io_write(fd, &p_pass_bytes[off], pass_size - off);
|
||||
if (ret > 0) off += ret;
|
||||
} while (ret > 0 && off != pass_size);
|
||||
res = off;
|
||||
}
|
||||
|
||||
res += gpgme_io_write(fd, "\n", 1);
|
||||
return static_cast<long long>(res) == (passphrase_size + 1)
|
||||
? 0
|
||||
: gpgme_error_from_errno(GPG_ERR_CANCELED);
|
||||
return res == pass_size + 1 ? 0 : gpgme_error_from_errno(GPG_ERR_CANCELED);
|
||||
}
|
||||
|
||||
static auto CustomPassphraseCb(void *hook, const char *uid_hint,
|
||||
@ -145,12 +138,11 @@ class GpgContext::Impl {
|
||||
"REQUEST_PIN_ENTRY",
|
||||
{{"uid_hint", uid_hint != nullptr ? uid_hint : ""},
|
||||
{"passphrase_info", passphrase_info != nullptr ? passphrase_info : ""},
|
||||
{"prev_was_bad", prev_was_bad ? "1" : "0"},
|
||||
{"prev_was_bad", (prev_was_bad != 0) ? "1" : "0"},
|
||||
{"ask_for_new", ask_for_new ? "1" : "0"}},
|
||||
[&passphrase, &looper](Module::EventIdentifier i,
|
||||
Module::Event::ListenerIdentifier ei,
|
||||
Module::Event::Params p) {
|
||||
qCWarning(core) << "REQUEST_PIN_ENTRY callback: " << i << ei << p;
|
||||
passphrase = p["passphrase"];
|
||||
looper.quit();
|
||||
});
|
||||
@ -158,24 +150,23 @@ class GpgContext::Impl {
|
||||
looper.exec();
|
||||
ResetCacheValue("PinentryContext");
|
||||
|
||||
auto passphrase_size = passphrase.size();
|
||||
qCWarning(core, "get passphrase from pinentry size: %lld", passphrase_size);
|
||||
auto pass_bytes = passphrase.toLatin1();
|
||||
auto pass_size = pass_bytes.size();
|
||||
const auto *p_pass_bytes = pass_bytes.constData();
|
||||
|
||||
size_t res = 0;
|
||||
if (passphrase_size > 0) {
|
||||
size_t off = 0;
|
||||
ssize_t res = 0;
|
||||
if (pass_size > 0) {
|
||||
ssize_t off = 0;
|
||||
ssize_t ret = 0;
|
||||
do {
|
||||
res = gpgme_io_write(fd, &passphrase[off], passphrase_size - off);
|
||||
if (res > 0) off += res;
|
||||
} while (res > 0 && off != passphrase_size);
|
||||
ret = gpgme_io_write(fd, &p_pass_bytes[off], pass_size - off);
|
||||
if (ret > 0) off += ret;
|
||||
} while (ret > 0 && off != pass_size);
|
||||
res = off;
|
||||
}
|
||||
|
||||
res += gpgme_io_write(fd, "\n", 1);
|
||||
|
||||
qCDebug(core, "custom passphrase cd is about to return, res: %ld", res);
|
||||
return res == passphrase_size + 1
|
||||
? 0
|
||||
: gpgme_error_from_errno(GPG_ERR_CANCELED);
|
||||
return res == pass_size + 1 ? 0 : gpgme_error_from_errno(GPG_ERR_CANCELED);
|
||||
}
|
||||
|
||||
static auto TestStatusCb(void *hook, const char *keyword,
|
||||
@ -280,7 +271,8 @@ class GpgContext::Impl {
|
||||
qCWarning(core, "set passphrase cb failed, test");
|
||||
return false;
|
||||
};
|
||||
} else if (!args_.use_pinentry) {
|
||||
} else if (!args_.use_pinentry &&
|
||||
Module::IsModuleActivate(kPinentryModuleID)) {
|
||||
if (!SetPassphraseCb(ctx, CustomPassphraseCb)) {
|
||||
qCDebug(core, "set passphrase cb failed, custom");
|
||||
return false;
|
||||
|
@ -49,11 +49,11 @@ auto GpgKeyImportExporter::ImportKey(const GFBuffer& in_buffer)
|
||||
if (in_buffer.Empty()) return {};
|
||||
|
||||
GpgData data_in(in_buffer);
|
||||
auto err = CheckGpgError(gpgme_op_import(ctx_.DefaultContext(), data_in));
|
||||
auto err = CheckGpgError(gpgme_op_import(ctx_.BinaryContext(), data_in));
|
||||
if (gpgme_err_code(err) != GPG_ERR_NO_ERROR) return {};
|
||||
|
||||
gpgme_import_result_t result;
|
||||
result = gpgme_op_import_result(ctx_.DefaultContext());
|
||||
result = gpgme_op_import_result(ctx_.BinaryContext());
|
||||
gpgme_import_status_t status = result->imports;
|
||||
auto import_info = SecureCreateSharedObject<GpgImportInformation>(result);
|
||||
while (status != nullptr) {
|
||||
|
@ -264,7 +264,7 @@ void CommonUtils::RaiseFailureMessageBox(QWidget *parent, GpgError err) {
|
||||
.arg(desc.second));
|
||||
}
|
||||
|
||||
void CommonUtils::SlotImportKeys(QWidget *parent, const QString &in_buffer) {
|
||||
void CommonUtils::SlotImportKeys(QWidget *parent, const QByteArray &in_buffer) {
|
||||
auto info =
|
||||
GpgKeyImportExporter::GetInstance().ImportKey(GFBuffer(in_buffer));
|
||||
emit SignalKeyStatusUpdated();
|
||||
@ -310,7 +310,7 @@ void CommonUtils::SlotImportKeyFromKeyServer(QWidget *parent) {
|
||||
|
||||
void CommonUtils::SlotImportKeyFromClipboard(QWidget *parent) {
|
||||
QClipboard *cb = QApplication::clipboard();
|
||||
SlotImportKeys(parent, cb->text(QClipboard::Clipboard));
|
||||
SlotImportKeys(parent, cb->text(QClipboard::Clipboard).toLatin1());
|
||||
}
|
||||
|
||||
void CommonUtils::SlotExecuteCommand(
|
||||
|
@ -215,7 +215,7 @@ class CommonUtils : public QWidget {
|
||||
void SignalRestartApplication(int);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void SignalFavoritesChanged();
|
||||
@ -228,7 +228,7 @@ class CommonUtils : public QWidget {
|
||||
* @param parent
|
||||
* @param in_buffer
|
||||
*/
|
||||
void SlotImportKeys(QWidget* parent, const QString& in_buffer);
|
||||
void SlotImportKeys(QWidget* parent, const QByteArray& in_buffer);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
|
@ -52,7 +52,7 @@ void MainWindow::slot_start_wizard() {
|
||||
void MainWindow::slot_import_key_from_edit() {
|
||||
if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return;
|
||||
CommonUtils::GetInstance()->SlotImportKeys(
|
||||
this, edit_->CurTextPage()->GetTextPage()->toPlainText());
|
||||
this, edit_->CurTextPage()->GetTextPage()->toPlainText().toLatin1());
|
||||
}
|
||||
|
||||
void MainWindow::slot_open_key_management() {
|
||||
|
Loading…
Reference in New Issue
Block a user