[systemd-devel] crypto: to show stars or not to show them

Jan Engelhardt jengelh at medozas.de
Mon Mar 28 15:10:16 PDT 2011


On Monday 2011-03-28 23:29, Lennart Poettering wrote:

>On Sun, 27.03.11 23:52, Jan Engelhardt (jengelh at medozas.de) wrote:
>
>> 
>> On Friday 2011-03-18 01:41, Lennart Poettering wrote:
>> 
>> >On Fri, 18.03.11 00:18, Jan Engelhardt (jengelh at medozas.de) wrote:
>> >
>> >> Meanwhile, I have two new suggestions.
>> >
>> >I have one too (or actually Kay came up with it), and I think you are
>> >going to like it:
>> >
>> >Start with showing input feedback as we currently do. If the user then
>> >presses TAB the stars disappear, and instead we show "(no echo)" or
>> >so. Then, the user can proceed with typing his password without
>> >asterisks.
>> >[...]
>> 
>> Incorporating Graham's suggestion to use BKSP instead:
>
>Hmm?
>
>Backspace? Why backspace?

Quoting Graham:

"On a slightly different note; Would it be possible to watch for 
unprintable keys? For example, what about a single backspace/delete at 
the start of the prompt, before you've entered anything? I'm used to tab 
making things appear, not making things disappear. On the other hand, 
I'm used to backspace/delete making things disappear; so it feels more 
logical to me."

>I am not sure I like the idea and neither does
>Kay who I discussed this with earlier today. If people mistype their
>passwords, they tend to backspace them away again, and start anew. I am
>pretty sure if they do that they'd be quite surprised if the password is
>hidden completely even when they try to retype it afterwards.

It was intended that once you typed something, going BKSP and getting a 
quiet prompt should not be possible anymore. I fixed that bug now; New 
patch is at git://dev.medozas.de/systemd now. (Also below)


>I think it would be a bad idea to overload an existing key with a well
>defined meaning with a different meaning,

\b is better because you can't take anything away at the start of 
prompt. \t instead creates and so is not easily distinguishable from the 
actual phrase.

>based on where the cursor
>is. To keep things simple we should pick a currently unused key, which
>TAB is. TAB in most UIs is used to switch between different UI
>elements. I think this translates relatively well to the different
>display modes in this context.
>
>I have commited your patch nonetheless, but then replaced Backspace by
>TAB in a subsequent patch. Would be cool if you could check if the
>version in git still does what you need.

Uh.
*rediffs patch*
*upload to git*


parent 2d87855ae873aa3a4816c8e3a37e5ec06cc65c5e (v20-113-g2d87855)
commit 2e6d9fe9b5397afb856f0a993fb76a0d9a1d1977
Author: Jan Engelhardt <jengelh at medozas.de>
Date:   Fri Mar 18 00:18:50 2011 +0100

ask-password: use backspace for silent prompt

Previous ask-password patch was somewhat flakey, but was applied
nevertheless in a hurry.

Activating noecho mode was only meant to be possible with the very
first key.

Restore use of bksp.

References: http://lists.freedesktop.org/archives/systemd-devel/2011-March/001694.html
---
 src/ask-password-api.c |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/ask-password-api.c b/src/ask-password-api.c
index cb05590..9e98bbf 100644
--- a/src/ask-password-api.c
+++ b/src/ask-password-api.c
@@ -60,7 +60,7 @@ int ask_password_tty(
         int r, ttyfd = -1, notify = -1;
         struct pollfd pollfd[2];
         bool reset_tty = false;
-        bool silent_mode = false;
+        int silent_mode = 0;
         enum {
                 POLL_TTY,
                 POLL_INOTIFY
@@ -170,32 +170,33 @@ int ask_password_tty(
                         break;
                 else if (c == 21) { /* C-u */
 
-                        if (!silent_mode)
+                        if (silent_mode <= 0)
                                 backspace_chars(ttyfd, p);
                         p = 0;
 
                 } else if (c == '\b' || c == 127) {
+                        if (p == 0 && silent_mode == 0) {
+                                silent_mode = 1;
+                                loop_write(ttyfd, "(no echo) ", 10, false);
+                        } else if (p > 0) {
 
-                        if (p > 0) {
-
-                                if (!silent_mode)
+                                if (silent_mode <= 0)
                                         backspace_chars(ttyfd, 1);
 
                                 p--;
                         } else if (ttyfd >= 0)
                                 loop_write(ttyfd, "\a", 1, false);
 
-                } else if (c == '\t' && !silent_mode) {
-
-                        backspace_chars(ttyfd, p);
-                        silent_mode = true;
-
-                        if (ttyfd >= 0)
-                                loop_write(ttyfd, "(no echo) ", 10, false);
                 } else {
+                        if (silent_mode == 0)
+                                /*
+                                 * If anything was entered, disable going
+                                 * silent later on.
+                                 */
+                                silent_mode = -1;
                         passphrase[p++] = c;
 
-                        if (!silent_mode && ttyfd >= 0)
+                        if (silent_mode <= 0 && ttyfd >= 0)
                                 loop_write(ttyfd, "*", 1, false);
                 }
         }
-- 
# Created with git-export-patch


More information about the systemd-devel mailing list