mirror of
https://github.com/dyne/Tomb
synced 2024-10-18 15:42:17 +00:00
Direct handling of pinentry execution
We skip distro wrappers here since they interfere with stdin/out As usual: better to have less intermediaries.
This commit is contained in:
parent
1ef2576b16
commit
bbe9a49ec3
103
tomb
103
tomb
|
@ -160,7 +160,14 @@ TRAPSTOP() { _endgame STOP }
|
||||||
|
|
||||||
_cat() { local -a _arr;
|
_cat() { local -a _arr;
|
||||||
# read file using mapfile, newline fix
|
# read file using mapfile, newline fix
|
||||||
_arr=("${(f@)${mapfile[${1}]%$’\n’}}"); print "$_arr" }
|
_arr=("${(f@)${mapfile[${1}]%$’\n’}}"); print "$_arr"
|
||||||
|
}
|
||||||
|
|
||||||
|
_is_found() {
|
||||||
|
# returns 0 if binary if found in path
|
||||||
|
[[ "$1" = "" ]] && return 1
|
||||||
|
return command -v "$1" 1>/dev/null 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
# Identify the running user
|
# Identify the running user
|
||||||
# Set global variables _UID, _GID, _TTY, and _USER, either from the
|
# Set global variables _UID, _GID, _TTY, and _USER, either from the
|
||||||
|
@ -343,15 +350,17 @@ ask_password() {
|
||||||
local gtkrc
|
local gtkrc
|
||||||
local theme
|
local theme
|
||||||
|
|
||||||
[[ "$DISPLAY" = "" ]] || {
|
# Distributions have broken wrappers for pinentry: they do
|
||||||
theme=/share/themes/tomb/gtk-2.0-key/gtkrc
|
# implement fallback, but they disrupt the output somehow. We are
|
||||||
for i in /usr/local /usr; do
|
# better off relying on less intermediaries, so we implement our
|
||||||
[[ -r $i/$theme ]] && {
|
# own fallback mechanisms. Pinentry supported: curses, gtk-2, qt4
|
||||||
gtkrc=$i/$theme
|
# and x11.
|
||||||
break }
|
|
||||||
done }
|
|
||||||
|
|
||||||
output=`cat <<EOF | GTK2_RC_FILES="$gtkrc" pinentry-gtk-2
|
if [[ "$DISPLAY" = "" ]]; then
|
||||||
|
|
||||||
|
if _is_found "pinentry-curses"; then
|
||||||
|
|
||||||
|
output=`cat <<EOF | pinentry-curses
|
||||||
OPTION ttyname=$TTY
|
OPTION ttyname=$TTY
|
||||||
OPTION lc-ctype=$LANG
|
OPTION lc-ctype=$LANG
|
||||||
SETTITLE $title
|
SETTITLE $title
|
||||||
|
@ -359,7 +368,77 @@ SETDESC $description
|
||||||
SETPROMPT Password:
|
SETPROMPT Password:
|
||||||
GETPIN
|
GETPIN
|
||||||
EOF`
|
EOF`
|
||||||
|
else
|
||||||
|
_failure "Cannot find pinentry-curses and no DISPLAY detected."
|
||||||
|
fi
|
||||||
|
|
||||||
|
else # a DISPLAY is found to be active
|
||||||
|
|
||||||
|
# customized gtk2 dialog with a skull (if extras are installed)
|
||||||
|
if _is_found "pinentry-gtk-2"; then
|
||||||
|
|
||||||
|
[[ "$DISPLAY" = "" ]] || {
|
||||||
|
theme=/share/themes/tomb/gtk-2.0-key/gtkrc
|
||||||
|
for i in /usr/local /usr; do
|
||||||
|
[[ -r $i/$theme ]] && {
|
||||||
|
gtkrc=$i/$theme
|
||||||
|
break }
|
||||||
|
done }
|
||||||
|
|
||||||
|
output=`cat <<EOF | GTK2_RC_FILES="$gtkrc" pinentry-gtk-2
|
||||||
|
OPTION ttyname=$TTY
|
||||||
|
OPTION lc-ctype=$LANG
|
||||||
|
SETTITLE $title
|
||||||
|
SETDESC $description
|
||||||
|
SETPROMPT Password:
|
||||||
|
GETPIN
|
||||||
|
EOF`
|
||||||
|
|
||||||
|
# TODO QT4 customization of dialog
|
||||||
|
elif _is_found "pinentry-qt4"; then
|
||||||
|
|
||||||
|
output=`cat <<EOF | pinentry-qt4
|
||||||
|
OPTION ttyname=$TTY
|
||||||
|
OPTION lc-ctype=$LANG
|
||||||
|
SETTITLE $title
|
||||||
|
SETDESC $description
|
||||||
|
SETPROMPT Password:
|
||||||
|
GETPIN
|
||||||
|
EOF`
|
||||||
|
|
||||||
|
# TODO X11 customization of dialog
|
||||||
|
elif _is_found "pinentry-x11"; then
|
||||||
|
|
||||||
|
output=`cat <<EOF | pinentry-x11
|
||||||
|
OPTION ttyname=$TTY
|
||||||
|
OPTION lc-ctype=$LANG
|
||||||
|
SETTITLE $title
|
||||||
|
SETDESC $description
|
||||||
|
SETPROMPT Password:
|
||||||
|
GETPIN
|
||||||
|
EOF`
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
if _is_found "pinentry-curses"; then
|
||||||
|
|
||||||
|
_warning "Detected DISPLAY, but only pinentry-curses is found."
|
||||||
|
output=`cat <<EOF | pinentry-curses
|
||||||
|
OPTION ttyname=$TTY
|
||||||
|
OPTION lc-ctype=$LANG
|
||||||
|
SETTITLE $title
|
||||||
|
SETDESC $description
|
||||||
|
SETPROMPT Password:
|
||||||
|
GETPIN
|
||||||
|
EOF`
|
||||||
|
else
|
||||||
|
_failure "Cannot find any pinentry: impossible to ask for password."
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi # end of DISPLAY block
|
||||||
|
|
||||||
# parse the pinentry output
|
# parse the pinentry output
|
||||||
for i in ${(f)output}; do
|
for i in ${(f)output}; do
|
||||||
[[ "$i" =~ "^ERR.*" ]] && {
|
[[ "$i" =~ "^ERR.*" ]] && {
|
||||||
|
@ -371,7 +450,7 @@ EOF`
|
||||||
[[ "$i" =~ "^D .*" ]] && password="${i##D }"
|
[[ "$i" =~ "^D .*" ]] && password="${i##D }"
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ "$password" = "" ]] && {
|
[[ "$password" = "" ]] && {
|
||||||
_warning "Empty password"
|
_warning "Empty password"
|
||||||
print "empty"
|
print "empty"
|
||||||
return 1 }
|
return 1 }
|
||||||
|
@ -724,7 +803,7 @@ _tomb_key_recover recover_key() {
|
||||||
local key="${1}" # Unique argument is an encrypted key
|
local key="${1}" # Unique argument is an encrypted key
|
||||||
|
|
||||||
_warning "Attempting key recovery."
|
_warning "Attempting key recovery."
|
||||||
|
|
||||||
_head="${key[(f)1]}" # take the first line
|
_head="${key[(f)1]}" # take the first line
|
||||||
|
|
||||||
TOMBKEY="" # Reset global variable
|
TOMBKEY="" # Reset global variable
|
||||||
|
|
Loading…
Reference in a new issue