diff options
author | saturneric <[email protected]> | 2024-01-17 16:14:13 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-17 16:14:13 +0000 |
commit | 37848811b6c8ca6c2a707431ec077c8098918afe (patch) | |
tree | 2ed4e5759ca6c432171963068beca61a164e98d2 /src | |
parent | feat: update ci files and reduce dependencies (diff) | |
download | GpgFrontend-37848811b6c8ca6c2a707431ec077c8098918afe.tar.gz GpgFrontend-37848811b6c8ca6c2a707431ec077c8098918afe.zip |
fix: improve code quality, docs and ci files
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/GpgFrontendContext.h | 1 | ||||
-rw-r--r-- | src/core/function/ArchiveFileOperator.cpp | 2 | ||||
-rw-r--r-- | src/core/function/DataObjectOperator.cpp | 2 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyManager.cpp | 7 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyOpera.cpp | 2 | ||||
-rw-r--r-- | src/core/model/GFBuffer.cpp | 12 | ||||
-rw-r--r-- | src/core/model/GFBuffer.h | 2 | ||||
-rw-r--r-- | src/core/model/GFDataExchanger.cpp | 2 | ||||
-rw-r--r-- | src/core/module/Module.cpp | 3 | ||||
-rw-r--r-- | src/core/thread/FileReadTask.cpp | 3 | ||||
-rw-r--r-- | src/init.cpp | 17 | ||||
-rw-r--r-- | src/pinentry/focusframe.cpp | 72 | ||||
-rw-r--r-- | src/pinentry/focusframe.h | 36 | ||||
-rw-r--r-- | src/pinentry/keyboardfocusindication.cpp | 43 | ||||
-rw-r--r-- | src/pinentry/keyboardfocusindication.h | 42 | ||||
-rw-r--r-- | src/pinentry/pinentry.cpp | 159 | ||||
-rw-r--r-- | src/pinentry/pinentry.h | 12 | ||||
-rw-r--r-- | src/pinentry/pinentrydialog.cpp | 44 | ||||
-rw-r--r-- | src/pinentry/pinentrydialog.h | 1 | ||||
-rw-r--r-- | src/pinentry/util.cpp | 42 | ||||
-rw-r--r-- | src/test/core/GpgCoreTestBasicOpera.cpp | 29 | ||||
-rw-r--r-- | src/test/core/GpgCoreTestFileBasicOpera.cpp | 6 |
23 files changed, 43 insertions, 501 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 96334dd1..71734127 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,9 +30,6 @@ endif() # Introduce GpgME find_package(Gpgme REQUIRED) -# Introduce Config++ -find_package(Config++ REQUIRED) - # Introduce OpenSSL if (APPLE) # Define possible OpenSSL directories @@ -421,7 +418,7 @@ if (BUILD_APPLICATION) # Make app build with resources add_dependencies(${AppName} resources) - + # using c++ standard 17 target_compile_features(${AppName} PUBLIC cxx_std_17) diff --git a/src/GpgFrontendContext.h b/src/GpgFrontendContext.h index e0d176f1..00bbcfbe 100644 --- a/src/GpgFrontendContext.h +++ b/src/GpgFrontendContext.h @@ -40,7 +40,6 @@ struct GpgFrontendContext { char** argv; spdlog::level::level_enum log_level; - bool load_ui_env; bool gather_external_gnupg_info; bool load_default_gpg_context; diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp index a4b90698..54c78628 100644 --- a/src/core/function/ArchiveFileOperator.cpp +++ b/src/core/function/ArchiveFileOperator.cpp @@ -158,9 +158,11 @@ void ArchiveFileOperator::NewArchive2DataExchanger( if (r > ARCHIVE_FAILED) { auto fd = open(archive_entry_sourcepath(entry), O_RDONLY); auto len = read(fd, buff.data(), buff.size()); + assert(len <= buff.size() && len > 0); while (len > 0) { archive_write_data(archive, buff.data(), len); len = read(fd, buff.data(), buff.size()); + assert(len <= buff.size() && len > 0); } close(fd); } diff --git a/src/core/function/DataObjectOperator.cpp b/src/core/function/DataObjectOperator.cpp index e1d8b4da..cbf21f8e 100644 --- a/src/core/function/DataObjectOperator.cpp +++ b/src/core/function/DataObjectOperator.cpp @@ -65,7 +65,7 @@ DataObjectOperator::DataObjectOperator(int channel) auto DataObjectOperator::SaveDataObj(const QString& key, const QJsonDocument& value) -> QString { - QByteArray hash_obj_key = {}; + QByteArray hash_obj_key; if (key.isEmpty()) { hash_obj_key = QCryptographicHash::hash( diff --git a/src/core/function/gpg/GpgKeyManager.cpp b/src/core/function/gpg/GpgKeyManager.cpp index 8d7d9a28..b5efe141 100644 --- a/src/core/function/gpg/GpgKeyManager.cpp +++ b/src/core/function/gpg/GpgKeyManager.cpp @@ -176,9 +176,10 @@ auto GpgFrontend::GpgKeyManager::SetOwnerTrustLevel(const GpgKey& key, GpgData data_out; - auto err = gpgme_op_interact( - ctx_.DefaultContext(), static_cast<gpgme_key_t>(key), 0, - GpgKeyManager::interactor_cb_fnc, (void*)&handel_struct, data_out); + auto err = + gpgme_op_interact(ctx_.DefaultContext(), static_cast<gpgme_key_t>(key), 0, + GpgKeyManager::interactor_cb_fnc, + static_cast<void*>(&handel_struct), data_out); return CheckGpgError(err) == GPG_ERR_NO_ERROR && handel_struct.Success(); } diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index d9133905..9a722c0b 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -247,7 +247,7 @@ void GpgKeyOpera::GenerateKeyWithSubkey( subkey_params](const DataObjectPtr& data_object) -> GpgError { auto userid = params->GetUserid().toUtf8(); auto algo = (params->GetAlgo() + params->GetKeySizeStr()).toUtf8(); - unsigned long expires = expires = + unsigned long expires = QDateTime::currentDateTime().secsTo(params->GetExpireTime()); GpgError err; diff --git a/src/core/model/GFBuffer.cpp b/src/core/model/GFBuffer.cpp index c65ae689..56015613 100644 --- a/src/core/model/GFBuffer.cpp +++ b/src/core/model/GFBuffer.cpp @@ -33,18 +33,6 @@ namespace GpgFrontend { GFBuffer::GFBuffer() : buffer_(SecureCreateSharedObject<std::vector<std::byte>>()) {} -GFBuffer::GFBuffer(const char* c_str) - : buffer_(SecureCreateSharedObject<std::vector<std::byte>>()) { - if (c_str == nullptr) { - return; - } - - size_t const length = std::strlen(c_str); - buffer_->reserve(length); - buffer_->assign(reinterpret_cast<const std::byte*>(c_str), - reinterpret_cast<const std::byte*>(c_str) + length); -} - GFBuffer::GFBuffer(QByteArray buffer) : buffer_(SecureCreateSharedObject<std::vector<std::byte>>()) { std::transform(buffer.begin(), buffer.end(), std::back_inserter(*buffer_), diff --git a/src/core/model/GFBuffer.h b/src/core/model/GFBuffer.h index d947401e..381bcdf7 100644 --- a/src/core/model/GFBuffer.h +++ b/src/core/model/GFBuffer.h @@ -37,8 +37,6 @@ class GPGFRONTEND_CORE_EXPORT GFBuffer { public: GFBuffer(); - explicit GFBuffer(const char* c_str); - explicit GFBuffer(QByteArray buffer); explicit GFBuffer(QString str); diff --git a/src/core/model/GFDataExchanger.cpp b/src/core/model/GFDataExchanger.cpp index 70a6498e..abf79c6b 100644 --- a/src/core/model/GFDataExchanger.cpp +++ b/src/core/model/GFDataExchanger.cpp @@ -59,7 +59,7 @@ auto GFDataExchanger::Write(const std::byte* buffer, size_t size) -> ssize_t { auto GFDataExchanger::Read(std::byte* buffer, size_t size) -> ssize_t { std::unique_lock<std::mutex> lock(mutex_); - if (size <= 0 || (close_ && queue_.empty())) return 0; + if (size == 0 || (close_ && queue_.empty())) return 0; std::atomic<ssize_t> read_bytes = 0; for (size_t i = 0; i < size; ++i) { diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index cab72a9a..c37b2262 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -40,7 +40,8 @@ class Module::Impl { Impl(ModuleRawPtr m_ptr, ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) - : m_ptr_(m_ptr), + : gpc_(nullptr), + m_ptr_(m_ptr), identifier_(std::move(id)), version_(std::move(version)), meta_data_(std::move(meta_data)) {} diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index c757d4c0..49a3f540 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -61,7 +61,8 @@ auto FileReadTask::Run() -> int { void FileReadTask::slot_read_bytes() { QByteArray read_buffer; - if (!target_file_.atEnd() && + if (QByteArray read_buffer; + !target_file_.atEnd() && (read_buffer = target_file_.read(kBufferSize)).size() > 0) { GF_CORE_LOG_DEBUG("io thread read bytes: {}", read_buffer.size()); emit SignalFileBytesRead(std::move(read_buffer)); diff --git a/src/init.cpp b/src/init.cpp index 4f9cf821..f9a1dabd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -55,17 +55,10 @@ int setenv(const char *name, const char *value, int overwrite) { void InitLoggingSystem(const GFCxtSPtr &ctx) { RegisterSyncLogger("core", ctx->log_level); - RegisterSyncLogger("main", ctx->log_level); - RegisterSyncLogger("module", ctx->log_level); - - if (ctx->load_ui_env) { - // init the logging system for ui - RegisterSyncLogger("ui", ctx->log_level); - } else { - RegisterSyncLogger("test", ctx->log_level); - } + RegisterSyncLogger("ui", ctx->log_level); + RegisterSyncLogger("test", ctx->log_level); } void InitGlobalPathEnv() { @@ -116,10 +109,8 @@ void InitGlobalBasicalEnv(const GFCxtWPtr &p_ctx, bool gui_mode) { module_init_args.log_level = ctx->log_level; Module::LoadGpgFrontendModules(module_init_args); - if (ctx->load_ui_env) { - // then preload ui - UI::PreInitGpgFrontendUI(); - } + // then preload ui + UI::PreInitGpgFrontendUI(); CoreInitArgs core_init_args; core_init_args.gather_external_gnupg_info = ctx->gather_external_gnupg_info; diff --git a/src/pinentry/focusframe.cpp b/src/pinentry/focusframe.cpp deleted file mode 100644 index c0c9f562..00000000 --- a/src/pinentry/focusframe.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* focusframe.cpp - A focus indicator for labels. - * Copyright (C) 2022 g10 Code GmbH - * - * Software engineering by Ingo Klöcker <[email protected]> - * - * This program 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 2 of the - * License, or (at your option) any later version. - * - * This program 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 this program; if not, see <https://www.gnu.org/licenses/>. - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include "focusframe.h" - -#if QT_CONFIG(graphicseffect) -#include <QGraphicsEffect> -#endif -#include <QStyleOptionFocusRect> -#include <QStylePainter> - -static QRect effectiveWidgetRect(const QWidget *w) { - // based on QWidgetPrivate::effectiveRectFor -#if QT_CONFIG(graphicseffect) - const auto *const graphicsEffect = w->graphicsEffect(); - if (graphicsEffect && graphicsEffect->isEnabled()) - return graphicsEffect->boundingRectFor(w->rect()).toAlignedRect(); -#endif // QT_CONFIG(graphicseffect) - return w->rect(); -} - -static QRect clipRect(const QWidget *w) { - // based on QWidgetPrivate::clipRect - if (!w->isVisible()) { - return QRect(); - } - QRect r = effectiveWidgetRect(w); - int ox = 0; - int oy = 0; - while (w && w->isVisible() && !w->isWindow() && w->parentWidget()) { - ox -= w->x(); - oy -= w->y(); - w = w->parentWidget(); - r &= QRect(ox, oy, w->width(), w->height()); - } - return r; -} - -void FocusFrame::paintEvent(QPaintEvent *) { - if (!widget()) { - return; - } - - QStylePainter p{this}; - QStyleOptionFocusRect option; - initStyleOption(&option); - const int vmargin = - style()->pixelMetric(QStyle::PM_FocusFrameVMargin, &option); - const int hmargin = - style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &option); - const QRect rect = - clipRect(widget()).adjusted(0, 0, hmargin * 2, vmargin * 2); - p.setClipRect(rect); - p.drawPrimitive(QStyle::PE_FrameFocusRect, option); -} diff --git a/src/pinentry/focusframe.h b/src/pinentry/focusframe.h deleted file mode 100644 index 3d2231ea..00000000 --- a/src/pinentry/focusframe.h +++ /dev/null @@ -1,36 +0,0 @@ -/* focusframe.h - A focus indicator for labels. - * Copyright (C) 2022 g10 Code GmbH - * - * Software engineering by Ingo Klöcker <[email protected]> - * - * This program 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 2 of the - * License, or (at your option) any later version. - * - * This program 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 this program; if not, see <https://www.gnu.org/licenses/>. - * SPDX-License-Identifier: GPL-2.0+ - */ - -#ifndef __FOCUSFRAME_H__ -#define __FOCUSFRAME_H__ - -#include <QFocusFrame> - -class FocusFrame : public QFocusFrame -{ - Q_OBJECT -public: - using QFocusFrame::QFocusFrame; - -protected: - void paintEvent(QPaintEvent *event) override; -}; - -#endif // __FOCUSFRAME_H__ diff --git a/src/pinentry/keyboardfocusindication.cpp b/src/pinentry/keyboardfocusindication.cpp deleted file mode 100644 index d783d981..00000000 --- a/src/pinentry/keyboardfocusindication.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* keyboardfocusindication.cpp - Helper for extended keyboard focus indication. - * Copyright (C) 2022 g10 Code GmbH - * - * Software engineering by Ingo Klöcker <[email protected]> - * - * This program 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 2 of the - * License, or (at your option) any later version. - * - * This program 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 this program; if not, see <https://www.gnu.org/licenses/>. - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include "keyboardfocusindication.h" - -#include "focusframe.h" - -#include <QApplication> - -KeyboardFocusIndication::KeyboardFocusIndication(QObject *parent) - : QObject{parent} -{ - connect(qApp, &QApplication::focusChanged, this, &KeyboardFocusIndication::updateFocusFrame); -} - -void KeyboardFocusIndication::updateFocusFrame(QWidget *, QWidget *focusWidget) -{ - if (focusWidget && focusWidget->inherits("QLabel") && focusWidget->window()->testAttribute(Qt::WA_KeyboardFocusChange)) { - if (!focusFrame) { - focusFrame = new FocusFrame{focusWidget}; - } - focusFrame->setWidget(focusWidget); - } else if (focusFrame) { - focusFrame->setWidget(nullptr); - } -} diff --git a/src/pinentry/keyboardfocusindication.h b/src/pinentry/keyboardfocusindication.h deleted file mode 100644 index e86a317e..00000000 --- a/src/pinentry/keyboardfocusindication.h +++ /dev/null @@ -1,42 +0,0 @@ -/* keyboardfocusindication.h - Helper for extended keyboard focus indication. - * Copyright (C) 2022 g10 Code GmbH - * - * Software engineering by Ingo Klöcker <[email protected]> - * - * This program 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 2 of the - * License, or (at your option) any later version. - * - * This program 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 this program; if not, see <https://www.gnu.org/licenses/>. - * SPDX-License-Identifier: GPL-2.0+ - */ - -#ifndef __KEYBOARDFOCUSINDICATION_H__ -#define __KEYBOARDFOCUSINDICATION_H__ - -#include <QObject> -#include <QPointer> -#include <QWidget> - -class FocusFrame; - -class KeyboardFocusIndication : public QObject -{ - Q_OBJECT -public: - KeyboardFocusIndication(QObject *parent); - -private: - void updateFocusFrame(QWidget *, QWidget *); - - QPointer<FocusFrame> focusFrame; -}; - -#endif // __KEYBOARDFOCUSINDICATION_H__ diff --git a/src/pinentry/pinentry.cpp b/src/pinentry/pinentry.cpp index 4a5f1408..6168a203 100644 --- a/src/pinentry/pinentry.cpp +++ b/src/pinentry/pinentry.cpp @@ -442,61 +442,6 @@ int pinentry_inq_quality(const QString &passphrase) { return std::max(-100, std::min(100, score)); } -/* Run a checkpin inquiry */ -char *pinentry_inq_checkpin(pinentry_t pin, const char *passphrase, - size_t length) { - assuan_context_t ctx = (assuan_context_t)pin->ctx_assuan; - const char prefix[] = "INQUIRE CHECKPIN "; - char *command; - char *line; - size_t linelen; - int gotvalue = 0; - char *value = NULL; - int rc; - - if (!ctx) return 0; /* Can't run the callback. */ - - if (length > 300) - length = 300; /* Limit so that it definitely fits into an Assuan - line. */ - - command = - GpgFrontend::SecureMallocAsType<char>(strlen(prefix) + 3 * length + 1); - if (!command) return 0; - strcpy(command, prefix); - copy_and_escape(command + strlen(command), passphrase, length); - rc = assuan_write_line(ctx, command); - GpgFrontend::SecureFree(command); - if (rc) { - fprintf(stderr, "ASSUAN WRITE LINE failed: rc=%d\n", rc); - return 0; - } - - for (;;) { - do { - rc = assuan_read_line(ctx, &line, &linelen); - if (rc) { - fprintf(stderr, "ASSUAN READ LINE failed: rc=%d\n", rc); - return 0; - } - } while (*line == '#' || !linelen); - if (line[0] == 'E' && line[1] == 'N' && line[2] == 'D' && - (!line[3] || line[3] == ' ')) - break; /* END command received*/ - if (line[0] == 'C' && line[1] == 'A' && line[2] == 'N' && - (!line[3] || line[3] == ' ')) - break; /* CAN command received*/ - if (line[0] == 'E' && line[1] == 'R' && line[2] == 'R' && - (!line[3] || line[3] == ' ')) - break; /* ERR command received*/ - if (line[0] != 'D' || line[1] != ' ' || linelen < 3 || gotvalue) continue; - gotvalue = 1; - value = strdup(line + 2); - } - - return value; -} - /* Run a genpin inquiry */ char *pinentry_inq_genpin(pinentry_t pin) { assuan_context_t ctx = (assuan_context_t)pin->ctx_assuan; @@ -581,23 +526,6 @@ static void pinentry_setbuffer_clear(pinentry_t pin) { pin->pin_len = 0; } -/* passphrase better be alloced with secmem_alloc. */ -void pinentry_setbuffer_use(pinentry_t pin, char *passphrase, int len) { - if (!passphrase) { - assert(len == 0); - pinentry_setbuffer_clear(pin); - - return; - } - - if (passphrase && len == 0) len = strlen(passphrase) + 1; - - if (pin->pin) GpgFrontend::SecureFree(pin->pin); - - pin->pin = passphrase; - pin->pin_len = len; -} - static struct assuan_malloc_hooks assuan_malloc_hooks = { GpgFrontend::SecureMalloc, GpgFrontend::SecureRealloc, GpgFrontend::SecureFree}; @@ -659,93 +587,6 @@ int pinentry_have_display(int argc, char **argv) { return found; } -/* Print usage information and and provide strings for help. */ -static const char *my_strusage(int level) { - const char *p; - - switch (level) { - case 11: - p = this_pgmname; - break; - case 12: - p = "pinentry"; - break; - case 13: - p = 0; - break; - case 14: - p = "Copyright (C) 2023 Saturneric"; - break; - case 19: - p = "Please report bugs to <[email protected]>.\n"; - break; - case 1: - case 40: { - static char *str; - - if (!str) { - size_t n = 50 + strlen(this_pgmname); - str = static_cast<char *>(malloc(n)); - if (str) { - snprintf(str, n, "Usage: %s [options] (-h for help)", this_pgmname); - } - } - p = str; - } break; - case 41: - p = "Ask securely for a secret and print it to stdout."; - break; - - case 42: - p = "1"; /* Flag print 40 as part of 41. */ - break; - - default: - p = NULL; - break; - } - return p; -} - -char *parse_color(char *arg, pinentry_color_t *color_p, int *bright_p) { - static struct { - const char *name; - pinentry_color_t color; - } colors[] = { - {"none", PINENTRY_COLOR_NONE}, {"default", PINENTRY_COLOR_DEFAULT}, - {"black", PINENTRY_COLOR_BLACK}, {"red", PINENTRY_COLOR_RED}, - {"green", PINENTRY_COLOR_GREEN}, {"yellow", PINENTRY_COLOR_YELLOW}, - {"blue", PINENTRY_COLOR_BLUE}, {"magenta", PINENTRY_COLOR_MAGENTA}, - {"cyan", PINENTRY_COLOR_CYAN}, {"white", PINENTRY_COLOR_WHITE}}; - - int i; - char *new_arg; - pinentry_color_t color = PINENTRY_COLOR_DEFAULT; - - if (!arg) return NULL; - - new_arg = strchr(arg, ','); - if (new_arg) new_arg++; - - if (bright_p) { - const char *bname[] = {"bright-", "bright", "bold-", "bold"}; - - *bright_p = 0; - for (i = 0; i < sizeof(bname) / sizeof(bname[0]); i++) - if (!strncasecmp(arg, bname[i], strlen(bname[i]))) { - *bright_p = 1; - arg += strlen(bname[i]); - } - } - - for (i = 0; i < sizeof(colors) / sizeof(colors[0]); i++) - if (!strncasecmp(arg, colors[i].name, strlen(colors[i].name))) - color = colors[i].color; - - *color_p = color; - return new_arg; -} - /* Set the optional flag used with getinfo. */ void pinentry_set_flavor_flag(const char *string) { flavor_flag = string; } diff --git a/src/pinentry/pinentry.h b/src/pinentry/pinentry.h index 80452e93..3a01a69e 100644 --- a/src/pinentry/pinentry.h +++ b/src/pinentry/pinentry.h @@ -305,12 +305,6 @@ char *pinentry_get_title(pinentry_t pe); /* Run a quality inquiry for PASSPHRASE of LENGTH. */ int pinentry_inq_quality(const QString &passphrase); -/* Run a checkpin inquiry for PASSPHRASE of LENGTH. Returns NULL, if the - passphrase satisfies the constraints. Otherwise, returns a malloced error - string. */ -char *pinentry_inq_checkpin(pinentry_t pin, const char *passphrase, - std::size_t length); - /* Run a genpin iquriry. Returns a malloced string or NULL */ char *pinentry_inq_genpin(pinentry_t pin); @@ -318,12 +312,6 @@ char *pinentry_inq_genpin(pinentry_t pin); PIN. Returns new buffer on success and 0 on failure. */ char *pinentry_setbufferlen(pinentry_t pin, int len); -/* Use the buffer at BUFFER for PIN->PIN. BUFFER must be NULL or - allocated using secmem_alloc. LEN is the size of the buffer. If - it is unknown, but BUFFER is a NUL terminated string, you pass 0 to - just use strlen(buffer)+1. */ -void pinentry_setbuffer_use(pinentry_t pin, char *buffer, int len); - /* Initialize the secure memory subsystem, drop privileges and return. Must be called early. */ void pinentry_init(const char *pgmname); diff --git a/src/pinentry/pinentrydialog.cpp b/src/pinentry/pinentrydialog.cpp index a8d85455..c823c1f3 100644 --- a/src/pinentry/pinentrydialog.cpp +++ b/src/pinentry/pinentrydialog.cpp @@ -645,47 +645,5 @@ void PinEntryDialog::onAccept() { return; } - const auto result = checkConstraints(); - if (result != PassphraseNotOk) { - accept(); - } -} - -PinEntryDialog::PassphraseCheckResult PinEntryDialog::checkConstraints() { - if (!mEnforceConstraints) { - return PassphraseNotChecked; - } - - const auto passphrase = _edit->pin().toUtf8(); - unique_malloced_ptr<char> error{pinentry_inq_checkpin( - _pinentry_info.get(), passphrase.constData(), passphrase.size())}; - - if (!error) { - return PassphraseOk; - } - - const auto message_lines = - QString::fromUtf8(QByteArray::fromPercentEncoding(error.get())) - .split(QChar{'\n'}); - if (message_lines.isEmpty()) { - // shouldn't happen because pinentry_inq_checkpin() either returns NULL or a - // non-empty string - return PassphraseOk; - } - const auto &first_line = message_lines.first(); - const auto index_of_first_non_empty_additional_line = - message_lines.indexOf(QRegularExpression{QStringLiteral(".*\\S.*")}, 1); - const auto additional_lines = - index_of_first_non_empty_additional_line > 0 - ? message_lines.mid(index_of_first_non_empty_additional_line) - .join(QChar{'\n'}) - : QString{}; - QMessageBox message_box{this}; - message_box.setIcon(QMessageBox::Information); - message_box.setWindowTitle(mConstraintsErrorTitle); - message_box.setText(first_line); - message_box.setInformativeText(additional_lines); - message_box.setStandardButtons(QMessageBox::Ok); - message_box.exec(); - return PassphraseNotOk; + accept(); } diff --git a/src/pinentry/pinentrydialog.h b/src/pinentry/pinentrydialog.h index 9f405b10..9cc677e5 100644 --- a/src/pinentry/pinentrydialog.h +++ b/src/pinentry/pinentrydialog.h @@ -134,7 +134,6 @@ class PinEntryDialog : public QDialog { PassphraseNotOk = 0, PassphraseOk }; - PassphraseCheckResult checkConstraints(); QLabel *_icon = nullptr; QLabel *_desc = nullptr; diff --git a/src/pinentry/util.cpp b/src/pinentry/util.cpp index f1bac4ba..5b4a4e80 100644 --- a/src/pinentry/util.cpp +++ b/src/pinentry/util.cpp @@ -24,13 +24,13 @@ #include <unistd.h> #ifndef WINDOWS -# include <errno.h> +#include <errno.h> #endif +#include <assert.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <assert.h> #include "util.h" @@ -39,32 +39,6 @@ static int uid_set = 0; static uid_t real_uid, file_uid; #endif /*!HAVE_DOSISH_SYSTEM*/ -/* Write DATA of size BYTES to FD, until all is written or an error - occurs. */ -ssize_t -xwrite(int fd, const void *data, size_t bytes) -{ - char *ptr; - size_t todo; - ssize_t written = 0; - - for (ptr = (char *)data, todo = bytes; todo; ptr += written, todo -= written) - { - do - written = write (fd, ptr, todo); - while ( -#ifdef WINDOWS - 0 -#else - written == -1 && errno == EINTR -#endif - ); - if (written < 0) - break; - } - return written; -} - #if 0 extern int debug; @@ -88,23 +62,17 @@ debugmsg(const char *fmt, ...) /* initialize uid variables */ #ifndef HAVE_DOSISH_SYSTEM -static void -init_uids(void) -{ +static void init_uids(void) { real_uid = getuid(); file_uid = geteuid(); uid_set = 1; } #endif - /* drop all additional privileges */ -void -drop_privs(void) -{ +void drop_privs(void) { #ifndef HAVE_DOSISH_SYSTEM - if (!uid_set) - init_uids(); + if (!uid_set) init_uids(); if (real_uid != file_uid) { if (setuid(real_uid) < 0) { perror("dropping privileges failed"); diff --git a/src/test/core/GpgCoreTestBasicOpera.cpp b/src/test/core/GpgCoreTestBasicOpera.cpp index e525afa9..238c9530 100644 --- a/src/test/core/GpgCoreTestBasicOpera.cpp +++ b/src/test/core/GpgCoreTestBasicOpera.cpp @@ -47,7 +47,7 @@ TEST_F(GpgCoreTest, CoreEncryptDecrTest) { "E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29"); GpgBasicOperator::GetInstance().Encrypt( - {encrypt_key}, GFBuffer("Hello GpgFrontend!"), true, + {encrypt_key}, GFBuffer(QString("Hello GpgFrontend!")), true, [&callback_called_flag](GpgError err, const DataObjectPtr& data_obj) { ASSERT_TRUE((data_obj->Check<GpgEncryptResult, GFBuffer>())); auto result = ExtractParams<GpgEncryptResult>(data_obj, 0); @@ -64,7 +64,8 @@ TEST_F(GpgCoreTest, CoreEncryptDecrTest) { ASSERT_FALSE(d_result.Recipients().empty()); ASSERT_EQ(d_result.Recipients()[0].keyid, "6A2764F8298DEB29"); - ASSERT_EQ(decr_out_buffer, GFBuffer("Hello GpgFrontend!")); + ASSERT_EQ(decr_out_buffer, + GFBuffer(QString("Hello GpgFrontend!"))); // stop waiting callback_called_flag = true; @@ -82,7 +83,7 @@ TEST_F(GpgCoreTest, CoreEncryptDecrTest) { TEST_F(GpgCoreTest, CoreEncryptSymmetricDecrTest) { std::atomic_bool callback_called_flag{false}; - auto encrypt_text = GFBuffer("Hello GpgFrontend!"); + auto encrypt_text = GFBuffer(QString("Hello GpgFrontend!")); GpgBasicOperator::GetInstance().EncryptSymmetric( encrypt_text, true, @@ -100,7 +101,8 @@ TEST_F(GpgCoreTest, CoreEncryptSymmetricDecrTest) { auto decr_out_buffer = ExtractParams<GFBuffer>(data_obj, 1); ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR); ASSERT_TRUE(d_result.Recipients().empty()); - ASSERT_EQ(decr_out_buffer, GFBuffer("Hello GpgFrontend!")); + ASSERT_EQ(decr_out_buffer, + GFBuffer(QString("Hello GpgFrontend!"))); // stop waiting callback_called_flag = true; @@ -118,7 +120,7 @@ TEST_F(GpgCoreTest, CoreEncryptSymmetricDecrTest) { TEST_F(GpgCoreTest, CoreEncryptDecrTest_KeyNotFound_1) { std::atomic_bool callback_called_flag{false}; - auto encr_out_data = GFBuffer( + auto encr_out_data = GFBuffer(QString( "-----BEGIN PGP MESSAGE-----\n" "\n" "hQEMA6UM/S9sZ32MAQf9Fb6gp6nvgKTQBv2mmjXia6ODXYq6kNeLsPVzLCbHyWOs\n" @@ -129,7 +131,7 @@ TEST_F(GpgCoreTest, CoreEncryptDecrTest_KeyNotFound_1) { "dIORyt5wugqAtgE4qEGTvr/pJ/oXPw4Wve/trece/9I/AR38vW8ntVmDa/hV75iZ\n" "4QGAhQ8grD4kq31GHXHUOmBX51XXW9SINmplC8elEx3R460EUZJjjb0OvTih+eZH\n" "=8n2H\n" - "-----END PGP MESSAGE-----"); + "-----END PGP MESSAGE-----")); GpgBasicOperator::GetInstance().Decrypt( encr_out_data, @@ -155,7 +157,7 @@ TEST_F(GpgCoreTest, CoreEncryptDecrTest_KeyNotFound_1) { TEST_F(GpgCoreTest, CoreEncryptDecrTest_KeyNotFound_ResultAnalyse) { std::atomic_bool callback_called_flag{false}; - auto encr_out_data = GFBuffer( + auto encr_out_data = GFBuffer(QString( "-----BEGIN PGP MESSAGE-----\n" "\n" "hQEMA6UM/S9sZ32MAQf9Fb6gp6nvgKTQBv2mmjXia6ODXYq6kNeLsPVzLCbHyWOs\n" @@ -166,7 +168,7 @@ TEST_F(GpgCoreTest, CoreEncryptDecrTest_KeyNotFound_ResultAnalyse) { "dIORyt5wugqAtgE4qEGTvr/pJ/oXPw4Wve/trece/9I/AR38vW8ntVmDa/hV75iZ\n" "4QGAhQ8grD4kq31GHXHUOmBX51XXW9SINmplC8elEx3R460EUZJjjb0OvTih+eZH\n" "=8n2H\n" - "-----END PGP MESSAGE-----"); + "-----END PGP MESSAGE-----")); GpgBasicOperator::GetInstance().Decrypt( encr_out_data, @@ -199,7 +201,7 @@ TEST_F(GpgCoreTest, CoreSignVerifyNormalTest) { auto sign_key = GpgKeyGetter::GetInstance().GetPubkey( "467F14220CE8DCF780CF4BAD8465C55B25C9B7D1"); - auto sign_text = GFBuffer("Hello GpgFrontend!"); + auto sign_text = GFBuffer(QString("Hello GpgFrontend!")); GpgBasicOperator::GetInstance().Sign( {sign_key}, sign_text, GPGME_SIG_MODE_NORMAL, true, @@ -238,7 +240,7 @@ TEST_F(GpgCoreTest, CoreSignVerifyDetachTest) { auto sign_key = GpgKeyGetter::GetInstance().GetPubkey( "467F14220CE8DCF780CF4BAD8465C55B25C9B7D1"); - auto sign_text = GFBuffer("Hello GpgFrontend!"); + auto sign_text = GFBuffer(QString("Hello GpgFrontend!")); GpgBasicOperator::GetInstance().Sign( {sign_key}, sign_text, GPGME_SIG_MODE_DETACH, true, @@ -277,7 +279,7 @@ TEST_F(GpgCoreTest, CoreSignVerifyClearTest) { auto sign_key = GpgKeyGetter::GetInstance().GetPubkey( "467F14220CE8DCF780CF4BAD8465C55B25C9B7D1"); - auto sign_text = GFBuffer("Hello GpgFrontend!"); + auto sign_text = GFBuffer(QString("Hello GpgFrontend!")); GpgBasicOperator::GetInstance().Sign( {sign_key}, sign_text, GPGME_SIG_MODE_CLEAR, true, @@ -318,7 +320,7 @@ TEST_F(GpgCoreTest, CoreEncryptSignDecrVerifyTest) { "467F14220CE8DCF780CF4BAD8465C55B25C9B7D1"); auto sign_key = GpgKeyGetter::GetInstance().GetKey( "8933EB283A18995F45D61DAC021D89771B680FFB"); - auto encrypt_text = GFBuffer("Hello GpgFrontend!"); + auto encrypt_text = GFBuffer(QString("Hello GpgFrontend!")); ASSERT_TRUE(sign_key.IsPrivateKey()); ASSERT_TRUE(sign_key.IsHasActualSigningCapability()); @@ -349,7 +351,8 @@ TEST_F(GpgCoreTest, CoreEncryptSignDecrVerifyTest) { ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR); ASSERT_FALSE(decrypt_result.Recipients().empty()); - ASSERT_EQ(decr_out_buffer, GFBuffer("Hello GpgFrontend!")); + ASSERT_EQ(decr_out_buffer, + GFBuffer(QString("Hello GpgFrontend!"))); ASSERT_EQ(decrypt_result.Recipients()[0].keyid, "F89C95A05088CC93"); diff --git a/src/test/core/GpgCoreTestFileBasicOpera.cpp b/src/test/core/GpgCoreTestFileBasicOpera.cpp index 029ff6fc..d5b0f52d 100644 --- a/src/test/core/GpgCoreTestFileBasicOpera.cpp +++ b/src/test/core/GpgCoreTestFileBasicOpera.cpp @@ -74,7 +74,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptDecrTest) { const auto [read_success, buffer] = ReadFileGFBuffer(decrpypt_output_file); ASSERT_TRUE(read_success); - ASSERT_EQ(buffer, GFBuffer("Hello GpgFrontend!")); + ASSERT_EQ(buffer, GFBuffer(QString("Hello GpgFrontend!"))); // stop waiting callback_called_flag = true; @@ -119,7 +119,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSymmetricDecrTest) { const auto [read_success, buffer] = ReadFileGFBuffer(decrpypt_output_file); ASSERT_TRUE(read_success); - ASSERT_EQ(buffer, GFBuffer("Hello GpgFrontend!")); + ASSERT_EQ(buffer, GFBuffer(QString("Hello GpgFrontend!"))); // stop waiting callback_called_flag = true; @@ -221,7 +221,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSignDecrVerifyTest) { const auto [read_success, buffer] = ReadFileGFBuffer(decrpypt_output_file); ASSERT_TRUE(read_success); - ASSERT_EQ(buffer, GFBuffer("Hello GpgFrontend!")); + ASSERT_EQ(buffer, GFBuffer(QString("Hello GpgFrontend!"))); // stop waiting callback_called_flag = true; |