Simplify ssh askpass to require cached secret
- Remove native password prompts from posix and Windows scripts - Fail loudly when T3_SSH_AUTH_SECRET is missing
This commit is contained in:
1 parent
6ea09363b2
commit
0f2ed34b4f
2 files changed
+11
-72
No files matched your search
@@ -1,33 +1,10 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
PROMPT="${1:-SSH authentication}"
|
||||
# Invoked by ssh via SSH_ASKPASS when T3 Code re-runs ssh with a cached password
|
||||
# from the renderer's in-app prompt. We never expose a native dialog here — if
|
||||
# T3_SSH_AUTH_SECRET is missing, that's a caller bug and we fail loudly.
|
||||
if [ "${T3_SSH_AUTH_SECRET+x}" = "x" ]; then
|
||||
printf "%s\n" "$T3_SSH_AUTH_SECRET"
|
||||
exit 0
|
||||
fi
|
||||
if command -v osascript >/dev/null 2>&1; then
|
||||
T3_SSH_ASKPASS_PROMPT="$PROMPT" /usr/bin/osascript <<'APPLESCRIPT'
|
||||
set promptText to system attribute "T3_SSH_ASKPASS_PROMPT"
|
||||
try
|
||||
set dialogResult to display dialog promptText default answer "" with hidden answer buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"
|
||||
text returned of dialogResult
|
||||
on error number -128
|
||||
error number -128
|
||||
end try
|
||||
APPLESCRIPT
|
||||
exit $?
|
||||
fi
|
||||
if command -v zenity >/dev/null 2>&1; then
|
||||
zenity --password --title="SSH authentication" --text="$PROMPT"
|
||||
exit $?
|
||||
fi
|
||||
if command -v kdialog >/dev/null 2>&1; then
|
||||
kdialog --title "SSH authentication" --password "$PROMPT"
|
||||
exit $?
|
||||
fi
|
||||
if command -v ssh-askpass >/dev/null 2>&1; then
|
||||
ssh-askpass "$PROMPT"
|
||||
exit $?
|
||||
fi
|
||||
printf 'Unable to open an SSH password prompt on this desktop.\n' >&2
|
||||
printf 'T3 Code ssh-askpass invoked without T3_SSH_AUTH_SECRET.\n' >&2
|
||||
exit 1
|
||||
@@ -1,48 +1,10 @@
|
||||
if ($env:T3_SSH_AUTH_SECRET -ne $null) {
|
||||
# Invoked by ssh via SSH_ASKPASS (through ssh-askpass.cmd) when T3 Code re-runs
|
||||
# ssh with a cached password from the renderer's in-app prompt. We never expose
|
||||
# a native dialog here — if T3_SSH_AUTH_SECRET is missing, that's a caller bug
|
||||
# and we fail loudly.
|
||||
if ($null -ne $env:T3_SSH_AUTH_SECRET) {
|
||||
[Console]::Out.WriteLine($env:T3_SSH_AUTH_SECRET)
|
||||
exit 0
|
||||
}
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
[System.Windows.Forms.Application]::EnableVisualStyles()
|
||||
$prompt = if ($args.Length -gt 0 -and $args[0]) { $args[0] } else { "SSH authentication" }
|
||||
$form = New-Object System.Windows.Forms.Form
|
||||
$form.Text = "SSH authentication"
|
||||
$form.Width = 420
|
||||
$form.Height = 185
|
||||
$form.StartPosition = "CenterScreen"
|
||||
$form.FormBorderStyle = "FixedDialog"
|
||||
$form.MaximizeBox = $false
|
||||
$form.MinimizeBox = $false
|
||||
$form.TopMost = $true
|
||||
$label = New-Object System.Windows.Forms.Label
|
||||
$label.Left = 16
|
||||
$label.Top = 16
|
||||
$label.Width = 372
|
||||
$label.Height = 34
|
||||
$label.Text = $prompt
|
||||
$textbox = New-Object System.Windows.Forms.TextBox
|
||||
$textbox.Left = 16
|
||||
$textbox.Top = 60
|
||||
$textbox.Width = 372
|
||||
$textbox.UseSystemPasswordChar = $true
|
||||
$okButton = New-Object System.Windows.Forms.Button
|
||||
$okButton.Text = "OK"
|
||||
$okButton.Left = 232
|
||||
$okButton.Top = 100
|
||||
$okButton.Width = 75
|
||||
$cancelButton = New-Object System.Windows.Forms.Button
|
||||
$cancelButton.Text = "Cancel"
|
||||
$cancelButton.Left = 313
|
||||
$cancelButton.Top = 100
|
||||
$cancelButton.Width = 75
|
||||
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
||||
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
||||
$form.AcceptButton = $okButton
|
||||
$form.CancelButton = $cancelButton
|
||||
$form.Controls.Add($label)
|
||||
$form.Controls.Add($textbox)
|
||||
$form.Controls.Add($okButton)
|
||||
$form.Controls.Add($cancelButton)
|
||||
$result = $form.ShowDialog()
|
||||
if ($result -ne [System.Windows.Forms.DialogResult]::OK) { exit 1 }
|
||||
[Console]::Out.WriteLine($textbox.Text)
|
||||
[Console]::Error.WriteLine("T3 Code ssh-askpass invoked without T3_SSH_AUTH_SECRET.")
|
||||
exit 1
|
||||
Reference in new issue
Block a user