Subject: Tramp reuses bad ssh passphrase several times without asking

From: Stephane Chauveau <[email-masked]>
Date: Thu, 13 Nov 2014 19:29:52 +0100

When connecting via scp with both Password and PublicKey authentication,
the default behavior of OpenSSH is to ask for the public key passphrase
3 times and then for the password 3 times (so a total of 6 queries).
That behavior can be observed in previous versions of emacs (e.g. 24.3.1).

Remark: in the following it is important to understand the difference
between the passphrase and the password.

In 24.4.1 there seems to be a bug in the way bad passphrases are
handled: A bad passphrase is retried several times without asking the
user for a new one. So when providing a bad passphrase xxxxxxxxx, the
behavior in the minibuffer is now:

 Passphrase for /scp:hobb:  xxxxxxxxx
 Tramp sending password
 Password for /scp:hobb: yyyyyyyy
 Password for /scp:hobb: zzzzzzzz
 Tramp failed to connect.  If this happens repeatedly, try
    `M-x tramp-cleanup-this-connection'

The message window shows that 3 passphrases and 3 password were actually
tested:

 Tramp: Waiting for prompts from remote shell...
 Tramp: Sending passphrase [3 times]
 Tramp: Sending password [3 times]

My analysis is that there is a bug that prevents bad passphrase to be
queried again (a problem with the password cache?). The reason why the
password is only asked twice is because the xxxxxxxxx from my example is
probably send 3 times as a passphrase and 1 time as a password after
which the second password query occurs. This can be verified by
providing the password for xxxxxxxxx instead of the passphrase.

In GNU Emacs 24.4.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.23)
 of 2014-11-13 on simak
Windowing system distributor `The X.Org Foundation', version 11.0.11501000
System Description:	Linux Mint 17 Qiana

Configured using:
 `configure --prefix=/home/chauveau/Downloads/emacs-24.4-usr
 --with-gif=no'

Important settings:
  value of $LC_MONETARY: fr_FR.UTF-8
  value of $LC_NUMERIC: fr_FR.UTF-8
  value of $LC_TIME: fr_FR.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  shell-dirtrack-mode: t
  recentf-mode: t
  iswitchb-mode: t
  show-paren-mode: t
  display-time-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<escape> x r e p o r t <tab> <return>

Recent messages:
`epa-file' already enabled
Loading /home/chauveau/.recentf...done
Cleaning up the recentf list...done (0 removed)
For information about GNU Emacs and the GNU system, type C-h C-a.
Package iswitchb is obsolete!

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rfc822 mml mml-sec mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mail-utils edmacro kmacro
tramp-cache tramp-sh tramp tramp-compat auth-source eieio byte-opt
bytecomp byte-compile cconv eieio-core gnus-util mm-util mail-prsvr
password-cache tramp-loaddefs trampver shell pcomplete comint ansi-color
ring format-spec advice help-fns recentf tree-widget wid-edit
cl-loaddefs cl-lib easymenu iswitchb paren time epa-file epa derived epg
epg-config time-date tooltip electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
gfilenotify dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 107916 8301)
 (symbols 48 21970 0)
 (miscs 40 49 118)
 (strings 32 23583 4937)
 (string-bytes 1 721430)
 (vectors 16 14674)
 (vector-slots 8 444686 4578)
 (floats 8 100 142)
 (intervals 56 214 0)
 (buffers 960 11)
 (heap 1024 41699 914))

In GNU Emacs 24.4.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.23)
 of 2014-11-13 on simak
Windowing system distributor `The X.Org Foundation', version 11.0.11501000
System Description:	Linux Mint 17 Qiana

Configured using:
 `configure --prefix=/home/chauveau/Downloads/emacs-24.4-usr
 --with-gif=no'

Important settings:
  value of $LC_MONETARY: fr_FR.UTF-8
  value of $LC_NUMERIC: fr_FR.UTF-8
  value of $LC_TIME: fr_FR.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  shell-dirtrack-mode: t
  recentf-mode: t
  iswitchb-mode: t
  show-paren-mode: t
  display-time-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<escape> x r e p o r t <tab> <return>

Recent messages:
`epa-file' already enabled
Loading /home/chauveau/.recentf...done
Cleaning up the recentf list...done (0 removed)
For information about GNU Emacs and the GNU system, type C-h C-a.
Package iswitchb is obsolete!

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rfc822 mml mml-sec mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mail-utils edmacro kmacro
tramp-cache tramp-sh tramp tramp-compat auth-source eieio byte-opt
bytecomp byte-compile cconv eieio-core gnus-util mm-util mail-prsvr
password-cache tramp-loaddefs trampver shell pcomplete comint ansi-color
ring format-spec advice help-fns recentf tree-widget wid-edit
cl-loaddefs cl-lib easymenu iswitchb paren time epa-file epa derived epg
epg-config time-date tooltip electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
gfilenotify dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 107916 8301)
 (symbols 48 21970 0)
 (miscs 40 49 118)
 (strings 32 23583 4937)
 (string-bytes 1 721430)
 (vectors 16 14674)
 (vector-slots 8 444686 4578)
 (floats 8 100 142)
 (intervals 56 214 0)
 (buffers 960 11)
 (heap 1024 41699 914))