mirror of
https://github.com/gaschz/qubes-pass.git
synced 2025-03-01 14:22:31 +01:00
Use entirely original pass code for qrencode and clip functionality, but base64 the data and pass it to bash through stdin instead.
This commit is contained in:
parent
23d4dffd1a
commit
1d169d3e78
40
bin/qvm-pass
40
bin/qvm-pass
@ -7,7 +7,6 @@ import os
|
|||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pipes import quote
|
from pipes import quote
|
||||||
@ -63,7 +62,7 @@ usage_string = (
|
|||||||
|
|
||||||
# The following code was lifted from the pass program to support
|
# The following code was lifted from the pass program to support
|
||||||
# identical functionality.
|
# identical functionality.
|
||||||
shell_functions = """
|
shell_functions = b"""
|
||||||
X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"
|
X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"
|
||||||
CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"
|
CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"
|
||||||
BASE64="base64"
|
BASE64="base64"
|
||||||
@ -96,12 +95,11 @@ clip() {
|
|||||||
# trailing new lines.
|
# trailing new lines.
|
||||||
pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5
|
pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5
|
||||||
local before="$("${paste_cmd[@]}" 2>/dev/null | $BASE64)"
|
local before="$("${paste_cmd[@]}" 2>/dev/null | $BASE64)"
|
||||||
pwbased=$(cat "$1" | $BASE64) # Customized for qvm-pass.
|
echo -n "$1" | "${copy_cmd[@]}" || die "Error: Could not copy data to the clipboard"
|
||||||
echo -n "$pwbased" | $BASE64 -d | "${copy_cmd[@]}" || die "Error: Could not copy data to the clipboard"
|
|
||||||
(
|
(
|
||||||
( exec -a "$sleep_argv0" bash <<<"trap 'kill %1' TERM; sleep '$CLIP_TIME' & wait" )
|
( exec -a "$sleep_argv0" bash <<<"trap 'kill %1' TERM; sleep '$CLIP_TIME' & wait" )
|
||||||
local now="$("${paste_cmd[@]}" | $BASE64)"
|
local now="$("${paste_cmd[@]}" | $BASE64)"
|
||||||
[[ $now != $(echo -n "$pwbased") ]] && before="$now"
|
[[ $now != $(echo -n "$1" | $BASE64) ]] && before="$now"
|
||||||
|
|
||||||
# It might be nice to programatically check to see if klipper exists,
|
# It might be nice to programatically check to see if klipper exists,
|
||||||
# as well as checking for other common clipboard managers. But for now,
|
# as well as checking for other common clipboard managers. But for now,
|
||||||
@ -120,36 +118,38 @@ clip() {
|
|||||||
qrcode() {
|
qrcode() {
|
||||||
if [[ -n $DISPLAY || -n $WAYLAND_DISPLAY ]]; then
|
if [[ -n $DISPLAY || -n $WAYLAND_DISPLAY ]]; then
|
||||||
if type feh >/dev/null 2>&1; then
|
if type feh >/dev/null 2>&1; then
|
||||||
cat "$1" | qrencode --size 10 -o - | feh -x --title "pass: $2" -g +200+200 -
|
echo -n "$1" | qrencode --size 10 -o - | feh -x --title "pass: $2" -g +200+200 -
|
||||||
return
|
return
|
||||||
elif type gm >/dev/null 2>&1; then
|
elif type gm >/dev/null 2>&1; then
|
||||||
cat "$1" | qrencode --size 10 -o - | gm display -title "pass: $2" -geometry +200+200 -
|
echo -n "$1" | qrencode --size 10 -o - | gm display -title "pass: $2" -geometry +200+200 -
|
||||||
return
|
return
|
||||||
elif type display >/dev/null 2>&1; then
|
elif type display >/dev/null 2>&1; then
|
||||||
cat "$1" | qrencode --size 10 -o - | display -title "pass: $2" -geometry +200+200 -
|
echo -n "$1" | qrencode --size 10 -o - | display -title "pass: $2" -geometry +200+200 -
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
cat "$1" | qrencode -t utf8
|
echo -n "$1" | qrencode -t utf8
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def pass_frontend_shell(cmd, lineno=1):
|
def pass_frontend_shell(cmd, lineno=1):
|
||||||
cmd, data, path = cmd
|
cmd, data, path = cmd
|
||||||
|
cmd = quote(cmd)
|
||||||
|
path = quote(path)
|
||||||
line = data.splitlines()[lineno - 1]
|
line = data.splitlines()[lineno - 1]
|
||||||
|
|
||||||
global shell_functions
|
global shell_functions
|
||||||
with tempfile.TemporaryDirectory(prefix="qubes-pass-") as d:
|
quoted_cmd = shell_functions
|
||||||
fifo = os.path.join(d, "fifo")
|
quoted_cmd += b"\n\n"
|
||||||
os.mkfifo(fifo)
|
quoted_cmd += b"DATA=$( echo " + base64.b64encode(line) + b" | $BASE64 -d )\n"
|
||||||
quoted_cmd = (
|
quoted_cmd += ("%s %s %s" % (cmd, '"$DATA"', path)).encode("utf-8")
|
||||||
shell_functions + "\n\n" + " ".join(quote(x) for x in (cmd, fifo, path))
|
# quoted_cmd = (
|
||||||
)
|
# shell_functions + b"\n\n" + ("%s %s %s" % (cmd, data, path)).encode("utf-8")
|
||||||
p = subprocess.Popen(["bash", "-c", quoted_cmd])
|
# )
|
||||||
with open(fifo, "wb") as fifof:
|
p = subprocess.Popen(["bash"], stdin=subprocess.PIPE)
|
||||||
fifof.write(line)
|
p.communicate(quoted_cmd)
|
||||||
fifof.flush()
|
return p.wait()
|
||||||
return p.wait()
|
|
||||||
|
|
||||||
|
|
||||||
def clip(data, path, lineno=1):
|
def clip(data, path, lineno=1):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user