-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinentry-ssh-askpass
executable file
·32 lines (29 loc) · 1.06 KB
/
pinentry-ssh-askpass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
#
# Based on https://gist.githubusercontent.com/smashwilson/4420b235922581ea3d7b26769ee8ec9e/raw/fbbc55e6ef2ac363d9fd4452cf1eb078ebd1b3ca/ssh-pinentry.sh
#
# abstract: pinentry wrapper to allow it to be used for SSH_ASKPASS and SUDO_ASKPASS
#
urldecode() {
python -c 'import sys, urllib.parse; sys.stdout.write(urllib.parse.unquote(sys.stdin.read()))'
}
prompt="${1-}"
if [ -n "$prompt" ]; then
case "$prompt" in
*Enter*)
prompt=$(echo "$1" | sed 's@^.*Enter passphrase.*/\(.*\):.*$@SSH key "\1":@')
;;
*Bad*)
prompt=$(echo "$1" | sed 's@^.*Bad passphrase.*/\(.*\):.*$@(Retry) SSH key "\1":@')
;;
esac
else
prompt="[sudo] password for $USER: "
fi
# pinentry requires '-T $(tty)' in case it ends up calling pinentry-ncurses
# otherwise, it won't be able to get user input from the TTY and it will fail
exec pinentry -T "$(tty)" <<EOM | grep '^D ' | sed -e 's/^D //g' | tr -d '\n' | urldecode
$(test -n "${prompt-}" && echo "SETPROMPT $prompt")
$(test -n "${2-}" && echo "SETDESC $2")
GETPIN
EOM