aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-07-27 12:18:56 +0000
committersaturneric <[email protected]>2024-07-27 12:18:56 +0000
commite8efa4d104a889f60b2096510a7c492d74ed6b66 (patch)
tree0903bbb4f1a728b48a02de7f2024c1158b8aaf3f
parentfeat: improve sdk api for pinentry module (diff)
downloadGpgFrontend-e8efa4d104a889f60b2096510a7c492d74ed6b66.tar.gz
GpgFrontend-e8efa4d104a889f60b2096510a7c492d74ed6b66.zip
feat: move pinentry out of source code
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/core/function/CoreSignalStation.h6
-rw-r--r--src/core/function/gpg/GpgContext.cpp35
-rw-r--r--src/pinentry/CMakeLists.txt71
-rw-r--r--src/pinentry/accessibility.cpp44
-rw-r--r--src/pinentry/accessibility.h40
-rw-r--r--src/pinentry/capslock/capslock.cpp41
-rw-r--r--src/pinentry/capslock/capslock.h77
-rw-r--r--src/pinentry/capslock/capslock_unix.cpp137
-rw-r--r--src/pinentry/capslock/capslock_win.cpp26
-rw-r--r--src/pinentry/pinentry.cpp570
-rw-r--r--src/pinentry/pinentry.h339
-rw-r--r--src/pinentry/pinentry_debug.cpp31
-rw-r--r--src/pinentry/pinentry_debug.h28
-rw-r--r--src/pinentry/pinentryconfirm.cpp123
-rw-r--r--src/pinentry/pinentryconfirm.h63
-rw-r--r--src/pinentry/pinentrydialog.cpp634
-rw-r--r--src/pinentry/pinentrydialog.h170
-rw-r--r--src/pinentry/pinlineedit.cpp204
-rw-r--r--src/pinentry/pinlineedit.h60
-rw-r--r--src/pinentry/qti18n.cpp93
-rw-r--r--src/pinentry/secmem++.h91
-rw-r--r--src/ui/CMakeLists.txt3
-rw-r--r--src/ui/dialog/controller/ModuleControllerDialog.cpp4
-rw-r--r--src/ui/function/RaisePinentry.cpp112
-rw-r--r--src/ui/function/RaisePinentry.h60
-rw-r--r--src/ui/main_window/MainWindow.cpp4
-rw-r--r--src/ui/main_window/MainWindow.h5
-rw-r--r--src/ui/main_window/MainWindowSlotUI.cpp7
29 files changed, 26 insertions, 3057 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2802859f..9b590b7b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -80,10 +80,6 @@ endif ()
# Print modules
if (BUILD_CORE)
- # core depends pinentry
- message("[+] Build Pinentry")
- add_subdirectory(pinentry)
-
message("[+] Build Core")
add_subdirectory(core)
endif ()
@@ -492,7 +488,6 @@ if (LINUX AND LINUX_INSTALL_SOFTWARE)
gpgfrontend_core
gpgfrontend_ui
gpgfrontend_test
- gpgfrontend_pinentry
gpgfrontend_module_sdk)
message(STATUS "GpgFrontend Install Libraries: ${GPGFRONTEND_INSTALL_LIBRARIES}")
diff --git a/src/core/function/CoreSignalStation.h b/src/core/function/CoreSignalStation.h
index 8827c803..5c19f3b0 100644
--- a/src/core/function/CoreSignalStation.h
+++ b/src/core/function/CoreSignalStation.h
@@ -62,12 +62,6 @@ class GPGFRONTEND_CORE_EXPORT CoreSignalStation : public QObject {
* @brief
*
*/
- void SignalUserInputPassphraseCallback(QSharedPointer<GpgPassphraseContext>);
-
- /**
- * @brief
- *
- */
void SignalBadGnupgEnv(QString);
/**
diff --git a/src/core/function/gpg/GpgContext.cpp b/src/core/function/gpg/GpgContext.cpp
index e0869188..d89ce92a 100644
--- a/src/core/function/gpg/GpgContext.cpp
+++ b/src/core/function/gpg/GpgContext.cpp
@@ -139,32 +139,41 @@ class GpgContext::Impl {
<< ", last_was_bad: " << prev_was_bad;
QEventLoop looper;
- QObject::connect(CoreSignalStation::GetInstance(),
- &CoreSignalStation::SignalUserInputPassphraseCallback,
- &looper, &QEventLoop::quit);
+ QString passphrase = "";
+
+ Module::TriggerEvent(
+ "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"},
+ {"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();
+ });
- emit CoreSignalStation::GetInstance() -> SignalNeedUserInputPassphrase(
- context);
looper.exec();
-
ResetCacheValue("PinentryContext");
- auto passphrase = context->GetPassphrase().toStdString();
- auto passpahrase_size = passphrase.size();
- qCDebug(core, "get passphrase from pinentry size: %lu", passpahrase_size);
+
+ auto passphrase_size = passphrase.size();
+ qCWarning(core, "get passphrase from pinentry size: %lld", passphrase_size);
size_t res = 0;
- if (passpahrase_size > 0) {
+ if (passphrase_size > 0) {
size_t off = 0;
do {
- res = gpgme_io_write(fd, &passphrase[off], passpahrase_size - off);
+ res = gpgme_io_write(fd, &passphrase[off], passphrase_size - off);
if (res > 0) off += res;
- } while (res > 0 && off != passpahrase_size);
+ } while (res > 0 && off != passphrase_size);
}
res += gpgme_io_write(fd, "\n", 1);
qCDebug(core, "custom passphrase cd is about to return, res: %ld", res);
- return res == passpahrase_size + 1
+ return res == passphrase_size + 1
? 0
: gpgme_error_from_errno(GPG_ERR_CANCELED);
}
diff --git a/src/pinentry/CMakeLists.txt b/src/pinentry/CMakeLists.txt
deleted file mode 100644
index db2b0b4f..00000000
--- a/src/pinentry/CMakeLists.txt
+++ /dev/null
@@ -1,71 +0,0 @@
-# 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
-
-aux_source_directory(. PINENTRY_SOURCE)
-
-# capslock
-list(APPEND PINENTRY_SOURCE "capslock/capslock.cpp")
-if (MINGW)
- list(APPEND PINENTRY_SOURCE "capslock/capslock_win.cpp")
-else()
- list(APPEND PINENTRY_SOURCE "capslock/capslock_unix.cpp")
-endif()
-
-add_library(gpgfrontend_pinentry SHARED ${PINENTRY_SOURCE})
-
-
-# link options
-
-target_link_libraries(gpgfrontend_pinentry PUBLIC gpgfrontend_core)
-
-if(GPGFRONTEND_QT5_BUILD)
- # link Qt core
- target_link_libraries(gpgfrontend_pinentry PUBLIC Qt5::Widgets)
-else()
- # link Qt core
- target_link_libraries(gpgfrontend_pinentry PUBLIC Qt6::Widgets)
-endif()
-
-if (XCODE_BUILD)
- set_target_properties(gpgfrontend_pinentry
- PROPERTIES
- ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
- LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
- LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
- XCODE_ATTRIBUTE_SKIP_INSTALL "Yes"
- XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${GPGFRONTEND_XOCDE_CODE_SIGN_IDENTITY}")
-endif ()
-
-
-# using std c++ 17
-target_compile_features(gpgfrontend_pinentry PUBLIC cxx_std_17)
-
-
-# set lib output path
-if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
- set_target_properties(gpgfrontend_pinentry PROPERTIES
- LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/lib
- RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/lib)
-endif()
diff --git a/src/pinentry/accessibility.cpp b/src/pinentry/accessibility.cpp
deleted file mode 100644
index f139832a..00000000
--- a/src/pinentry/accessibility.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/* accessibility.cpp - Helpers for making pinentry accessible
- * Copyright (C) 2021 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 "accessibility.h"
-
-#include <QString>
-#include <QWidget>
-
-namespace Accessibility {
-
-void setDescription(QWidget *w, const QString &text) {
- if (w) {
-#ifndef QT_NO_ACCESSIBILITY
- w->setAccessibleDescription(text);
-#endif
- }
-}
-
-void setName(QWidget *w, const QString &text) {
- if (w) {
-#ifndef QT_NO_ACCESSIBILITY
- w->setAccessibleName(text);
-#endif
- }
-}
-
-} // namespace Accessibility
diff --git a/src/pinentry/accessibility.h b/src/pinentry/accessibility.h
deleted file mode 100644
index 9ef912d6..00000000
--- a/src/pinentry/accessibility.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* accessibility.h - Helpers for making pinentry accessible
- * Copyright (C) 2021 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 __PINENTRY_QT_ACCESSIBILITY_H__
-#define __PINENTRY_QT_ACCESSIBILITY_H__
-
-class QString;
-class QWidget;
-
-namespace Accessibility
-{
-
-/* Wrapper for QWidget::setAccessibleDescription which does nothing if
- QT_NO_ACCESSIBILITY is defined. */
-void setDescription(QWidget *w, const QString &text);
-
-/* Wrapper for QWidget::setAccessibleName which does nothing if
- QT_NO_ACCESSIBILITY is defined. */
-void setName(QWidget *w, const QString &text);
-
-} // namespace Accessibility
-
-#endif // __PINENTRY_QT_ACCESSIBILITY_H__
diff --git a/src/pinentry/capslock/capslock.cpp b/src/pinentry/capslock/capslock.cpp
deleted file mode 100644
index a730c220..00000000
--- a/src/pinentry/capslock/capslock.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/* capslock.cpp - Helper to check whether Caps Lock is on
- * Copyright (C) 2021 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 <QDebug>
-#include <QGuiApplication>
-
-#include "capslock.h"
-
-CapsLockWatcher::Private::Private(CapsLockWatcher *q) : q{q} {
-#ifdef PINENTRY_QT_WAYLAND
- if (qApp->platformName() == QLatin1String("wayland")) {
- watchWayland();
- }
-#endif
-}
-
-CapsLockWatcher::CapsLockWatcher(QObject *parent)
- : QObject{parent}, d{new Private{this}} {
- if (qApp->platformName() == QLatin1String("wayland")) {
-#ifndef PINENTRY_QT_WAYLAND
- qWarning() << "CapsLockWatcher was compiled without support for Wayland";
-#endif
- }
-}
diff --git a/src/pinentry/capslock/capslock.h b/src/pinentry/capslock/capslock.h
deleted file mode 100644
index 138f88cc..00000000
--- a/src/pinentry/capslock/capslock.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* capslock.h - Helper to check whether Caps Lock is on
- * Copyright (C) 2021 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 __PINENTRY_QT_CAPSLOCK_H__
-#define __PINENTRY_QT_CAPSLOCK_H__
-
-#include <QObject>
-#include <memory>
-
-enum class LockState { Unknown = -1, Off, On };
-
-LockState capsLockState();
-
-#ifdef PINENTRY_QT_WAYLAND
-namespace KWayland {
-namespace Client {
-class Registry;
-class Seat;
-} // namespace Client
-} // namespace KWayland
-#endif
-
-class CapsLockWatcher : public QObject {
- Q_OBJECT
-
- public:
- explicit CapsLockWatcher(QObject *parent = nullptr);
-
- Q_SIGNALS:
- void stateChanged(bool locked);
-
- private:
- class Private;
- std::unique_ptr<Private> d;
-};
-
-class CapsLockWatcher::Private {
- public:
- explicit Private(CapsLockWatcher *);
-#ifdef PINENTRY_QT_WAYLAND
- void watchWayland();
-#endif
-
- private:
-#ifdef PINENTRY_QT_WAYLAND
- void registry_seatAnnounced(quint32, quint32);
- void seat_hasKeyboardChanged(bool);
- void keyboard_modifiersChanged(quint32);
-#endif
-
- private:
- CapsLockWatcher *const q;
-
-#ifdef PINENTRY_QT_WAYLAND
- KWayland::Client::Registry *registry = nullptr;
- KWayland::Client::Seat *seat = nullptr;
-#endif
-};
-
-#endif // __PINENTRY_QT_CAPSLOCK_H__
diff --git a/src/pinentry/capslock/capslock_unix.cpp b/src/pinentry/capslock/capslock_unix.cpp
deleted file mode 100644
index e4f4cd17..00000000
--- a/src/pinentry/capslock/capslock_unix.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/* capslock_unix.cpp - Helper to check whether Caps Lock is on
- * Copyright (C) 2021 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+
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "capslock.h"
-
-#ifdef PINENTRY_QT_WAYLAND
-#include <KWayland/Client/connection_thread.h>
-#include <KWayland/Client/keyboard.h>
-#include <KWayland/Client/registry.h>
-#include <KWayland/Client/seat.h>
-#endif
-
-#include <QGuiApplication>
-
-#ifdef PINENTRY_QT_X11
-#include <X11/XKBlib.h>
-
-#include <QX11Info>
-#undef Status
-#endif
-
-#include <QDebug>
-
-#ifdef PINENTRY_QT_WAYLAND
-using namespace KWayland::Client;
-#endif
-
-#ifdef PINENTRY_QT_WAYLAND
-static bool watchingWayland = false;
-#endif
-
-LockState capsLockState() {
- static bool reportUnsupportedPlatform = true;
-#ifdef PINENTRY_QT_X11
- if (qApp->platformName() == QLatin1String("xcb")) {
- unsigned int state;
- XkbGetIndicatorState(QX11Info::display(), XkbUseCoreKbd, &state);
- return (state & 0x01) == 1 ? LockState::On : LockState::Off;
- }
-#endif
-#ifdef PINENTRY_QT_WAYLAND
- if (qApp->platformName() == QLatin1String("wayland")) {
- if (!watchingWayland && reportUnsupportedPlatform) {
- qDebug() << "Use CapsLockWatcher for checking for Caps Lock on Wayland";
- }
- } else
-#endif
- if (reportUnsupportedPlatform) {
- qWarning() << "Checking for Caps Lock not possible on unsupported platform:"
- << qApp->platformName();
- }
- reportUnsupportedPlatform = false;
- return LockState::Unknown;
-}
-
-#ifdef PINENTRY_QT_WAYLAND
-void CapsLockWatcher::Private::watchWayland() {
- watchingWayland = true;
- auto connection = ConnectionThread::fromApplication(q);
- if (!connection) {
- qWarning() << "Failed to get connection to Wayland server from QPA";
- return;
- }
- registry = new Registry{q};
- registry->create(connection);
- if (!registry->isValid()) {
- qWarning() << "Failed to create valid KWayland registry";
- return;
- }
- registry->setup();
-
- connect(registry, &Registry::seatAnnounced, q,
- [this](quint32 name, quint32 version) {
- registry_seatAnnounced(name, version);
- });
-}
-
-void CapsLockWatcher::Private::registry_seatAnnounced(quint32 name,
- quint32 version) {
- Q_ASSERT(registry);
- seat = registry->createSeat(name, version, q);
- if (!seat->isValid()) {
- qWarning() << "Failed to create valid KWayland seat";
- return;
- }
-
- connect(seat, &Seat::hasKeyboardChanged, q,
- [this](bool hasKeyboard) { seat_hasKeyboardChanged(hasKeyboard); });
-}
-
-void CapsLockWatcher::Private::seat_hasKeyboardChanged(bool hasKeyboard) {
- Q_ASSERT(seat);
-
- if (!hasKeyboard) {
- qDebug() << "Seat has no keyboard";
- return;
- }
-
- auto keyboard = seat->createKeyboard(q);
- if (!keyboard->isValid()) {
- qWarning() << "Failed to create valid KWayland keyboard";
- return;
- }
-
- connect(keyboard, &Keyboard::modifiersChanged, q,
- [this](quint32, quint32, quint32 locked, quint32) {
- keyboard_modifiersChanged(locked);
- });
-}
-
-void CapsLockWatcher::Private::keyboard_modifiersChanged(quint32 locked) {
- const bool capsLockIsLocked = (locked & 2u) != 0;
- qDebug() << "Caps Lock is locked:" << capsLockIsLocked;
- Q_EMIT q->stateChanged(capsLockIsLocked);
-}
-#endif
diff --git a/src/pinentry/capslock/capslock_win.cpp b/src/pinentry/capslock/capslock_win.cpp
deleted file mode 100644
index 46bc7043..00000000
--- a/src/pinentry/capslock/capslock_win.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/* capslock_win.cpp - Helper to check whether Caps Lock is on
- * Copyright (C) 2021 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 <windows.h>
-
-#include "capslock.h"
-
-LockState capsLockState() {
- return (GetKeyState(VK_CAPITAL) & 1) ? LockState::On : LockState::Off;
-}
diff --git a/src/pinentry/pinentry.cpp b/src/pinentry/pinentry.cpp
deleted file mode 100644
index 5f233f5d..00000000
--- a/src/pinentry/pinentry.cpp
+++ /dev/null
@@ -1,570 +0,0 @@
-/* pinentry.c - The PIN entry support library
- * Copyright (C) 2002, 2003, 2007, 2008, 2010, 2015, 2016, 2021 g10 Code GmbH
- *
- * This file is part of PINENTRY.
- *
- * PINENTRY 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.
- *
- * PINENTRY 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+
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifndef WINDOWS
-#include <errno.h>
-#endif
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#ifndef WINDOWS
-#include <sys/utsname.h>
-#endif
-#ifndef WINDOWS
-#include <locale.h>
-#endif
-#include <limits.h>
-#ifdef WINDOWS
-#include <windows.h>
-#endif
-
-#include <assuan.h>
-
-#include "core/utils/MemoryUtils.h"
-#include "pinentry.h"
-
-#ifdef WINDOWS
-#define getpid() GetCurrentProcessId()
-#endif
-
-/* Keep the name of our program here. */
-static char this_pgmname[50];
-
-struct pinentry pinentry;
-
-static const char *flavor_flag;
-
-/* Because gtk_init removes the --display arg from the command lines
- * and our command line parser is called after gtk_init (so that it
- * does not see gtk specific options) we don't have a way to get hold
- * of the --display option. Our solution is to remember --display in
- * the call to pinentry_have_display and set it then in our
- * parser. */
-static char *remember_display;
-
-static void pinentry_reset(int use_defaults) {
- /* GPG Agent sets these options once when it starts the pinentry.
- Don't reset them. */
- int grab = pinentry.grab;
- char *ttyname = pinentry.ttyname;
- char *ttytype = pinentry.ttytype_l;
- char *ttyalert = pinentry.ttyalert;
- char *lc_ctype = pinentry.lc_ctype;
- char *lc_messages = pinentry.lc_messages;
- int allow_external_password_cache = pinentry.allow_external_password_cache;
- char *default_ok = pinentry.default_ok;
- char *default_cancel = pinentry.default_cancel;
- char *default_prompt = pinentry.default_prompt;
- char *default_pwmngr = pinentry.default_pwmngr;
- char *default_cf_visi = pinentry.default_cf_visi;
- char *default_tt_visi = pinentry.default_tt_visi;
- char *default_tt_hide = pinentry.default_tt_hide;
- char *default_capshint = pinentry.default_capshint;
- char *touch_file = pinentry.touch_file;
- unsigned long owner_pid = pinentry.owner_pid;
- int owner_uid = pinentry.owner_uid;
- char *owner_host = pinentry.owner_host;
- int constraints_enforce = pinentry.constraints_enforce;
- char *constraints_hint_short = pinentry.constraints_hint_short;
- char *constraints_hint_long = pinentry.constraints_hint_long;
- char *constraints_error_title = pinentry.constraints_error_title;
-
- /* These options are set from the command line. Don't reset
- them. */
- int debug = pinentry.debug;
- char *display = pinentry.display;
- int parent_wid = pinentry.parent_wid;
-
- pinentry_color_t color_fg = pinentry.color_fg;
- int color_fg_bright = pinentry.color_fg_bright;
- pinentry_color_t color_bg = pinentry.color_bg;
- pinentry_color_t color_so = pinentry.color_so;
- int color_so_bright = pinentry.color_so_bright;
- pinentry_color_t color_ok = pinentry.color_ok;
- int color_ok_bright = pinentry.color_ok_bright;
- pinentry_color_t color_qualitybar = pinentry.color_qualitybar;
- int color_qualitybar_bright = pinentry.color_qualitybar_bright;
-
- int timeout = pinentry.timeout;
-
- char *invisible_char = pinentry.invisible_char;
-
- /* Free any allocated memory. */
- if (use_defaults) {
- free(pinentry.ttyname);
- free(pinentry.ttytype_l);
- free(pinentry.ttyalert);
- free(pinentry.lc_ctype);
- free(pinentry.lc_messages);
- free(pinentry.default_ok);
- free(pinentry.default_cancel);
- free(pinentry.default_prompt);
- free(pinentry.default_pwmngr);
- free(pinentry.default_cf_visi);
- free(pinentry.default_tt_visi);
- free(pinentry.default_tt_hide);
- free(pinentry.default_capshint);
- free(pinentry.touch_file);
- free(pinentry.owner_host);
- free(pinentry.display);
- free(pinentry.constraints_hint_short);
- free(pinentry.constraints_hint_long);
- free(pinentry.constraints_error_title);
- }
-
- free(pinentry.title);
- free(pinentry.description);
- free(pinentry.error);
- free(pinentry.prompt);
- free(pinentry.ok);
- free(pinentry.notok);
- free(pinentry.cancel);
- GpgFrontend::SecureFree(pinentry.pin);
- free(pinentry.repeat_passphrase);
- free(pinentry.repeat_error_string);
- free(pinentry.quality_bar);
- free(pinentry.quality_bar_tt);
- free(pinentry.formatted_passphrase_hint);
- free(pinentry.keyinfo);
- free(pinentry.specific_err_info);
-
- /* Reset the pinentry structure. */
- memset(&pinentry, 0, sizeof(pinentry));
-
- /* Restore options without a default we want to preserve. */
- pinentry.invisible_char = invisible_char;
-
- /* Restore other options or set defaults. */
-
- if (use_defaults) {
- /* Pinentry timeout in seconds. */
- pinentry.timeout = 60;
-
- /* Global grab. */
- pinentry.grab = 1;
-
- pinentry.color_fg = PINENTRY_COLOR_DEFAULT;
- pinentry.color_fg_bright = 0;
- pinentry.color_bg = PINENTRY_COLOR_DEFAULT;
- pinentry.color_so = PINENTRY_COLOR_DEFAULT;
- pinentry.color_so_bright = 0;
- pinentry.color_ok = PINENTRY_COLOR_DEFAULT;
- pinentry.color_ok_bright = 0;
- pinentry.color_qualitybar = PINENTRY_COLOR_DEFAULT;
- pinentry.color_qualitybar_bright = 0;
-
- pinentry.owner_uid = -1;
- } else /* Restore the options. */
- {
- pinentry.grab = grab;
- pinentry.ttyname = ttyname;
- pinentry.ttytype_l = ttytype;
- pinentry.ttyalert = ttyalert;
- pinentry.lc_ctype = lc_ctype;
- pinentry.lc_messages = lc_messages;
- pinentry.allow_external_password_cache = allow_external_password_cache;
- pinentry.default_ok = default_ok;
- pinentry.default_cancel = default_cancel;
- pinentry.default_prompt = default_prompt;
- pinentry.default_pwmngr = default_pwmngr;
- pinentry.default_cf_visi = default_cf_visi;
- pinentry.default_tt_visi = default_tt_visi;
- pinentry.default_tt_hide = default_tt_hide;
- pinentry.default_capshint = default_capshint;
- pinentry.touch_file = touch_file;
- pinentry.owner_pid = owner_pid;
- pinentry.owner_uid = owner_uid;
- pinentry.owner_host = owner_host;
- pinentry.constraints_enforce = constraints_enforce;
- pinentry.constraints_hint_short = constraints_hint_short;
- pinentry.constraints_hint_long = constraints_hint_long;
- pinentry.constraints_error_title = constraints_error_title;
-
- pinentry.debug = debug;
- pinentry.display = display;
- pinentry.parent_wid = parent_wid;
-
- pinentry.color_fg = color_fg;
- pinentry.color_fg_bright = color_fg_bright;
- pinentry.color_bg = color_bg;
- pinentry.color_so = color_so;
- pinentry.color_so_bright = color_so_bright;
- pinentry.color_ok = color_ok;
- pinentry.color_ok_bright = color_ok_bright;
- pinentry.color_qualitybar = color_qualitybar;
- pinentry.color_qualitybar_bright = color_qualitybar_bright;
-
- pinentry.timeout = timeout;
- }
-}
-
-static gpg_error_t pinentry_assuan_reset_handler(assuan_context_t ctx,
- char *line) {
- (void)ctx;
- (void)line;
-
- pinentry_reset(0);
-
- return 0;
-}
-
-/* Return a malloced copy of the commandline for PID. If this is not
- * possible NULL is returned. */
-#ifndef WINDOWS
-static char *get_cmdline(unsigned long pid) {
- char buffer[200];
- FILE *fp;
- size_t i, n;
-
- snprintf(buffer, sizeof buffer, "/proc/%lu/cmdline", pid);
-
- fp = fopen(buffer, "rb");
- if (!fp) return NULL;
- n = fread(buffer, 1, sizeof buffer - 1, fp);
- if (n < sizeof buffer - 1 && ferror(fp)) {
- /* Some error occurred. */
- fclose(fp);
- return NULL;
- }
- fclose(fp);
- if (n == 0) return NULL;
- /* Arguments are delimited by Nuls. We should do proper quoting but
- * that can be a bit complicated, thus we simply replace the Nuls by
- * spaces. */
- for (i = 0; i < n; i++)
- if (!buffer[i] && i < n - 1) buffer[i] = ' ';
- buffer[i] = 0; /* Make sure the last byte is the string terminator. */
-
- return strdup(buffer);
-}
-#endif /*!WINDOWS*/
-
-/* Atomically ask the kernel for information about process PID.
- * Return a malloc'ed copy of the process name as long as the process
- * uid matches UID. If it cannot determine that the process has uid
- * UID, it returns NULL.
- *
- * This is not as informative as get_cmdline, but it verifies that the
- * process does belong to the user in question.
- */
-#ifndef WINDOWS
-static char *get_pid_name_for_uid(unsigned long pid, int uid) {
- char buffer[400];
- FILE *fp;
- size_t end, n;
- char *uidstr;
-
- snprintf(buffer, sizeof buffer, "/proc/%lu/status", pid);
-
- fp = fopen(buffer, "rb");
- if (!fp) return NULL;
- n = fread(buffer, 1, sizeof buffer - 1, fp);
- if (n < sizeof buffer - 1 && ferror(fp)) {
- /* Some error occurred. */
- fclose(fp);
- return NULL;
- }
- fclose(fp);
- if (n == 0) return NULL;
- buffer[n] = 0;
- /* Fixme: Is it specified that "Name" is always the first line? For
- * robustness I would prefer to have a real parser here. -wk */
- if (strncmp(buffer, "Name:\t", 6)) return NULL;
- end = strcspn(buffer + 6, "\n") + 6;
- buffer[end] = 0;
-
- /* check that uid matches what we expect */
- uidstr = strstr(buffer + end + 1, "\nUid:\t");
- if (!uidstr) return NULL;
- if (atoi(uidstr + 6) != uid) return NULL;
-
- return strdup(buffer + 6);
-}
-#endif /*!WINDOWS*/
-
-const char *pinentry_get_pgmname(void) { return this_pgmname; }
-
-/* Return a malloced string with the title. The caller mus free the
- * string. If no title is available or the title string has an error
- * NULL is returned. */
-char *pinentry_get_title(pinentry_t pe) {
- char *title;
-
- if (pe->title) title = strdup(pe->title);
-#ifndef WINDOWS
- else if (pe->owner_pid) {
- char buf[200];
- struct utsname utsbuf;
- char *pidname = NULL;
- char *cmdline = NULL;
-
- if (pe->owner_host && !uname(&utsbuf) &&
- !strcmp(utsbuf.nodename, pe->owner_host)) {
- pidname = get_pid_name_for_uid(pe->owner_pid, pe->owner_uid);
- if (pidname) cmdline = get_cmdline(pe->owner_pid);
- }
-
- if (pe->owner_host && (cmdline || pidname))
- snprintf(buf, sizeof buf, "[%lu]@%s (%s)", pe->owner_pid, pe->owner_host,
- cmdline ? cmdline : pidname);
- else if (pe->owner_host)
- snprintf(buf, sizeof buf, "[%lu]@%s", pe->owner_pid, pe->owner_host);
- else
- snprintf(buf, sizeof buf, "[%lu] <unknown host>", pe->owner_pid);
- free(pidname);
- free(cmdline);
- title = strdup(buf);
- }
-#endif /*!WINDOWS*/
- else
- title = strdup(this_pgmname);
-
- return title;
-}
-
-/* Run a quality inquiry for PASSPHRASE of LENGTH. (We need LENGTH
- because not all backends might be able to return a proper
- C-string.). Returns: A value between -100 and 100 to give an
- estimate of the passphrase's quality. Negative values are use if
- the caller won't even accept that passphrase. Note that we expect
- just one data line which should not be escaped in any represent a
- numeric signed decimal value. Extra data is currently ignored but
- should not be send at all. */
-int pinentry_inq_quality(const QString &passphrase) {
- int score = 0;
-
- score += std::min(40, static_cast<int>(passphrase.length()) * 2);
-
- bool has_upper = false;
- bool has_lower = false;
- bool has_digit = false;
- bool has_special = false;
- for (const auto ch : passphrase) {
- if (ch.isUpper()) has_upper = true;
- if (ch.isLower()) has_lower = true;
- if (ch.isDigit()) has_digit = true;
- if (!ch.isLetterOrNumber()) has_special = true;
- }
-
- int const variety_count =
- static_cast<int>(has_upper) + static_cast<int>(has_lower) +
- static_cast<int>(has_digit) + static_cast<int>(has_special);
- score += variety_count * 10;
-
- for (auto i = 0; i < passphrase.length() - 1; ++i) {
- if (passphrase[i] == passphrase[i + 1]) {
- score -= 5;
- }
- }
-
- QHash<QChar, int> char_count;
- for (const auto ch : passphrase) {
- char_count[ch]++;
- }
- for (auto &p : char_count) {
- if (p > 1) {
- score -= (p - 1) * 3;
- }
- }
-
- QString const lower_password = passphrase.toLower();
- if (lower_password.contains("password") ||
- lower_password.contains("123456")) {
- score -= 30;
- }
-
- return std::max(-100, std::min(100, score));
-}
-
-/* Run a genpin inquiry */
-char *pinentry_inq_genpin(pinentry_t pin) {
- assuan_context_t ctx = (assuan_context_t)pin->ctx_assuan;
- const char prefix[] = "INQUIRE GENPIN";
- char *line;
- size_t linelen;
- int gotvalue = 0;
- char *value = NULL;
- int rc;
-
- if (!ctx) return 0; /* Can't run the callback. */
-
- rc = assuan_write_line(ctx, prefix);
- 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);
- free(value);
- 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;
-}
-
-/* Try to make room for at least LEN bytes in the pinentry. Returns
- new buffer on success and 0 on failure or when the old buffer is
- sufficient. */
-char *pinentry_setbufferlen(pinentry_t pin, int len) {
- char *newp;
-
- if (pin->pin_len)
- assert(pin->pin);
- else
- assert(!pin->pin);
-
- if (len < 2048) len = 2048;
-
- if (len <= pin->pin_len) return pin->pin;
-
- newp = GpgFrontend::SecureReallocAsType<char>(pin->pin, len);
- if (newp) {
- pin->pin = newp;
- pin->pin_len = len;
- } else {
- GpgFrontend::SecureFree(pin->pin);
- pin->pin = 0;
- pin->pin_len = 0;
- }
- return newp;
-}
-
-static void pinentry_setbuffer_clear(pinentry_t pin) {
- if (!pin->pin) {
- assert(pin->pin_len == 0);
- return;
- }
-
- assert(pin->pin_len > 0);
-
- GpgFrontend::SecureFree(pin->pin);
- pin->pin = NULL;
- pin->pin_len = 0;
-}
-
-static struct assuan_malloc_hooks assuan_malloc_hooks = {
- GpgFrontend::SecureMalloc, GpgFrontend::SecureRealloc,
- GpgFrontend::SecureFree};
-
-/* Simple test to check whether DISPLAY is set or the option --display
- was given. Used to decide whether the GUI or curses should be
- initialized. */
-int pinentry_have_display(int argc, char **argv) {
- int found = 0;
-
- for (; argc; argc--, argv++) {
- if (!strcmp(*argv, "--display")) {
- if (argv[1] && !remember_display) {
- remember_display = strdup(argv[1]);
- if (!remember_display) {
-#ifndef WINDOWS
- fprintf(stderr, "%s: %s\n", this_pgmname, strerror(errno));
-#endif
- exit(EXIT_FAILURE);
- }
- }
- found = 1;
- break;
- } else if (!strncmp(*argv, "--display=", 10)) {
- if (!remember_display) {
- remember_display = strdup(*argv + 10);
- if (!remember_display) {
-#ifndef WINDOWS
- fprintf(stderr, "%s: %s\n", this_pgmname, strerror(errno));
-#endif
- exit(EXIT_FAILURE);
- }
- }
- found = 1;
- break;
- }
- }
-
-#ifndef WINDOWS
- {
- const char *s;
- s = getenv("DISPLAY");
- if (s && *s) found = 1;
- }
-#endif
-
- return found;
-}
-
-/* Set the optional flag used with getinfo. */
-void pinentry_set_flavor_flag(const char *string) { flavor_flag = string; }
-
-/* Note, that it is sufficient to allocate the target string D as
- long as the source string S, i.e.: strlen(s)+1; */
-static void strcpy_escaped(char *d, const char *s) {
- while (*s) {
- if (*s == '%' && s[1] && s[2]) {
- s++;
- *d++ = xtoi_2(s);
- s += 2;
- } else
- *d++ = *s++;
- }
- *d = 0;
-}
-
-/* Return a staically allocated string with information on the mode,
- * uid, and gid of DEVICE. On error "?" is returned if DEVICE is
- * NULL, "-" is returned. */
-static const char *device_stat_string(const char *device) {
-#ifdef HAVE_STAT
- static char buf[40];
- struct stat st;
-
- if (!device || !*device) return "-";
-
- if (stat(device, &st)) return "?"; /* Error */
- snprintf(buf, sizeof buf, "%lo/%lu/%lu", (unsigned long)st.st_mode,
- (unsigned long)st.st_uid, (unsigned long)st.st_gid);
- return buf;
-#else
- return "-";
-#endif
-} \ No newline at end of file
diff --git a/src/pinentry/pinentry.h b/src/pinentry/pinentry.h
deleted file mode 100644
index 143a8855..00000000
--- a/src/pinentry/pinentry.h
+++ /dev/null
@@ -1,339 +0,0 @@
-/* pinentry.h - The interface for the PIN entry support library.
- * Copyright (C) 2002, 2003, 2010, 2015, 2021 g10 Code GmbH
- *
- * This file is part of PINENTRY.
- *
- * PINENTRY 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.
- *
- * PINENTRY 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 PINENTRY_H
-#define PINENTRY_H
-
-#include <cstdint>
-
-#ifdef __cplusplus
-extern "C" {
-#if 0
-}
-#endif
-#endif
-
-typedef enum {
- PINENTRY_COLOR_NONE,
- PINENTRY_COLOR_DEFAULT,
- PINENTRY_COLOR_BLACK,
- PINENTRY_COLOR_RED,
- PINENTRY_COLOR_GREEN,
- PINENTRY_COLOR_YELLOW,
- PINENTRY_COLOR_BLUE,
- PINENTRY_COLOR_MAGENTA,
- PINENTRY_COLOR_CYAN,
- PINENTRY_COLOR_WHITE
-} pinentry_color_t;
-
-struct pinentry {
- /* The window title, or NULL. (Assuan: "SETTITLE TITLE".) */
- char *title;
- /* The description to display, or NULL. (Assuan: "SETDESC
- DESC".) */
- char *description;
- /* The error message to display, or NULL. (Assuan: "SETERROR
- MESSAGE".) */
- char *error;
- /* The prompt to display, or NULL. (Assuan: "SETPROMPT
- prompt".) */
- char *prompt;
- /* The OK button text to display, or NULL. (Assuan: "SETOK
- OK".) */
- char *ok;
- /* The Not-OK button text to display, or NULL. This is the text for
- the alternative option shown by the third button. (Assuan:
- "SETNOTOK NOTOK".) */
- char *notok;
- /* The Cancel button text to display, or NULL. (Assuan: "SETCANCEL
- CANCEL".) */
- char *cancel;
-
- /* The buffer to store the secret into. */
- char *pin;
- /* The length of the buffer. */
- int pin_len;
- /* Whether the pin was read from an external cache (1) or entered by
- the user (0). */
- int pin_from_cache;
-
- /* The name of the X display to use if X is available and supported.
- (Assuan: "OPTION display DISPLAY".) */
- char *display;
- /* The name of the terminal node to open if X not available or
- supported. (Assuan: "OPTION ttyname TTYNAME".) */
- char *ttyname;
- /* The type of the terminal. (Assuan: "OPTION ttytype TTYTYPE".) */
- char *ttytype_l;
- /* Set the alert mode (none, beep or flash). */
- char *ttyalert;
- /* The LC_CTYPE value for the terminal. (Assuan: "OPTION lc-ctype
- LC_CTYPE".) */
- char *lc_ctype;
- /* The LC_MESSAGES value for the terminal. (Assuan: "OPTION
- lc-messages LC_MESSAGES".) */
- char *lc_messages;
-
- /* True if debug mode is requested. */
- int debug;
-
- /* The number of seconds before giving up while waiting for user input. */
- int timeout;
-
- /* True if caller should grab the keyboard. (Assuan: "OPTION grab"
- or "OPTION no-grab".) */
- int grab;
-
- /* The PID of the owner or 0 if not known. The owner is the process
- * which actually triggered the the pinentry. For example gpg. */
- unsigned long owner_pid;
-
- /* The numeric uid (user ID) of the owner process or -1 if not
- * known. */
- int owner_uid;
-
- /* The malloced hostname of the owner or NULL. */
- char *owner_host;
-
- /* The window ID of the parent window over which the pinentry window
- should be displayed. (Assuan: "OPTION parent-wid WID".) */
- int parent_wid;
-
- /* The name of an optional file which will be touched after a curses
- entry has been displayed. (Assuan: "OPTION touch-file
- FILENAME".) */
- char *touch_file;
-
- /* The frontend should set this to -1 if the user canceled the
- request, and to the length of the PIN stored in pin
- otherwise. */
- int result;
-
- /* The frontend should set this if the NOTOK button was pressed. */
- int canceled;
-
- /* The frontend should set this to true if an error with the local
- conversion occurred. */
- int locale_err;
-
- /* The frontend should set this to a gpg-error so that commands are
- able to return specific error codes. This is an ugly hack due to
- the fact that pinentry_cmd_handler_t returns the length of the
- passphrase or a negative error code. */
- int specific_err;
-
- /* The frontend may store a string with the error location here. */
- const char *specific_err_loc;
-
- /* The frontend may store a malloced string here to emit an ERROR
- * status code with this extra info along with SPECIFIC_ERR. */
- char *specific_err_info;
-
- /* The frontend should set this to true if the window close button
- has been used. This flag is used in addition to a regular return
- value. */
- int close_button;
-
- /* The caller should set this to true if only one button is
- required. This is useful for notification dialogs where only a
- dismiss button is required. */
- int one_button;
-
- /* Whether this is a CONFIRM pinentry. */
- int confirm;
-
- /* If true a second prompt for the passphrase is shown and the user
- is expected to enter the same passphrase again. Pinentry checks
- that both match. (Assuan: "SETREPEAT".) */
- char *repeat_passphrase;
-
- /* The string to show if a repeated passphrase does not match.
- (Assuan: "SETREPEATERROR ERROR".) */
- char *repeat_error_string;
-
- /* The string to show if a repeated passphrase does match.
- (Assuan: "SETREPEATOK STRING".) */
- char *repeat_ok_string;
-
- /* Set to true if the passphrase has been entered a second time and
- matches the first passphrase. */
- int repeat_okay;
-
- /* If this is not NULL, a passphrase quality indicator is shown.
- There will also be an inquiry back to the caller to get an
- indication of the quality for the passphrase entered so far. The
- string is used as a label for the quality bar. (Assuan:
- "SETQUALITYBAR LABEL".) */
- char *quality_bar;
-
- /* The tooltip to be shown for the qualitybar. Malloced or NULL.
- (Assuan: "SETQUALITYBAR_TT TOOLTIP".) */
- char *quality_bar_tt;
-
- /* If this is not NULL, a generate action should be shown.
- There will be an inquiry back to the caller to get such a
- PIN. generate action. Malloced or NULL.
- (Assuan: "SETGENPIN LABEL" .) */
- char *genpin_label;
-
- /* The tooltip to be shown for the generate action. Malloced or NULL.
- (Assuan: "SETGENPIN_TT TOOLTIP".) */
- char *genpin_tt;
-
- /* Specifies whether passphrase formatting should be enabled.
- (Assuan: "OPTION formatted-passphrase") */
- int formatted_passphrase;
-
- /* A hint to be shown near the passphrase input field if passphrase
- formatting is enabled. Malloced or NULL.
- (Assuan: "OPTION formatted-passphrase-hint=HINT".) */
- char *formatted_passphrase_hint;
-
- /* For the curses pinentry, the color of error messages. */
- pinentry_color_t color_fg;
- int color_fg_bright;
- pinentry_color_t color_bg;
- pinentry_color_t color_so;
- int color_so_bright;
- pinentry_color_t color_ok;
- int color_ok_bright;
- pinentry_color_t color_qualitybar;
- int color_qualitybar_bright;
-
- /* Malloced and i18ned default strings or NULL. These strings may
- include an underscore character to indicate an accelerator key.
- A double underscore represents a plain one. */
- /* (Assuan: "OPTION default-ok OK"). */
- char *default_ok;
- /* (Assuan: "OPTION default-cancel CANCEL"). */
- char *default_cancel;
- /* (Assuan: "OPTION default-prompt PROMPT"). */
- char *default_prompt;
- /* (Assuan: "OPTION default-pwmngr
- SAVE_PASSWORD_WITH_PASSWORD_MANAGER?"). */
- char *default_pwmngr;
- /* (Assuan: "OPTION default-cf-visi
- Do you really want to make your passphrase visible?"). */
- char *default_cf_visi;
- /* (Assuan: "OPTION default-tt-visi
- Make passphrase visible?"). */
- char *default_tt_visi;
- /* (Assuan: "OPTION default-tt-hide
- Hide passphrase"). */
- char *default_tt_hide;
- /* (Assuan: "OPTION default-capshint
- Caps Lock is on"). */
- char *default_capshint;
-
- /* Whether we are allowed to read the password from an external
- cache. (Assuan: "OPTION allow-external-password-cache") */
- int allow_external_password_cache;
-
- /* We only try the cache once. */
- int tried_password_cache;
-
- /* A stable identifier for the key. (Assuan: "SETKEYINFO
- KEYINFO".) */
- char *keyinfo;
-
- /* Whether we may cache the password (according to the user). */
- int may_cache_password;
-
- /* NOTE: If you add any additional fields to this structure, be sure
- to update the initializer in pinentry/pinentry.c!!! */
-
- /* For the quality indicator and genpin we need to do an inquiry.
- Thus we need to save the assuan ctx. */
- void *ctx_assuan;
-
- /* An UTF-8 string with an invisible character used to override the
- default in some pinentries. Only the first character is
- used. */
- char *invisible_char;
-
- /* Whether the passphrase constraints are enforced by gpg-agent.
- (Assuan: "OPTION constraints-enforce") */
- int constraints_enforce;
-
- /* A short translated hint for the user with the constraints for new
- passphrases to be displayed near the passphrase input field.
- Malloced or NULL.
- (Assuan: "OPTION constraints-hint-short=At least 8 characters".) */
- char *constraints_hint_short;
-
- /* A longer translated hint for the user with the constraints for new
- passphrases to be displayed for example as tooltip. Malloced or NULL.
- (Assuan: "OPTION constraints-hint-long=The passphrase must ...".) */
- char *constraints_hint_long;
-
- /* A short translated title for an error dialog informing the user about
- unsatisfied passphrase constraints. Malloced or NULL.
- (Assuan: "OPTION constraints-error-title=Passphrase Not Allowed".) */
- char *constraints_error_title;
-};
-typedef struct pinentry *pinentry_t;
-
-/* The pinentry command handler type processes the pinentry request
- PIN. If PIN->pin is zero, request a confirmation, otherwise a PIN
- entry. On confirmation, the function should return TRUE if
- confirmed, and FALSE otherwise. On PIN entry, the function should
- return -1 if an error occurred or the user cancelled the operation
- and 1 otherwise. */
-typedef int (*pinentry_cmd_handler_t)(pinentry_t pin);
-
-const char *pinentry_get_pgmname(void);
-
-char *pinentry_get_title(pinentry_t pe);
-
-/* Run a quality inquiry for PASSPHRASE of LENGTH. */
-int pinentry_inq_quality(const QString &passphrase);
-
-/* Run a genpin iquriry. Returns a malloced string or NULL */
-char *pinentry_inq_genpin(pinentry_t pin);
-
-/* Try to make room for at least LEN bytes for the pin in the pinentry
- PIN. Returns new buffer on success and 0 on failure. */
-char *pinentry_setbufferlen(pinentry_t pin, int len);
-
-/* Return true if either DISPLAY is set or ARGV contains the string
- "--display". */
-int pinentry_have_display(int argc, char **argv);
-
-/* Parse the command line options. May exit the program if only help
- or version output is requested. */
-void pinentry_parse_opts(int argc, char *argv[]);
-
-/* Set the optional flag used with getinfo. */
-void pinentry_set_flavor_flag(const char *string);
-
-#ifdef WINDOWS
-/* Windows declares sleep as obsolete, but provides a definition for
- _sleep but non for the still existing sleep. */
-#define sleep(a) _sleep((a))
-#endif /*WINDOWS*/
-
-#if 0
-{
-#endif
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PINENTRY_H */
diff --git a/src/pinentry/pinentry_debug.cpp b/src/pinentry/pinentry_debug.cpp
deleted file mode 100644
index 9afbcdb3..00000000
--- a/src/pinentry/pinentry_debug.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/* pinentry_debug.h - Logging category for pinentry
- * Copyright (C) 2021 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+
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "pinentry_debug.h"
-
-#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
-Q_LOGGING_CATEGORY(PINENTRY_LOG, "gpg.pinentry", QtWarningMsg)
-#else
-Q_LOGGING_CATEGORY(PINENTRY_LOG, "gpg.pinentry")
-#endif
diff --git a/src/pinentry/pinentry_debug.h b/src/pinentry/pinentry_debug.h
deleted file mode 100644
index fc8c808a..00000000
--- a/src/pinentry/pinentry_debug.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* pinentry_debug.h - Logging category for pinentry
- * Copyright (C) 2021 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 __PINENTRY_QT_DEBUG_H__
-#define __PINENTRY_QT_DEBUG_H__
-
-#include <QLoggingCategory>
-
-Q_DECLARE_LOGGING_CATEGORY(PINENTRY_LOG)
-
-#endif // __PINENTRY_QT_DEBUG_H__
diff --git a/src/pinentry/pinentryconfirm.cpp b/src/pinentry/pinentryconfirm.cpp
deleted file mode 100644
index 31d55b5c..00000000
--- a/src/pinentry/pinentryconfirm.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-/* pinentryconfirm.cpp - A QMessageBox with a timeout
- *
- * Copyright (C) 2011 Ben Kibbey <[email protected]>
- * 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 "pinentryconfirm.h"
-
-#include <QAbstractButton>
-#include <QApplication>
-#include <QFontMetrics>
-#include <QGridLayout>
-#include <QLabel>
-#include <QSpacerItem>
-
-#include "accessibility.h"
-#include "pinentrydialog.h"
-
-namespace {
-QLabel *messageBoxLabel(QMessageBox *messageBox) {
- return messageBox->findChild<QLabel *>(QStringLiteral("qt_msgbox_label"));
-}
-} // namespace
-
-PinentryConfirm::PinentryConfirm(Icon icon, const QString &title,
- const QString &text, StandardButtons buttons,
- QWidget *parent, Qt::WindowFlags flags)
- : QMessageBox{icon, title, text, buttons, parent, flags} {
- _timer.callOnTimeout(this, &PinentryConfirm::slotTimeout);
-
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::installActivationObserver(this);
- accessibilityActiveChanged(QAccessible::isActive());
-#endif
-
-#if QT_VERSION >= 0x050000
- /* This is in line with PinentryDialog ctor to have a maximizing
- * animation when opening. */
- if (qApp->platformName() != QLatin1String("wayland")) {
- setWindowState(Qt::WindowMinimized);
- QTimer::singleShot(0, this, [this]() { raiseWindow(this); });
- }
-#else
- activateWindow();
- raise();
-#endif
-}
-
-PinentryConfirm::~PinentryConfirm() {
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::removeActivationObserver(this);
-#endif
-}
-
-void PinentryConfirm::setTimeout(std::chrono::seconds timeout) {
- _timer.setInterval(timeout);
-}
-
-std::chrono::seconds PinentryConfirm::timeout() const {
- return std::chrono::duration_cast<std::chrono::seconds>(
- _timer.intervalAsDuration());
-}
-
-bool PinentryConfirm::timedOut() const { return _timed_out; }
-
-void PinentryConfirm::showEvent(QShowEvent *event) {
- static bool resized;
- if (!resized) {
- QGridLayout *lay = dynamic_cast<QGridLayout *>(layout());
- if (lay) {
- QSize textSize = fontMetrics().size(Qt::TextExpandTabs, text(),
- fontMetrics().maxWidth());
- QSpacerItem *horizontalSpacer =
- new QSpacerItem(textSize.width() + iconPixmap().width(), 0,
- QSizePolicy::Minimum, QSizePolicy::Expanding);
- lay->addItem(horizontalSpacer, lay->rowCount(), 1, 1,
- lay->columnCount() - 1);
- }
- resized = true;
- }
-
- QMessageBox::showEvent(event);
-
- if (timeout() > std::chrono::milliseconds::zero()) {
- _timer.setSingleShot(true);
- _timer.start();
- }
-}
-
-void PinentryConfirm::slotTimeout() {
- QAbstractButton *b = button(QMessageBox::Cancel);
- _timed_out = true;
-
- if (b) {
- b->animateClick();
- }
-}
-
-#ifndef QT_NO_ACCESSIBILITY
-void PinentryConfirm::accessibilityActiveChanged(bool active) {
- // Allow text label to get focus if accessibility is active
- const auto focusPolicy = active ? Qt::StrongFocus : Qt::ClickFocus;
- if (auto label = messageBoxLabel(this)) {
- label->setFocusPolicy(focusPolicy);
- }
-}
-#endif
diff --git a/src/pinentry/pinentryconfirm.h b/src/pinentry/pinentryconfirm.h
deleted file mode 100644
index 7be7c268..00000000
--- a/src/pinentry/pinentryconfirm.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* pinentryconfirm.h - A QMessageBox with a timeout
- *
- * Copyright (C) 2011 Ben Kibbey <[email protected]>
- * 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 PINENTRYCONFIRM_H
-#define PINENTRYCONFIRM_H
-
-#include <QAccessible>
-#include <QMessageBox>
-#include <QTimer>
-
-class PinentryConfirm : public QMessageBox
-#ifndef QT_NO_ACCESSIBILITY
- , public QAccessible::ActivationObserver
-#endif
-{
- Q_OBJECT
-public:
- PinentryConfirm(Icon icon, const QString &title, const QString &text,
- StandardButtons buttons = NoButton, QWidget *parent = nullptr,
- Qt::WindowFlags flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
- ~PinentryConfirm() override;
-
- void setTimeout(std::chrono::seconds timeout);
- std::chrono::seconds timeout() const;
-
- bool timedOut() const;
-
-protected:
- void showEvent(QShowEvent *event) override;
-
-private Q_SLOTS:
- void slotTimeout();
-
-private:
-#ifndef QT_NO_ACCESSIBILITY
- void accessibilityActiveChanged(bool active) override;
-#endif
-
-private:
- QTimer _timer;
- bool _timed_out = false;
-};
-
-#endif
diff --git a/src/pinentry/pinentrydialog.cpp b/src/pinentry/pinentrydialog.cpp
deleted file mode 100644
index d63b0015..00000000
--- a/src/pinentry/pinentrydialog.cpp
+++ /dev/null
@@ -1,634 +0,0 @@
-/* pinentrydialog.cpp - A (not yet) secure Qt 4 dialog for PIN entry.
- * Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
- * Copyright 2007 Ingo Klöcker
- * Copyright 2016 Intevation GmbH
- * Copyright (C) 2021, 2022 g10 Code GmbH
- *
- * Written by Steffen Hansen <[email protected]>.
- * Modified by Andre Heinecke <[email protected]>
- * 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 "pinentrydialog.h"
-
-#include <qnamespace.h>
-
-#include <QAccessible>
-#include <QAction>
-#include <QApplication>
-#include <QCheckBox>
-#include <QDebug>
-#include <QDialogButtonBox>
-#include <QFontMetrics>
-#include <QGridLayout>
-#include <QHBoxLayout>
-#include <QKeyEvent>
-#include <QLabel>
-#include <QLineEdit>
-#include <QMessageBox>
-#include <QPainter>
-#include <QPalette>
-#include <QProgressBar>
-#include <QPushButton>
-#include <QRegularExpression>
-#include <QStyle>
-#include <QVBoxLayout>
-
-#include "accessibility.h"
-#include "capslock/capslock.h"
-#include "core/utils/MemoryUtils.h"
-#include "pinentry.h"
-#include "pinlineedit.h"
-
-void raiseWindow(QWidget *w) {
- w->setWindowState((w->windowState() & ~Qt::WindowMinimized) |
- Qt::WindowActive);
- w->activateWindow();
- w->raise();
-}
-
-auto applicationIconPixmap(const QIcon &overlayIcon) -> QPixmap {
- QPixmap pm = qApp->windowIcon().pixmap(48, 48);
-
- if (!overlayIcon.isNull()) {
- QPainter painter(&pm);
- const int emblem_size = 22;
- painter.drawPixmap(pm.width() - emblem_size, 0,
- overlayIcon.pixmap(emblem_size, emblem_size));
- }
-
- return pm;
-}
-
-void PinEntryDialog::slotTimeout() {
- _timed_out = true;
- reject();
-}
-
-PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name, int timeout,
- bool modal, bool enable_quality_bar,
- const QString &repeatString,
- const QString &visibilityTT,
- const QString &hideTT)
- : QDialog{parent},
- _have_quality_bar{enable_quality_bar},
- mVisibilityTT{visibilityTT},
- mHideTT{hideTT} {
- Q_UNUSED(name)
-
- if (modal) {
- setWindowModality(Qt::ApplicationModal);
- setModal(true);
- }
-
- QPalette red_text_palette;
- red_text_palette.setColor(QPalette::WindowText, Qt::red);
-
- auto *const main_layout = new QVBoxLayout{this};
-
- auto *const hbox = new QHBoxLayout;
-
- _icon = new QLabel(this);
- _icon->setPixmap(applicationIconPixmap());
- hbox->addWidget(_icon, 0, Qt::AlignVCenter | Qt::AlignLeft);
-
- auto *const grid = new QGridLayout;
- int row = 1;
-
- _error = new QLabel{this};
- _error->setTextFormat(Qt::PlainText);
- _error->setTextInteractionFlags(Qt::TextSelectableByMouse);
- _error->setPalette(red_text_palette);
- _error->hide();
- grid->addWidget(_error, row, 1, 1, 2);
-
- row++;
- _desc = new QLabel{this};
- _desc->setTextFormat(Qt::PlainText);
- _desc->setTextInteractionFlags(Qt::TextSelectableByMouse);
- _desc->hide();
- grid->addWidget(_desc, row, 1, 1, 2);
-
- row++;
- mCapsLockHint = new QLabel{this};
- mCapsLockHint->setTextFormat(Qt::PlainText);
- mCapsLockHint->setTextInteractionFlags(Qt::TextSelectableByMouse);
- mCapsLockHint->setPalette(red_text_palette);
- mCapsLockHint->setAlignment(Qt::AlignCenter);
- mCapsLockHint->setVisible(false);
- grid->addWidget(mCapsLockHint, row, 1, 1, 2);
-
- row++;
- {
- _prompt = new QLabel(this);
- _prompt->setTextFormat(Qt::PlainText);
- _prompt->setTextInteractionFlags(Qt::TextSelectableByMouse);
- _prompt->hide();
- grid->addWidget(_prompt, row, 1);
-
- auto *const l = new QHBoxLayout;
- _edit = new PinLineEdit(this);
- _edit->setMaxLength(256);
- _edit->setMinimumWidth(_edit->fontMetrics().averageCharWidth() * 20 + 48);
- _edit->setEchoMode(QLineEdit::Password);
- _prompt->setBuddy(_edit);
- l->addWidget(_edit, 1);
-
- if (!repeatString.isNull()) {
- mGenerateButton = new QPushButton{this};
- mGenerateButton->setIcon(QIcon(QLatin1String(":password-generate.svg")));
- mGenerateButton->setVisible(false);
- l->addWidget(mGenerateButton);
- }
- grid->addLayout(l, row, 2);
- }
-
- /* Set up the show password action */
- const QIcon visibility_icon = QIcon(QLatin1String(":visibility.svg"));
- const QIcon hide_icon = QIcon(QLatin1String(":hint.svg"));
-#if QT_VERSION >= 0x050200
- if (!visibility_icon.isNull() && !hide_icon.isNull()) {
- mVisiActionEdit =
- _edit->addAction(visibility_icon, QLineEdit::TrailingPosition);
- mVisiActionEdit->setVisible(false);
- mVisiActionEdit->setToolTip(mVisibilityTT);
- } else
-#endif
- {
- if (!mVisibilityTT.isNull()) {
- row++;
- mVisiCB = new QCheckBox{mVisibilityTT, this};
- grid->addWidget(mVisiCB, row, 1, 1, 2, Qt::AlignLeft);
- }
- }
-
- row++;
- mConstraintsHint = new QLabel{this};
- mConstraintsHint->setTextFormat(Qt::PlainText);
- mConstraintsHint->setTextInteractionFlags(Qt::TextSelectableByMouse);
- mConstraintsHint->setVisible(false);
- grid->addWidget(mConstraintsHint, row, 2);
-
- row++;
- mFormattedPassphraseHintSpacer = new QLabel{this};
- mFormattedPassphraseHintSpacer->setVisible(false);
- mFormattedPassphraseHint = new QLabel{this};
- mFormattedPassphraseHint->setTextFormat(Qt::PlainText);
- mFormattedPassphraseHint->setTextInteractionFlags(Qt::TextSelectableByMouse);
- mFormattedPassphraseHint->setVisible(false);
- grid->addWidget(mFormattedPassphraseHintSpacer, row, 1);
- grid->addWidget(mFormattedPassphraseHint, row, 2);
-
- if (!repeatString.isNull()) {
- row++;
- auto *repeat_label = new QLabel{this};
- repeat_label->setTextFormat(Qt::PlainText);
- repeat_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
- repeat_label->setText(repeatString);
- grid->addWidget(repeat_label, row, 1);
-
- mRepeat = new PinLineEdit(this);
- mRepeat->setMaxLength(256);
- mRepeat->setEchoMode(QLineEdit::Password);
- repeat_label->setBuddy(mRepeat);
- grid->addWidget(mRepeat, row, 2);
-
- row++;
- mRepeatError = new QLabel{this};
- mRepeatError->setTextFormat(Qt::PlainText);
- mRepeatError->setTextInteractionFlags(Qt::TextSelectableByMouse);
- mRepeatError->setPalette(red_text_palette);
- mRepeatError->hide();
- grid->addWidget(mRepeatError, row, 2);
- }
-
- if (enable_quality_bar) {
- row++;
- _quality_bar_label = new QLabel(this);
- _quality_bar_label->setTextFormat(Qt::PlainText);
- _quality_bar_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
- _quality_bar_label->setAlignment(Qt::AlignVCenter);
- grid->addWidget(_quality_bar_label, row, 1);
-
- _quality_bar = new QProgressBar(this);
- _quality_bar->setAlignment(Qt::AlignCenter);
- _quality_bar_label->setBuddy(_quality_bar);
- grid->addWidget(_quality_bar, row, 2);
- }
-
- hbox->addLayout(grid, 1);
- main_layout->addLayout(hbox);
-
- auto *const buttons = new QDialogButtonBox(this);
- buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
- _ok = buttons->button(QDialogButtonBox::Ok);
- _cancel = buttons->button(QDialogButtonBox::Cancel);
-
- if (style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons)) {
- _ok->setIcon(style()->standardIcon(QStyle::SP_DialogOkButton));
- _cancel->setIcon(style()->standardIcon(QStyle::SP_DialogCancelButton));
- }
-
- main_layout->addStretch(1);
- main_layout->addWidget(buttons);
- main_layout->setSizeConstraint(QLayout::SetFixedSize);
-
- if (timeout > 0) {
- _timer = new QTimer(this);
- connect(_timer, &QTimer::timeout, this, &PinEntryDialog::slotTimeout);
- _timer->start(timeout * 1000);
- }
-
- connect(buttons, &QDialogButtonBox::accepted, this,
- &PinEntryDialog::onAccept);
- connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
- connect(_edit, &QLineEdit::textChanged, this, &PinEntryDialog::updateQuality);
- connect(_edit, &QLineEdit::textChanged, this, &PinEntryDialog::textChanged);
- connect(_edit, &PinLineEdit::backspacePressed, this,
- &PinEntryDialog::onBackspace);
- if (mGenerateButton != nullptr) {
- connect(mGenerateButton, &QPushButton::clicked, this,
- &PinEntryDialog::generatePin);
- }
- if (mVisiActionEdit != nullptr) {
- connect(mVisiActionEdit, &QAction::triggered, this,
- &PinEntryDialog::toggleVisibility);
- }
- if (mVisiCB != nullptr) {
- connect(mVisiCB, &QCheckBox::toggled, this,
- &PinEntryDialog::toggleVisibility);
- }
- if (mRepeat != nullptr) {
- connect(mRepeat, &QLineEdit::textChanged, this,
- &PinEntryDialog::textChanged);
- }
-
- auto *caps_lock_watcher = new CapsLockWatcher{this};
- connect(caps_lock_watcher, &CapsLockWatcher::stateChanged, this,
- [this](bool locked) { mCapsLockHint->setVisible(locked); });
-
- connect(qApp, &QApplication::focusChanged, this,
- &PinEntryDialog::focusChanged);
- connect(qApp, &QApplication::applicationStateChanged, this,
- &PinEntryDialog::checkCapsLock);
- checkCapsLock();
-
- setAttribute(Qt::WA_DeleteOnClose);
- setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
-
- /* This is mostly an issue on Windows where this results
- in the pinentry popping up nicely with an animation and
- comes to front. It is not ifdefed for Windows only since
- window managers on Linux like KWin can also have this
- result in an animation when the pinentry is shown and
- not just popping it up.
- */
- if (qApp->platformName() != QLatin1String("wayland")) {
- setWindowState(Qt::WindowMinimized);
- QTimer::singleShot(0, this, [this]() { raiseWindow(this); });
- } else {
- raiseWindow(this);
- }
-}
-
-void PinEntryDialog::keyPressEvent(QKeyEvent *e) {
- const auto return_pressed =
- (!e->modifiers() &&
- (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)) ||
- (e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter);
- if (return_pressed && _edit->hasFocus() && (mRepeat != nullptr)) {
- // if the user pressed Return in the first input field, then move the
- // focus to the repeat input field and prevent further event processing
- // by QDialog (which would trigger the default button)
- mRepeat->setFocus();
- e->ignore();
- return;
- }
-
- QDialog::keyPressEvent(e);
-}
-
-void PinEntryDialog::keyReleaseEvent(QKeyEvent *event) {
- QDialog::keyReleaseEvent(event);
- checkCapsLock();
-}
-
-void PinEntryDialog::showEvent(QShowEvent *event) {
- QDialog::showEvent(event);
- _edit->setFocus();
-}
-
-void PinEntryDialog::setDescription(const QString &txt) {
- _desc->setVisible(!txt.isEmpty());
- _desc->setText(txt);
- _icon->setPixmap(applicationIconPixmap());
- setError(QString());
-}
-
-QString PinEntryDialog::description() const { return _desc->text(); }
-
-void PinEntryDialog::setError(const QString &txt) {
- if (!txt.isNull()) {
- _icon->setPixmap(
- applicationIconPixmap(QIcon{QStringLiteral(":data-error.svg")}));
- }
- _error->setText(txt);
- _error->setVisible(!txt.isEmpty());
-}
-
-QString PinEntryDialog::error() const { return _error->text(); }
-
-void PinEntryDialog::setPin(const QString &txt) { _edit->setPin(txt); }
-
-QString PinEntryDialog::pin() const { return _edit->pin(); }
-
-void PinEntryDialog::setPrompt(const QString &txt) {
- _prompt->setText(txt);
- _prompt->setVisible(!txt.isEmpty());
- if (txt.contains("PIN")) _disable_echo_allowed = false;
-}
-
-QString PinEntryDialog::prompt() const { return _prompt->text(); }
-
-void PinEntryDialog::setOkText(const QString &txt) {
- _ok->setText(txt);
- _ok->setVisible(!txt.isEmpty());
-}
-
-void PinEntryDialog::setCancelText(const QString &txt) {
- _cancel->setText(txt);
- _cancel->setVisible(!txt.isEmpty());
-}
-
-void PinEntryDialog::setQualityBar(const QString &txt) {
- if (_have_quality_bar) {
- _quality_bar_label->setText(txt);
- }
-}
-
-void PinEntryDialog::setQualityBarTT(const QString &txt) {
- if (_have_quality_bar) {
- _quality_bar->setToolTip(txt);
- }
-}
-
-void PinEntryDialog::setGenpinLabel(const QString &txt) {
- if (mGenerateButton == nullptr) {
- return;
- }
- mGenerateButton->setVisible(!txt.isEmpty());
- if (!txt.isEmpty()) {
- Accessibility::setName(mGenerateButton, txt);
- }
-}
-
-void PinEntryDialog::setGenpinTT(const QString &txt) {
- if (mGenerateButton != nullptr) {
- mGenerateButton->setToolTip(txt);
- }
-}
-
-void PinEntryDialog::setCapsLockHint(const QString &txt) {
- mCapsLockHint->setText(txt);
-}
-
-void PinEntryDialog::setFormattedPassphrase(
- const PinEntryDialog::FormattedPassphraseOptions &options) {
- mFormatPassphrase = options.formatPassphrase;
- mFormattedPassphraseHint->setTextFormat(Qt::RichText);
- mFormattedPassphraseHint->setText(QLatin1String("<html>") +
- options.hint.toHtmlEscaped() +
- QLatin1String("</html>"));
- Accessibility::setName(mFormattedPassphraseHint, options.hint);
- // toggleFormattedPassphrase();
-}
-
-void PinEntryDialog::setConstraintsOptions(const ConstraintsOptions &options) {
- mEnforceConstraints = options.enforce;
- mConstraintsHint->setText(options.shortHint);
- if (!options.longHint.isEmpty()) {
- mConstraintsHint->setToolTip(
- QLatin1String("<html>") +
- options.longHint.toHtmlEscaped().replace(QLatin1String("\n\n"),
- QLatin1String("<br>")) +
- QLatin1String("</html>"));
- Accessibility::setDescription(mConstraintsHint, options.longHint);
- }
- mConstraintsErrorTitle = options.errorTitle;
-
- mConstraintsHint->setVisible(mEnforceConstraints &&
- !options.shortHint.isEmpty());
-}
-
-void PinEntryDialog::toggleFormattedPassphrase() {
- const bool enable_formatting =
- mFormatPassphrase && _edit->echoMode() == QLineEdit::Normal;
- _edit->setFormattedPassphrase(enable_formatting);
- if (mRepeat != nullptr) {
- mRepeat->setFormattedPassphrase(enable_formatting);
- const bool hint_about_to_be_hidden =
- mFormattedPassphraseHint->isVisible() && !enable_formatting;
- if (hint_about_to_be_hidden) {
- // set hint spacer to current height of hint label before hiding the hint
- mFormattedPassphraseHintSpacer->setMinimumHeight(
- mFormattedPassphraseHint->height());
- mFormattedPassphraseHintSpacer->setVisible(true);
- } else if (enable_formatting) {
- mFormattedPassphraseHintSpacer->setVisible(false);
- }
- mFormattedPassphraseHint->setVisible(enable_formatting);
- }
-}
-
-void PinEntryDialog::onBackspace() {
- cancelTimeout();
-
- if (_disable_echo_allowed) {
- _edit->setEchoMode(QLineEdit::NoEcho);
- if (mRepeat != nullptr) {
- mRepeat->setEchoMode(QLineEdit::NoEcho);
- }
- }
-}
-
-void PinEntryDialog::updateQuality(const QString &txt) {
- int length;
- int percent;
- QPalette pal;
-
- _disable_echo_allowed = false;
-
- if (!_have_quality_bar) {
- return;
- }
-
- length = txt.length();
- percent = length != 0 ? pinentry_inq_quality(txt) : 0;
- if (length == 0) {
- _quality_bar->reset();
- } else {
- pal = _quality_bar->palette();
- if (percent < 0) {
- pal.setColor(QPalette::Highlight, QColor("red"));
- percent = -percent;
- } else {
- pal.setColor(QPalette::Highlight, QColor("green"));
- }
- _quality_bar->setPalette(pal);
- _quality_bar->setValue(percent);
- }
-}
-
-void PinEntryDialog::setPinentryInfo(struct pinentry peinfo) {
- _pinentry_info =
- GpgFrontend::SecureCreateUniqueObject<struct pinentry>(peinfo);
-}
-
-void PinEntryDialog::focusChanged(QWidget *old, QWidget *now) {
- // Grab keyboard. It might be a little weird to do it here, but it works!
- // Previously this code was in showEvent, but that did not work in Qt4.
- if (!_pinentry_info || (_pinentry_info->grab != 0)) {
- if (_grabbed && (old != nullptr) && (old == _edit || old == mRepeat)) {
- old->releaseKeyboard();
- _grabbed = false;
- }
- if (!_grabbed && (now != nullptr) && (now == _edit || now == mRepeat)) {
- now->grabKeyboard();
- _grabbed = true;
- }
- }
-}
-
-void PinEntryDialog::textChanged(const QString &text) {
- Q_UNUSED(text);
-
- cancelTimeout();
-
- if ((mVisiActionEdit != nullptr) && sender() == _edit) {
- mVisiActionEdit->setVisible(!_edit->pin().isEmpty());
- }
- if (mGenerateButton != nullptr) {
- mGenerateButton->setVisible(_edit->pin().isEmpty()
-#ifndef QT_NO_ACCESSIBILITY
- && !mGenerateButton->accessibleName().isEmpty()
-#endif
- );
- }
-}
-
-void PinEntryDialog::generatePin() {
- // std::unique_ptr<char> pin{pinentry_inq_genpin(_pinentry_info.get())};
- // if (pin) {
- // if (_edit->echoMode() == QLineEdit::Password) {
- // if (mVisiActionEdit != nullptr) {
- // mVisiActionEdit->trigger();
- // }
- // if (mVisiCB != nullptr) {
- // mVisiCB->setChecked(true);
- // }
- // }
- // const auto pin_str = QString::fromUtf8(pin.get());
- // _edit->setPin(pin_str);
- // mRepeat->setPin(pin_str);
- // // explicitly focus the first input field and select the generated
- // password _edit->setFocus(); _edit->selectAll();
- // }
-}
-
-void PinEntryDialog::toggleVisibility() {
- if (sender() != mVisiCB) {
- if (_edit->echoMode() == QLineEdit::Password) {
- if (mVisiActionEdit != nullptr) {
- mVisiActionEdit->setIcon(QIcon(QLatin1String(":hint.svg")));
- mVisiActionEdit->setToolTip(mHideTT);
- }
- _edit->setEchoMode(QLineEdit::Normal);
- if (mRepeat != nullptr) {
- mRepeat->setEchoMode(QLineEdit::Normal);
- }
- } else {
- if (mVisiActionEdit != nullptr) {
- mVisiActionEdit->setIcon(QIcon(QLatin1String(":visibility.svg")));
- mVisiActionEdit->setToolTip(mVisibilityTT);
- }
- _edit->setEchoMode(QLineEdit::Password);
- if (mRepeat != nullptr) {
- mRepeat->setEchoMode(QLineEdit::Password);
- }
- }
- } else {
- if (mVisiCB->isChecked()) {
- if (mRepeat != nullptr) {
- mRepeat->setEchoMode(QLineEdit::Normal);
- }
- _edit->setEchoMode(QLineEdit::Normal);
- } else {
- if (mRepeat != nullptr) {
- mRepeat->setEchoMode(QLineEdit::Password);
- }
- _edit->setEchoMode(QLineEdit::Password);
- }
- }
- toggleFormattedPassphrase();
-}
-
-QString PinEntryDialog::repeatedPin() const {
- if (mRepeat != nullptr) {
- return mRepeat->pin();
- }
- return QString();
-}
-
-bool PinEntryDialog::timedOut() const { return _timed_out; }
-
-void PinEntryDialog::setRepeatErrorText(const QString &err) {
- if (mRepeatError != nullptr) {
- mRepeatError->setText(err);
- }
-}
-
-void PinEntryDialog::cancelTimeout() {
- if (_timer != nullptr) {
- _timer->stop();
- }
-}
-
-void PinEntryDialog::checkCapsLock() {
- const auto state = capsLockState();
- if (state != LockState::Unknown) {
- mCapsLockHint->setVisible(state == LockState::On);
- }
-}
-
-void PinEntryDialog::onAccept() {
- cancelTimeout();
-
- if ((mRepeat != nullptr) && mRepeat->pin() != _edit->pin()) {
-#ifndef QT_NO_ACCESSIBILITY
- if (QAccessible::isActive()) {
- QMessageBox::information(this, mRepeatError->text(),
- mRepeatError->text());
- } else
-#endif
- {
- mRepeatError->setVisible(true);
- }
- return;
- }
-
- accept();
-}
diff --git a/src/pinentry/pinentrydialog.h b/src/pinentry/pinentrydialog.h
deleted file mode 100644
index 9cc677e5..00000000
--- a/src/pinentry/pinentrydialog.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/* pinentrydialog.h - A (not yet) secure Qt 4 dialog for PIN entry.
- * Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
- * Copyright 2007 Ingo Klöcker
- * Copyright 2016 Intevation GmbH
- * Copyright (C) 2021, 2022 g10 Code GmbH
- *
- * Written by Steffen Hansen <[email protected]>.
- * Modified by Andre Heinecke <[email protected]>
- * 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 __PINENTRYDIALOG_H__
-#define __PINENTRYDIALOG_H__
-
-#include <QAccessible>
-#include <QDialog>
-#include <QStyle>
-#include <QTimer>
-
-#include "core/function/SecureMemoryAllocator.h"
-#include "pinentry.h"
-
-class QIcon;
-class QLabel;
-class QPushButton;
-class QLineEdit;
-class PinLineEdit;
-class QString;
-class QProgressBar;
-class QCheckBox;
-class QAction;
-
-QPixmap applicationIconPixmap(const QIcon &overlayIcon = {});
-
-void raiseWindow(QWidget *w);
-
-class PinEntryDialog : public QDialog {
- Q_OBJECT
-
- Q_PROPERTY(QString description READ description WRITE setDescription)
- Q_PROPERTY(QString error READ error WRITE setError)
- Q_PROPERTY(QString pin READ pin WRITE setPin)
- Q_PROPERTY(QString prompt READ prompt WRITE setPrompt)
- public:
- struct FormattedPassphraseOptions {
- bool formatPassphrase;
- QString hint;
- };
- struct ConstraintsOptions {
- bool enforce;
- QString shortHint;
- QString longHint;
- QString errorTitle;
- };
-
- explicit PinEntryDialog(QWidget *parent = 0, const char *name = 0,
- int timeout = 0, bool modal = false,
- bool enable_quality_bar = false,
- const QString &repeatString = QString(),
- const QString &visibiltyTT = QString(),
- const QString &hideTT = QString());
-
- void setDescription(const QString &);
- QString description() const;
-
- void setError(const QString &);
- QString error() const;
-
- void setPin(const QString &);
- QString pin() const;
-
- QString repeatedPin() const;
- void setRepeatErrorText(const QString &);
-
- void setPrompt(const QString &);
- QString prompt() const;
-
- void setOkText(const QString &);
- void setCancelText(const QString &);
-
- void setQualityBar(const QString &);
- void setQualityBarTT(const QString &);
-
- void setGenpinLabel(const QString &);
- void setGenpinTT(const QString &);
-
- void setCapsLockHint(const QString &);
-
- void setFormattedPassphrase(const FormattedPassphraseOptions &options);
-
- void setConstraintsOptions(const ConstraintsOptions &options);
-
- void setPinentryInfo(struct pinentry);
-
- bool timedOut() const;
-
- protected Q_SLOTS:
- void updateQuality(const QString &);
- void slotTimeout();
- void textChanged(const QString &);
- void focusChanged(QWidget *old, QWidget *now);
- void toggleVisibility();
- void onBackspace();
- void generatePin();
- void toggleFormattedPassphrase();
-
- protected:
- void keyPressEvent(QKeyEvent *event) override;
- void keyReleaseEvent(QKeyEvent *event) override;
- void showEvent(QShowEvent *event) override;
-
- private Q_SLOTS:
- void cancelTimeout();
- void checkCapsLock();
- void onAccept();
-
- private:
- enum PassphraseCheckResult {
- PassphraseNotChecked = -1,
- PassphraseNotOk = 0,
- PassphraseOk
- };
-
- QLabel *_icon = nullptr;
- QLabel *_desc = nullptr;
- QLabel *_error = nullptr;
- QLabel *_prompt = nullptr;
- QLabel *_quality_bar_label = nullptr;
- QProgressBar *_quality_bar = nullptr;
- PinLineEdit *_edit = nullptr;
- PinLineEdit *mRepeat = nullptr;
- QLabel *mRepeatError = nullptr;
- QPushButton *_ok = nullptr;
- QPushButton *_cancel = nullptr;
- bool _grabbed = false;
- bool _have_quality_bar = false;
- bool _timed_out = false;
- bool _disable_echo_allowed = true;
- bool mEnforceConstraints = false;
- bool mFormatPassphrase = false;
-
- GpgFrontend::SecureUniquePtr<struct pinentry> _pinentry_info = nullptr;
- QTimer *_timer = nullptr;
- QString mVisibilityTT;
- QString mHideTT;
- QAction *mVisiActionEdit = nullptr;
- QPushButton *mGenerateButton = nullptr;
- QCheckBox *mVisiCB = nullptr;
- QLabel *mFormattedPassphraseHint = nullptr;
- QLabel *mFormattedPassphraseHintSpacer = nullptr;
- QLabel *mCapsLockHint = nullptr;
- QLabel *mConstraintsHint = nullptr;
- QString mConstraintsErrorTitle;
-};
-
-#endif // __PINENTRYDIALOG_H__
diff --git a/src/pinentry/pinlineedit.cpp b/src/pinentry/pinlineedit.cpp
deleted file mode 100644
index 9d172b56..00000000
--- a/src/pinentry/pinlineedit.cpp
+++ /dev/null
@@ -1,204 +0,0 @@
-/* pinlineedit.cpp - Modified QLineEdit widget.
- * Copyright (C) 2018 Damien Goutte-Gattat
- * Copyright (C) 2021 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 "pinlineedit.h"
-
-#include <QClipboard>
-#include <QGuiApplication>
-#include <QKeyEvent>
-
-static const int FormattedPassphraseGroupSize = 5;
-static const QChar FormattedPassphraseSeparator = QChar::Nbsp;
-
-namespace {
-struct Selection {
- bool empty() const { return start < 0 || start >= end; }
- int length() const { return empty() ? 0 : end - start; }
-
- int start;
- int end;
-};
-} // namespace
-
-class PinLineEdit::Private {
- PinLineEdit *const q;
-
- public:
- Private(PinLineEdit *q) : q{q} {}
-
- QString formatted(QString text) const {
- const int dashCount = text.size() / FormattedPassphraseGroupSize;
- text.reserve(text.size() + dashCount);
- for (int i = FormattedPassphraseGroupSize; i < text.size();
- i += FormattedPassphraseGroupSize + 1) {
- text.insert(i, FormattedPassphraseSeparator);
- }
- return text;
- }
-
- Selection formattedSelection(Selection selection) const {
- if (selection.empty()) {
- return selection;
- }
- return {selection.start + selection.start / FormattedPassphraseGroupSize,
- selection.end + (selection.end - 1) / FormattedPassphraseGroupSize};
- }
-
- QString unformatted(QString text) const {
- for (int i = FormattedPassphraseGroupSize; i < text.size();
- i += FormattedPassphraseGroupSize) {
- text.remove(i, 1);
- }
- return text;
- }
-
- Selection unformattedSelection(Selection selection) const {
- if (selection.empty()) {
- return selection;
- }
- return {
- selection.start - selection.start / (FormattedPassphraseGroupSize + 1),
- selection.end - selection.end / (FormattedPassphraseGroupSize + 1)};
- }
-
- void copyToClipboard() {
- if (q->echoMode() != QLineEdit::Normal) {
- return;
- }
-
- QString text = q->selectedText();
- if (mFormattedPassphrase) {
- text.remove(FormattedPassphraseSeparator);
- }
- if (!text.isEmpty()) {
- QGuiApplication::clipboard()->setText(text);
- }
- }
-
- int selectionEnd() {
-#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
- return q->selectionEnd();
-#else
- return q->selectionStart() + q->selectedText().size();
-#endif
- }
-
- public:
- bool mFormattedPassphrase = false;
-};
-
-PinLineEdit::PinLineEdit(QWidget *parent)
- : QLineEdit(parent), d{new Private{this}} {
- connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdited()));
-}
-
-PinLineEdit::~PinLineEdit() = default;
-
-void PinLineEdit::setFormattedPassphrase(bool on) {
- if (on == d->mFormattedPassphrase) {
- return;
- }
- d->mFormattedPassphrase = on;
- Selection selection{selectionStart(), d->selectionEnd()};
- if (d->mFormattedPassphrase) {
- setText(d->formatted(text()));
- selection = d->formattedSelection(selection);
- } else {
- setText(d->unformatted(text()));
- selection = d->unformattedSelection(selection);
- }
- if (!selection.empty()) {
- setSelection(selection.start, selection.length());
- }
-}
-
-void PinLineEdit::copy() const { d->copyToClipboard(); }
-
-void PinLineEdit::cut() {
- if (hasSelectedText()) {
- copy();
- del();
- }
-}
-
-void PinLineEdit::setPin(const QString &pin) {
- setText(d->mFormattedPassphrase ? d->formatted(pin) : pin);
-}
-
-QString PinLineEdit::pin() const {
- if (d->mFormattedPassphrase) {
- return d->unformatted(text());
- } else {
- return text();
- }
-}
-
-void PinLineEdit::keyPressEvent(QKeyEvent *e) {
- if (e == QKeySequence::Copy) {
- copy();
- return;
- } else if (e == QKeySequence::Cut) {
- if (!isReadOnly() && hasSelectedText()) {
- copy();
- del();
- }
- return;
- } else if (e == QKeySequence::DeleteEndOfLine) {
- if (!isReadOnly()) {
- setSelection(cursorPosition(), text().size());
- copy();
- del();
- }
- return;
- } else if (e == QKeySequence::DeleteCompleteLine) {
- if (!isReadOnly()) {
- setSelection(0, text().size());
- copy();
- del();
- }
- return;
- }
-
- QLineEdit::keyPressEvent(e);
-
- if (e->key() == Qt::Key::Key_Backspace) {
- emit backspacePressed();
- }
-}
-
-void PinLineEdit::textEdited() {
- if (!d->mFormattedPassphrase) {
- return;
- }
- auto currentText = text();
- // first calculate the cursor position in the reformatted text; the cursor
- // is put left of the separators, so that backspace works as expected
- auto cursorPos = cursorPosition();
- cursorPos -= QStringView{currentText}.left(cursorPos).count(
- FormattedPassphraseSeparator);
- cursorPos += std::max(cursorPos - 1, 0) / FormattedPassphraseGroupSize;
- // then reformat the text
- currentText.remove(FormattedPassphraseSeparator);
- currentText = d->formatted(currentText);
- // finally, set reformatted text and updated cursor position
- setText(currentText);
- setCursorPosition(cursorPos);
-}
diff --git a/src/pinentry/pinlineedit.h b/src/pinentry/pinlineedit.h
deleted file mode 100644
index 72ac85a5..00000000
--- a/src/pinentry/pinlineedit.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* pinlineedit.h - Modified QLineEdit widget.
- * Copyright (C) 2018 Damien Goutte-Gattat
- * Copyright (C) 2021 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 _PINLINEEDIT_H_
-#define _PINLINEEDIT_H_
-
-#include <QLineEdit>
-
-class PinLineEdit : public QLineEdit {
- Q_OBJECT
-
- public:
- explicit PinLineEdit(QWidget *parent = nullptr);
- ~PinLineEdit() override;
-
- void setPin(const QString &pin);
- QString pin() const;
-
- public Q_SLOTS:
- void setFormattedPassphrase(bool on);
- void copy() const;
- void cut();
-
- Q_SIGNALS:
- void backspacePressed();
-
- protected:
- void keyPressEvent(QKeyEvent *) override;
-
- private:
- using QLineEdit::setText;
- using QLineEdit::text;
-
- private Q_SLOTS:
- void textEdited();
-
- private:
- class Private;
- std::unique_ptr<Private> d;
-};
-
-#endif // _PINLINEEDIT_H_
diff --git a/src/pinentry/qti18n.cpp b/src/pinentry/qti18n.cpp
deleted file mode 100644
index 198e6cc4..00000000
--- a/src/pinentry/qti18n.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/* qti18n.cpp - Load qt translations for pinentry.
- * Copyright 2021 g10 Code GmbH
- * SPDX-FileCopyrightText: 2015 Lukáš Tinkl <[email protected]>
- * SPDX-FileCopyrightText: 2021 Ingo Klöcker <[email protected]>
- *
- * Copied from k18n under the terms of LGPLv2 or later.
- *
- * 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 <QCoreApplication>
-#include <QDebug>
-#include <QLibraryInfo>
-#include <QLocale>
-#include <QTranslator>
-
-static bool loadCatalog(const QString &catalog, const QLocale &locale) {
- auto translator = new QTranslator(QCoreApplication::instance());
-
- if (!translator->load(locale, catalog, QString(),
- QLatin1String(":/i18n_qt"))) {
- qDebug() << "Loading the" << catalog << "catalog failed for locale"
- << locale;
- delete translator;
- return false;
- }
- QCoreApplication::instance()->installTranslator(translator);
- return true;
-}
-
-static bool loadCatalog(const QString &catalog, const QLocale &locale,
- const QLocale &fallbackLocale) {
- // try to load the catalog for locale
- if (loadCatalog(catalog, locale)) {
- return true;
- }
- // if this fails, then try the fallback locale (if it's different from locale)
- if (fallbackLocale != locale) {
- return loadCatalog(catalog, fallbackLocale);
- }
- return false;
-}
-
-// load global Qt translation, needed in KDE e.g. by lots of builtin dialogs
-// (QColorDialog, QFontDialog) that we use
-static void loadTranslation(const QString &localeName,
- const QString &fallbackLocaleName) {
- const QLocale locale{localeName};
- const QLocale fallbackLocale{fallbackLocaleName};
- // first, try to load the qt_ meta catalog
- if (loadCatalog(QStringLiteral("qt_"), locale, fallbackLocale)) {
- return;
- }
- // if loading the meta catalog failed, then try loading the four catalogs
- // it depends on, i.e. qtbase, qtscript, qtmultimedia, qtxmlpatterns,
- // separately
- const auto catalogs = {
- QStringLiteral("qtbase_"),
- /* QStringLiteral("qtscript_"),
- QStringLiteral("qtmultimedia_"),
- QStringLiteral("qtxmlpatterns_"), */
- };
- for (const auto &catalog : catalogs) {
- loadCatalog(catalog, locale, fallbackLocale);
- }
-}
-
-static void load() {
- // The way Qt translation system handles plural forms makes it necessary to
- // have a translation file which contains only plural forms for `en`. That's
- // why we load the `en` translation unconditionally, then load the
- // translation for the current locale to overload it.
- loadCatalog(QStringLiteral("qt_"), QLocale{QStringLiteral("en")});
-
- const QLocale locale = QLocale::system();
- if (locale.name() != QStringLiteral("en")) {
- loadTranslation(locale.name(), locale.bcp47Name());
- }
-}
-
-Q_COREAPP_STARTUP_FUNCTION(load)
diff --git a/src/pinentry/secmem++.h b/src/pinentry/secmem++.h
deleted file mode 100644
index 116da880..00000000
--- a/src/pinentry/secmem++.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/* STL allocator for secmem
- * Copyright (C) 2008 Marc Mutz <[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 __SECMEM_SECMEMPP_H__
-#define __SECMEM_SECMEMPP_H__
-
-#include "../secmem/secmem.h"
-#include <cstddef>
-
-namespace secmem {
-
- template <typename T>
- class alloc {
- public:
- // type definitions:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef T* pointer;
- typedef const T* const_pointer;
- typedef T& reference;
- typedef const T& const_reference;
- typedef T value_type;
-
- // rebind
- template <typename U>
- struct rebind {
- typedef alloc<U> other;
- };
-
- // address
- pointer address( reference value ) const {
- return &value;
- }
- const_pointer address( const_reference value ) const {
- return &value;
- }
-
- // (trivial) ctors and dtors
- alloc() {}
- alloc( const alloc & ) {}
- template <typename U> alloc( const alloc<U> & ) {}
- // copy ctor is ok
- ~alloc() {}
-
- // de/allocation
- size_type max_size() const {
- return secmem_get_max_size();
- }
-
- pointer allocate( size_type n, void * =0 ) {
- return static_cast<pointer>( secmem_malloc( n * sizeof(T) ) );
- }
-
- void deallocate( pointer p, size_type ) {
- secmem_free( p );
- }
-
- // de/construct
- void construct( pointer p, const T & value ) {
- void * loc = p;
- new (loc)T(value);
- }
- void destruct( pointer p ) {
- p->~T();
- }
- };
-
- // equality comparison
- template <typename T1,typename T2>
- bool operator==( const alloc<T1> &, const alloc<T2> & ) { return true; }
- template <typename T1, typename T2>
- bool operator!=( const alloc<T1> &, const alloc<T2> & ) { return false; }
-
-}
-
-#endif /* __SECMEM_SECMEMPP_H__ */
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index bb201390..0363f3bd 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -67,9 +67,6 @@ endif()
# link gpgfrontend_core
target_link_libraries(gpgfrontend_ui gpgfrontend_core)
-# link buddled pinentry
-target_link_libraries(gpgfrontend_ui gpgfrontend_pinentry)
-
# set up pch
target_precompile_headers(gpgfrontend_ui PUBLIC GpgFrontendUI.h)
diff --git a/src/ui/dialog/controller/ModuleControllerDialog.cpp b/src/ui/dialog/controller/ModuleControllerDialog.cpp
index 6c0e6d0a..8f1df81c 100644
--- a/src/ui/dialog/controller/ModuleControllerDialog.cpp
+++ b/src/ui/dialog/controller/ModuleControllerDialog.cpp
@@ -93,6 +93,10 @@ ModuleControllerDialog::ModuleControllerDialog(QWidget* parent)
Module::TriggerEvent(event_id);
});
+ connect(ui_->pushButton_4, &QPushButton::clicked, this, []() {
+
+ });
+
connect(ui_->showModsDirButton, &QPushButton::clicked, this, [=]() {
QDesktopServices::openUrl(QUrl::fromLocalFile(
GlobalSettingStation::GetInstance().GetModulesDir()));
diff --git a/src/ui/function/RaisePinentry.cpp b/src/ui/function/RaisePinentry.cpp
deleted file mode 100644
index b119c5f8..00000000
--- a/src/ui/function/RaisePinentry.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * 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()) {
- return widget;
- }
- }
- return fallback;
-}
-
-RaisePinentry::RaisePinentry(QWidget* parent,
- QSharedPointer<GpgPassphraseContext> context)
- : QWidget(parent), context_(std::move(context)) {}
-
-auto RaisePinentry::Exec() -> int {
- 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 Passphrase:") : QString(),
- tr("Show passphrase"), tr("Hide passphrase"));
-
- if (context_->IsPreWasBad()) {
- pinentry->setError(tr("Given Passphrase was wrong. Please retry."));
- }
-
- pinentry->setPrompt(tr("Passphrase:"));
-
- if (!context_->GetUidsInfo().isEmpty()) {
- pinentry->setDescription(QString("Please provide Passphrase 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("Bundled Pinentry"));
-
- /* If we reuse the same dialog window. */
- pinentry->setPin(QString());
- pinentry->setOkText(tr("Confirm"));
- pinentry->setCancelText(tr("Cancel"));
-
- connect(pinentry, &PinEntryDialog::finished, this,
- [pinentry, this](int result) {
- bool ret = result != 0;
-
- 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
deleted file mode 100644
index 40175dfd..00000000
--- a/src/ui/function/RaisePinentry.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * 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/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index 1e795325..1b9329c7 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -45,10 +45,6 @@ namespace GpgFrontend::UI {
MainWindow::MainWindow() : GeneralMainWindow("main_window") {
this->setMinimumSize(1200, 700);
this->setWindowTitle(qApp->applicationName());
-
- connect(CoreSignalStation::GetInstance(),
- &CoreSignalStation::SignalNeedUserInputPassphrase, this,
- &MainWindow::SlotRaisePinentry);
}
void MainWindow::Init() noexcept {
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index f53a4a03..b253a667 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -233,11 +233,6 @@ class MainWindow : public GeneralMainWindow {
*/
void SlotSetRestartNeeded(int);
- /**
- * @details Open a new tab for path
- */
- void SlotRaisePinentry(QSharedPointer<GpgPassphraseContext>);
-
private slots:
/**
diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp
index d2b39ee7..809a4af9 100644
--- a/src/ui/main_window/MainWindowSlotUI.cpp
+++ b/src/ui/main_window/MainWindowSlotUI.cpp
@@ -33,7 +33,6 @@
#include "core/model/SettingsObject.h"
#include "ui/UserInterfaceUtils.h"
#include "ui/dialog/Wizard.h"
-#include "ui/function/RaisePinentry.h"
#include "ui/main_window/KeyMgmt.h"
#include "ui/struct/settings_object/AppearanceSO.h"
#include "ui/widgets/TextEdit.h"
@@ -212,10 +211,4 @@ void MainWindow::SlotUpdateCryptoMenuStatus(unsigned int type) {
}
}
-void MainWindow::SlotRaisePinentry(
- QSharedPointer<GpgPassphraseContext> context) {
- auto* function = new RaisePinentry(this, context);
- function->Exec();
-}
-
} // namespace GpgFrontend::UI