emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 f1e7b5230ad: Tramp: Handle PIN requests from security keys (don


From: Michael Albinus
Subject: emacs-29 f1e7b5230ad: Tramp: Handle PIN requests from security keys (don't merge)
Date: Fri, 9 Feb 2024 05:05:29 -0500 (EST)

branch: emacs-29
commit f1e7b5230ad93aab20af1fd7b09931a746a89d5d
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Tramp: Handle PIN requests from security keys (don't merge)
    
    * doc/misc/tramp.texi (Frequently Asked Questions): Clarify FIDO entry.
    
    * lisp/net/tramp-sh.el (tramp-actions-before-shell)
    (tramp-actions-copy-out-of-band):
    Use `tramp-security-key-pin-regexp'.
    
    * lisp/net/tramp.el (tramp-security-key-pin-regexp): New defcustom.
    (tramp-action-otp-password, tramp-read-passwd): Trim password prompt.
    (tramp-action-show-and-confirm-message): Expand for PIN requests.
---
 doc/misc/tramp.texi  | 11 ++++++++---
 lisp/net/tramp-sh.el |  2 ++
 lisp/net/tramp.el    | 33 ++++++++++++++++++++++-----------
 3 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 3be88d1767a..d6031d96d6b 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -5070,9 +5070,14 @@ Does @value{tramp} support @acronym{SSH} security keys?
 Yes.  @command{OpenSSH} has added support for @acronym{FIDO} hardware
 devices via special key types @option{*-sk}.  @value{tramp} supports
 the additional handshaking messages for them.  This requires at least
-@command{OpenSSH} 8.2, and a @acronym{FIDO} @acronym{U2F} compatible
-security key, like yubikey, solokey, nitrokey, or titankey.
-
+@command{OpenSSH} 8.2, and a @acronym{FIDO} @acronym{U2F} or
+@acronym{FIDO2} compatible security key, like yubikey, solokey,
+nitrokey, or titankey.
+@c @uref{https://docs.fedoraproject.org/en-US/quick-docs/using-yubikeys/}
+
+@strong{Note} that there are reports on problems of handling yubikey
+residential keys by @command{ssh-agent}.  As workaround, you might
+disable @command{ssh-agent} for such keys.
 
 @item
 @value{tramp} does not connect to Samba or MS Windows hosts running
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 44c0bdc7aea..3e6fb384a8f 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -544,6 +544,7 @@ shell from reading its init file."
     (tramp-terminal-prompt-regexp tramp-action-terminal)
     (tramp-antispoof-regexp tramp-action-confirm-message)
     (tramp-security-key-confirm-regexp tramp-action-show-and-confirm-message)
+    (tramp-security-key-pin-regexp tramp-action-otp-password)
     (tramp-process-alive-regexp tramp-action-process-alive))
   "List of pattern/action pairs.
 Whenever a pattern matches, the corresponding action is performed.
@@ -563,6 +564,7 @@ corresponding PATTERN matches, the ACTION function is 
called.")
     (tramp-wrong-passwd-regexp tramp-action-permission-denied)
     (tramp-copy-failed-regexp tramp-action-permission-denied)
     (tramp-security-key-confirm-regexp tramp-action-show-and-confirm-message)
+    (tramp-security-key-pin-regexp tramp-action-otp-password)
     (tramp-process-alive-regexp tramp-action-out-of-band))
   "List of pattern/action pairs.
 This list is used for copying/renaming with out-of-band methods.
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index bd556753261..f3da56e7a4f 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -224,7 +224,7 @@ pair of the form (KEY VALUE).  The following KEYs are 
defined:
     set this to any value other than \"/bin/sh\": Tramp wants to
     use a shell which groks tilde expansion, but it can search
     for it.  Also note that \"/bin/sh\" exists on all Unixen
-    except Andtoid, this might not be true for the value that you
+    except Android, this might not be true for the value that you
     decide to use.  You Have Been Warned.
 
   * `tramp-remote-shell-login'
@@ -788,6 +788,13 @@ The regexp should match at end of buffer."
   :version "28.1"
   :type 'regexp)
 
+(defcustom tramp-security-key-pin-regexp
+  (rx bol (* "\r") (group "Enter PIN for " (* nonl)) (* (any "\r\n")))
+  "Regular expression matching security key PIN prompt.
+The regexp should match at end of buffer."
+  :version "29.3"
+  :type 'regexp)
+
 (defcustom tramp-operation-not-permitted-regexp
   (rx (| (: "preserving times" (* nonl)) "set mode") ":" (* blank)
       "Operation not permitted")
@@ -5589,7 +5596,7 @@ of."
          prompt)
       (goto-char (point-min))
       (tramp-check-for-regexp proc tramp-process-action-regexp)
-      (setq prompt (concat (match-string 1) " "))
+      (setq prompt (concat (string-trim (match-string 1)) " "))
       (tramp-message vec 3 "Sending %s" (match-string 1))
       ;; We don't call `tramp-send-string' in order to hide the
       ;; password from the debug buffer and the traces.
@@ -5665,14 +5672,17 @@ Wait, until the connection buffer changes."
       (ignore set-message-function clear-message-function)
       (tramp-message vec 6 "\n%s" (buffer-string))
       (tramp-check-for-regexp proc tramp-process-action-regexp)
-      (with-temp-message
-         (replace-regexp-in-string (rx (any "\r\n")) "" (match-string 0))
+      (with-temp-message (concat (string-trim (match-string 0)) " ")
        ;; Hide message in buffer.
        (narrow-to-region (point-max) (point-max))
        ;; Wait for new output.
        (while (not (tramp-compat-ignore-error file-error
                      (tramp-wait-for-regexp
-                      proc 0.1 tramp-security-key-confirmed-regexp)))
+                      proc 0.1
+                      (tramp-compat-rx
+                       (| (regexp tramp-security-key-confirmed-regexp)
+                          (regexp tramp-security-key-pin-regexp)
+                          (regexp tramp-security-key-timeout-regexp))))))
          (when (tramp-check-for-regexp proc tramp-security-key-timeout-regexp)
            (throw 'tramp-action 'timeout))
          (redisplay 'force)))
@@ -6726,12 +6736,13 @@ Consults the auth-source package."
                   (tramp-get-connection-property key "login-as")))
         (host (tramp-file-name-host-port vec))
         (pw-prompt
-         (or prompt
-             (with-current-buffer (process-buffer proc)
-               (tramp-check-for-regexp proc tramp-password-prompt-regexp)
-               (if (string-match-p "passphrase" (match-string 1))
-                   (match-string 0)
-                 (format "%s for %s " (capitalize (match-string 1)) key)))))
+         (string-trim-left
+          (or prompt
+              (with-current-buffer (process-buffer proc)
+                (tramp-check-for-regexp proc tramp-password-prompt-regexp)
+                (if (string-match-p "passphrase" (match-string 1))
+                    (match-string 0)
+                  (format "%s for %s " (capitalize (match-string 1)) key))))))
         (auth-source-creation-prompts `((secret . ,pw-prompt)))
         ;; Use connection-local value.
         (auth-sources (buffer-local-value 'auth-sources (process-buffer proc)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]