{"thread":{"id":"56891","subject":"[PATCH] git-gui--askpass implements SSH_ASKPASS_PROMPT","startedAt":"2021-11-14T00:30:54Z","lastAt":"2021-11-14T00:30:54Z","messageCount":1,"participants":["Likai Liu"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"441074","messageId":"20211114003026.4894-1-liulk@likai.org","threadId":"56891","inReplyTo":null,"subject":"[PATCH] git-gui--askpass implements SSH_ASKPASS_PROMPT","fromName":"Likai Liu","fromEmail":"liulk@likai.org","sentAt":"2021-11-14T00:30:26Z","receivedAt":"2021-11-14T00:30:54Z","isPatch":true,"sender":{"key":"liulk@likai.org","avatar":null},"body":"SSH_ASKPASS_PROMPT is a new behavior introduced in OpenSSH 8.2 for\nprompting U2F touch.\n\n  - When unset/empty, this is used to input passphrase as before.\n  - When set to \"confirm\", allows the user to OK or Cancel.\n  - When set to \"none\", only shows a message.\n\nSigned-off-by: Likai Liu <liulk@likai.org>\n---\n git-gui/git-gui--askpass | 70 +++++++++++++++++++++++++++++-----------\n 1 file changed, 52 insertions(+), 18 deletions(-)\n\ndiff --git a/git-gui/git-gui--askpass b/git-gui/git-gui--askpass\nindex 71a536d232..7d4bda8f31 100755\n--- a/git-gui/git-gui--askpass\n+++ b/git-gui/git-gui--askpass\n@@ -4,6 +4,21 @@ exec wish \"$0\" -- \"$@\"\n \n # This is a trivial implementation of an SSH_ASKPASS handler.\n # Git-gui uses this script if none are already configured.\n+#\n+# When SSH_ASKPASS_PROMPT is unset or empty, we show a message\n+# promot, a text input, an option to show the input, and the OK and\n+# Cancel buttons.  If the prompt explicitly asks for (yes/no) as the\n+# answer, the input will be checked to be either \"yes\" or \"no\".\n+#\n+# When SSH_ASKPASS_PROMPT=confirm, we only show the message and the OK\n+# and Cancel buttons without the text input.\n+#\n+# When SSH_ASKPASS_PROMPT=none, we only show the message.  This is\n+# typically to prompt for U2F touch, which cannot be dismissed.  We\n+# will get SIGTERM once touched.  The exit status is inconsequential.\n+#\n+# See: https://www.openssh.com/txt/release-8.2\n+# See also: notify_start() and notify_complete() in readpass.c\n \n package require Tk\n \n@@ -11,10 +26,22 @@ set answer {}\n set yesno  0\n set rc     255\n \n+if {[info exists ::env(SSH_ASKPASS_PROMPT)]} {\n+\tset mode $::env(SSH_ASKPASS_PROMPT)\n+} else {\n+\tset mode {}\n+}\n+switch $mode {\n+\tconfirm {}\n+\tnone {}\n+\tdefault {set mode {}}\n+}\n if {$argc < 1} {\n \tset prompt \"Enter your OpenSSH passphrase:\"\n } else {\n \tset prompt [join $argv \" \"]\n+}\n+if {$mode eq {}} {\n \tif {[regexp -nocase {\\(yes\\/no\\)\\?\\s*$} $prompt]} {\n \t\tset yesno 1\n \t}\n@@ -23,9 +50,6 @@ if {$argc < 1} {\n message .m -text $prompt -justify center -aspect 4000\n pack .m -side top -fill x -padx 20 -pady 20 -expand 1\n \n-entry .e -textvariable answer -width 50\n-pack .e -side top -fill x -padx 10 -pady 10\n-\n proc on_show_input_changed {args} {\n \tglobal show_input\n \tif {$show_input} {\n@@ -34,27 +58,37 @@ proc on_show_input_changed {args} {\n \t\t.e configure -show \"*\"\n \t}\n }\n-trace add variable show_input write \"on_show_input_changed\"\n \n-set show_input 0\n+if {$mode eq {}} {\n+\tentry .e -textvariable answer -width 50\n+\tpack .e -side top -fill x -padx 10 -pady 10\n \n-if {!$yesno} {\n-\tcheckbutton .cb_show -text \"Show input\" -variable show_input\n-\tpack .cb_show -side top -anchor nw\n+\ttrace add variable show_input write \"on_show_input_changed\"\n+\n+\tset show_input $yesno\n+\n+\tif {!$yesno} {\n+\t\tcheckbutton .cb_show -text \"Show input\" -variable show_input\n+\t\tpack .cb_show -side top -anchor nw\n+\t}\n }\n \n-frame .b\n-button .b.ok     -text OK     -command finish\n-button .b.cancel -text Cancel -command cancel\n+if {$mode ne {none}} {\n+\tframe .b\n+\tbutton .b.ok     -text OK     -command finish\n+\tbutton .b.cancel -text Cancel -command cancel\n \n-pack .b.ok -side left -expand 1\n-pack .b.cancel -side right -expand 1\n-pack .b -side bottom -fill x -padx 10 -pady 10\n+\tpack .b.ok -side left -expand 1\n+\tpack .b.cancel -side right -expand 1\n+\tpack .b -side bottom -fill x -padx 10 -pady 10\n \n-bind . <Visibility> {focus -force .e}\n-bind . <Key-Return> [list .b.ok invoke]\n-bind . <Key-Escape> [list .b.cancel invoke]\n-bind . <Destroy>    {set rc $rc}\n+\tif {$mode eq {}} {\n+\t\tbind . <Visibility> {focus -force .e}\n+\t}\n+\tbind . <Key-Return> [list .b.ok invoke]\n+\tbind . <Key-Escape> [list .b.cancel invoke]\n+}\n+bind . <Destroy> {set rc $rc}\n \n proc cancel {} {\n \tset ::rc 255\n-- \n2.30.1 (Apple Git-130)\n\n"}]}