aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2024-02-09 11:21:05 +0100
committerMichael Albinus2024-02-09 11:21:05 +0100
commit8d6a8e573f9a1e4eb9ebbc0ec244907263e61bb8 (patch)
treeb34dde37aba1575a39e0c56974edfcfeaf3c14ea
parent8d09e1def55e57a8c627ba704289f796c48a085d (diff)
downloademacs-8d6a8e573f9a1e4eb9ebbc0ec244907263e61bb8.tar.gz
emacs-8d6a8e573f9a1e4eb9ebbc0ec244907263e61bb8.zip
Tramp: Handle PIN requests from security keys
* 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.
-rw-r--r--doc/misc/tramp.texi11
-rw-r--r--lisp/net/tramp-sh.el2
-rw-r--r--lisp/net/tramp.el30
3 files changed, 30 insertions, 13 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 56945d3071c..90824024c03 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -5238,9 +5238,14 @@ Does @value{tramp} support @acronym{SSH} security keys?
5238Yes. @command{OpenSSH} has added support for @acronym{FIDO} hardware 5238Yes. @command{OpenSSH} has added support for @acronym{FIDO} hardware
5239devices via special key types @option{*-sk}. @value{tramp} supports 5239devices via special key types @option{*-sk}. @value{tramp} supports
5240the additional handshaking messages for them. This requires at least 5240the additional handshaking messages for them. This requires at least
5241@command{OpenSSH} 8.2, and a @acronym{FIDO} @acronym{U2F} compatible 5241@command{OpenSSH} 8.2, and a @acronym{FIDO} @acronym{U2F} or
5242security key, like yubikey, solokey, nitrokey, or titankey. 5242@acronym{FIDO2} compatible security key, like yubikey, solokey,
5243 5243nitrokey, or titankey.
5244@c @uref{https://docs.fedoraproject.org/en-US/quick-docs/using-yubikeys/}
5245
5246@strong{Note} that there are reports on problems of handling yubikey
5247residential keys by @command{ssh-agent}. As workaround, you might
5248disable @command{ssh-agent} for such keys.
5244 5249
5245@item 5250@item
5246@value{tramp} does not connect to Samba or MS Windows hosts running 5251@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 68ee541bee6..3557b3a1b64 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -547,6 +547,7 @@ shell from reading its init file."
547 (tramp-terminal-prompt-regexp tramp-action-terminal) 547 (tramp-terminal-prompt-regexp tramp-action-terminal)
548 (tramp-antispoof-regexp tramp-action-confirm-message) 548 (tramp-antispoof-regexp tramp-action-confirm-message)
549 (tramp-security-key-confirm-regexp tramp-action-show-and-confirm-message) 549 (tramp-security-key-confirm-regexp tramp-action-show-and-confirm-message)
550 (tramp-security-key-pin-regexp tramp-action-otp-password)
550 (tramp-process-alive-regexp tramp-action-process-alive)) 551 (tramp-process-alive-regexp tramp-action-process-alive))
551 "List of pattern/action pairs. 552 "List of pattern/action pairs.
552Whenever a pattern matches, the corresponding action is performed. 553Whenever a pattern matches, the corresponding action is performed.
@@ -566,6 +567,7 @@ corresponding PATTERN matches, the ACTION function is called.")
566 (tramp-wrong-passwd-regexp tramp-action-permission-denied) 567 (tramp-wrong-passwd-regexp tramp-action-permission-denied)
567 (tramp-copy-failed-regexp tramp-action-permission-denied) 568 (tramp-copy-failed-regexp tramp-action-permission-denied)
568 (tramp-security-key-confirm-regexp tramp-action-show-and-confirm-message) 569 (tramp-security-key-confirm-regexp tramp-action-show-and-confirm-message)
570 (tramp-security-key-pin-regexp tramp-action-otp-password)
569 (tramp-process-alive-regexp tramp-action-out-of-band)) 571 (tramp-process-alive-regexp tramp-action-out-of-band))
570 "List of pattern/action pairs. 572 "List of pattern/action pairs.
571This list is used for copying/renaming with out-of-band methods. 573This list is used for copying/renaming with out-of-band methods.
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 8e114912527..ae59915b1e8 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -770,6 +770,13 @@ The regexp should match at end of buffer."
770 :version "28.1" 770 :version "28.1"
771 :type 'regexp) 771 :type 'regexp)
772 772
773(defcustom tramp-security-key-pin-regexp
774 (rx bol (* "\r") (group "Enter PIN for " (* nonl)) (* (any "\r\n")))
775 "Regular expression matching security key PIN prompt.
776The regexp should match at end of buffer."
777 :version "29.3"
778 :type 'regexp)
779
773(defcustom tramp-operation-not-permitted-regexp 780(defcustom tramp-operation-not-permitted-regexp
774 (rx (| (: "preserving times" (* nonl)) "set mode") ":" (* blank) 781 (rx (| (: "preserving times" (* nonl)) "set mode") ":" (* blank)
775 "Operation not permitted") 782 "Operation not permitted")
@@ -5435,7 +5442,7 @@ of."
5435 prompt) 5442 prompt)
5436 (goto-char (point-min)) 5443 (goto-char (point-min))
5437 (tramp-check-for-regexp proc tramp-process-action-regexp) 5444 (tramp-check-for-regexp proc tramp-process-action-regexp)
5438 (setq prompt (concat (match-string 1) " ")) 5445 (setq prompt (concat (string-trim (match-string 1)) " "))
5439 (tramp-message vec 3 "Sending %s" (match-string 1)) 5446 (tramp-message vec 3 "Sending %s" (match-string 1))
5440 ;; We don't call `tramp-send-string' in order to hide the 5447 ;; We don't call `tramp-send-string' in order to hide the
5441 ;; password from the debug buffer and the traces. 5448 ;; password from the debug buffer and the traces.
@@ -5511,14 +5518,16 @@ Wait, until the connection buffer changes."
5511 (ignore set-message-function clear-message-function) 5518 (ignore set-message-function clear-message-function)
5512 (tramp-message vec 6 "\n%s" (buffer-string)) 5519 (tramp-message vec 6 "\n%s" (buffer-string))
5513 (tramp-check-for-regexp proc tramp-process-action-regexp) 5520 (tramp-check-for-regexp proc tramp-process-action-regexp)
5514 (with-temp-message 5521 (with-temp-message (concat (string-trim (match-string 0)) " ")
5515 (replace-regexp-in-string (rx (any "\r\n")) "" (match-string 0))
5516 ;; Hide message in buffer. 5522 ;; Hide message in buffer.
5517 (narrow-to-region (point-max) (point-max)) 5523 (narrow-to-region (point-max) (point-max))
5518 ;; Wait for new output. 5524 ;; Wait for new output.
5519 (while (not (ignore-error file-error 5525 (while (not (ignore-error file-error
5520 (tramp-wait-for-regexp 5526 (tramp-wait-for-regexp
5521 proc 0.1 tramp-security-key-confirmed-regexp))) 5527 proc 0.1
5528 (rx (| (regexp tramp-security-key-confirmed-regexp)
5529 (regexp tramp-security-key-pin-regexp)
5530 (regexp tramp-security-key-timeout-regexp))))))
5522 (when (tramp-check-for-regexp proc tramp-security-key-timeout-regexp) 5531 (when (tramp-check-for-regexp proc tramp-security-key-timeout-regexp)
5523 (throw 'tramp-action 'timeout)) 5532 (throw 'tramp-action 'timeout))
5524 (redisplay 'force)))))) 5533 (redisplay 'force))))))
@@ -6564,12 +6573,13 @@ Consults the auth-source package."
6564 (tramp-get-connection-property key "login-as"))) 6573 (tramp-get-connection-property key "login-as")))
6565 (host (tramp-file-name-host-port vec)) 6574 (host (tramp-file-name-host-port vec))
6566 (pw-prompt 6575 (pw-prompt
6567 (or prompt 6576 (string-trim-left
6568 (with-current-buffer (process-buffer proc) 6577 (or prompt
6569 (tramp-check-for-regexp proc tramp-password-prompt-regexp) 6578 (with-current-buffer (process-buffer proc)
6570 (if (string-match-p "passphrase" (match-string 1)) 6579 (tramp-check-for-regexp proc tramp-password-prompt-regexp)
6571 (match-string 0) 6580 (if (string-match-p "passphrase" (match-string 1))
6572 (format "%s for %s " (capitalize (match-string 1)) key))))) 6581 (match-string 0)
6582 (format "%s for %s " (capitalize (match-string 1)) key))))))
6573 (auth-source-creation-prompts `((secret . ,pw-prompt))) 6583 (auth-source-creation-prompts `((secret . ,pw-prompt)))
6574 ;; Use connection-local value. 6584 ;; Use connection-local value.
6575 (auth-sources (buffer-local-value 'auth-sources (process-buffer proc))) 6585 (auth-sources (buffer-local-value 'auth-sources (process-buffer proc)))