[PATCH pinentry 0/4] Disallow echo disabling when prompting for a PIN.

Damien Goutte-Gattat dgouttegattat at incenp.org
Tue Aug 21 21:31:53 CEST 2018


Hi Werner,

> So what about either
>
>  - not using this feature for a PIN
>  - making sure "[no echo]" is always disabled.

(I assume you meant "always displayed" or similar here.)

For the curses pinentry, "[no echo]" is always displayed when
echoing is disabled.

There's no easy way to achieve the same thing with the Gtk/Qt/TQt
pinentries though, so for them I am in favor of the first solution.
It's implemented with the patch below, which uses the presence of
"PIN" in the prompt text to distinguish between a PIN prompt and a
passphrase prompt (same logic already used in gpg-agent).

-- >8 --
Subject: [PATCH pinentry] Disallow echo disabling when prompting for a PIN.

* gtk+-2/pinentry-gtk-2.c (create_window): Do not setup
the backspace handler when prompting for a PIN.
callback only when not prompting for a PIN.
* qt/pinentrydialog.h (_got_input): Rename field to
_disable_echo_allowed.
* qt/pinentrydialog.cpp (PinEntryDialog::setPrompt): Disallow
echo disabling when prompting for a PIN.
* tqt/pinentrydialog.h (_got_input): Rename field to
_disable_echo_allowed.
* tqt/pinentrydialog.cpp (PinEntryDialog::setPrompt): Disallow
echo disabling when prompting for a PIN.

Signed-off-by: Damien Goutte-Gattat <dgouttegattat at incenp.org>
---
 gtk+-2/pinentry-gtk-2.c | 10 ++++++++--
 qt/pinentrydialog.cpp   |  8 +++++---
 qt/pinentrydialog.h     |  2 +-
 tqt/pinentrydialog.cpp  |  8 +++++---
 tqt/pinentrydialog.h    |  2 +-
 5 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/gtk+-2/pinentry-gtk-2.c b/gtk+-2/pinentry-gtk-2.c
index 1e07fdc..a4522e4 100644
--- a/gtk+-2/pinentry-gtk-2.c
+++ b/gtk+-2/pinentry-gtk-2.c
@@ -729,8 +729,14 @@ create_window (pinentry_t ctx)
       gtk_widget_set_size_request (entry, 200, -1);
       g_signal_connect (G_OBJECT (entry), "changed",
                         G_CALLBACK (changed_text_handler), entry);
-      g_signal_connect (G_OBJECT (entry), "backspace",
-                        G_CALLBACK (backspace_handler), entry);
+
+      /* Enable disabling echo if we're not asking for a PIN. */
+      if (pinentry->prompt && !strstr (pinentry->prompt, "PIN"))
+	{
+	  g_signal_connect (G_OBJECT (entry), "backspace",
+			    G_CALLBACK (backspace_handler), entry);
+	}
+
       hbox = gtk_hbox_new (FALSE, HIG_TINY);
       gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
       /* There was a wish in issue #2139 that this button should not
diff --git a/qt/pinentrydialog.cpp b/qt/pinentrydialog.cpp
index b7f2e53..a58e636 100644
--- a/qt/pinentrydialog.cpp
+++ b/qt/pinentrydialog.cpp
@@ -138,7 +138,7 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name,
     : QDialog(parent),
       mRepeat(NULL),
       _grabbed(false),
-      _got_input(false),
+      _disable_echo_allowed(true),
       mVisibilityTT(visibilityTT),
       mHideTT(hideTT),
       mVisiActionEdit(NULL),
@@ -318,6 +318,8 @@ 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
@@ -362,7 +364,7 @@ void PinEntryDialog::setQualityBarTT(const QString &txt)
 
 void PinEntryDialog::onBackspace()
 {
-    if (!_got_input) {
+    if (_disable_echo_allowed) {
         _edit->setEchoMode(QLineEdit::NoEcho);
         if (mRepeat) {
             mRepeat->setEchoMode(QLineEdit::NoEcho);
@@ -380,7 +382,7 @@ void PinEntryDialog::updateQuality(const QString &txt)
         _timer->stop();
     }
 
-    _got_input = true;
+    _disable_echo_allowed = false;
 
     if (!_have_quality_bar || !_pinentry_info) {
         return;
diff --git a/qt/pinentrydialog.h b/qt/pinentrydialog.h
index 396f03b..d5e6963 100644
--- a/qt/pinentrydialog.h
+++ b/qt/pinentrydialog.h
@@ -109,7 +109,7 @@ private:
     bool       _grabbed;
     bool       _have_quality_bar;
     bool       _timed_out;
-    bool       _got_input;
+    bool       _disable_echo_allowed;
     pinentry_t _pinentry_info;
     QTimer    *_timer;
     QString    mRepeatError,
diff --git a/tqt/pinentrydialog.cpp b/tqt/pinentrydialog.cpp
index 6a2ae12..b7aa309 100644
--- a/tqt/pinentrydialog.cpp
+++ b/tqt/pinentrydialog.cpp
@@ -33,7 +33,7 @@
 PinEntryDialog::PinEntryDialog( TQWidget* parent, const char* name,
                                 bool modal, bool enable_quality_bar )
   : TQDialog( parent, name, modal, TQt::WStyle_StaysOnTop ), _grabbed( false ),
-    _got_input( false )
+    _disable_echo_allowed ( true )
 {
   TQBoxLayout* top = new TQVBoxLayout( this, 6 );
   TQBoxLayout* upperLayout = new TQHBoxLayout( top );
@@ -134,7 +134,7 @@ void PinEntryDialog::updateQuality( const SecTQString & txt )
   int percent;
   TQPalette pal;
 
-  _got_input = true;
+  _disable_echo_allowed = false;
 
   if (!_have_quality_bar || !_pinentry_info)
     return;
@@ -166,7 +166,7 @@ void PinEntryDialog::updateQuality( const SecTQString & txt )
 
 void PinEntryDialog::onBackspace()
 {
-  if (!_got_input)
+  if (_disable_echo_allowed)
     _edit->setEchoMode( SecTQLineEdit::NoEcho );
 }
 
@@ -208,6 +208,8 @@ SecTQString PinEntryDialog::text() const
 void PinEntryDialog::setPrompt( const TQString& txt )
 {
   _prompt->setText( txt );
+  if (txt.contains("PIN"))
+    _disable_echo_allowed = false;
 }
 
 TQString PinEntryDialog::prompt() const
diff --git a/tqt/pinentrydialog.h b/tqt/pinentrydialog.h
index eb4d332..8ec3fd5 100644
--- a/tqt/pinentrydialog.h
+++ b/tqt/pinentrydialog.h
@@ -87,7 +87,7 @@ private:
   bool       _grabbed;
   bool       _have_quality_bar;
   pinentry_t _pinentry_info;
-  bool       _got_input;
+  bool       _disable_echo_allowed;
 };
 
 
-- 
2.14.4




More information about the Gnupg-devel mailing list