aboutsummaryrefslogtreecommitdiffstats
path: root/pinentry-rofi.sh
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-08-03 13:12:33 +0200
committerMatěj Cepl <mcepl@cepl.eu>2023-08-03 13:13:13 +0200
commit83b054b8c1c14ac7c67f9b1850964c7dd47b9132 (patch)
tree1915256655a51e61d5870db4b53306eb058b5163 /pinentry-rofi.sh
parentc44d20b642523c14a77e3f3c316a1d6cf1df7340 (diff)
downloadpinentry-rofi-83b054b8c1c14ac7c67f9b1850964c7dd47b9132.tar.gz
First steps
Diffstat (limited to 'pinentry-rofi.sh')
-rwxr-xr-x[-rw-r--r--]pinentry-rofi.sh65
1 files changed, 25 insertions, 40 deletions
diff --git a/pinentry-rofi.sh b/pinentry-rofi.sh
index 4ca14d0..f956799 100644..100755
--- a/pinentry-rofi.sh
+++ b/pinentry-rofi.sh
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
+set -eux
# pinentry-wsl-ps1
#
@@ -19,12 +20,12 @@
# pinentry-program /mnt/c/repos/pinentry-wsl-ps1/pinentry-wsl-ps1.sh
# b) Set the path to this script when you launch gpg-agent
# gpg-agent --pinentry-program /mnt/c/repos/pinentry-wsl-ps1/pinentry-wsl-ps1.sh
-# WSL-only 3. Optionally enable persistence of passwords.
-# WSL-only Requires https://github.com/davotronic5000/PowerShell_Credential_Manager
-# WSL-only Please follow instructions there to install from the Gallery or GitHub.
-# WSL-only Note security perspectives like https://security.stackexchange.com/questions/119765/how-secure-is-the-windows-credential-manager
-# WSL-only Possible values for PERSISTENCE are: "", "Session", "LocalMachine", or "Enterprise"
-PERSISTENCE=""
+# PORT 3. Optionally enable persistence of passwords.
+# PORT Requires https://github.com/davotronic5000/PowerShell_Credential_Manager
+# PORT Please follow instructions there to install from the Gallery or GitHub.
+# PORT Note security perspectives like https://security.stackexchange.com/questions/119765/how-secure-is-the-windows-credential-manager
+# PORT Possible values for PERSISTENCE are: "", "Session", "LocalMachine", or "Enterprise"
+# PORT PERSISTENCE=""
DEBUGLOG=""
# Do not casually edit the below values
@@ -46,6 +47,9 @@ REPEATDESCRIPTION="Confirm password for GPG key"
REPEATERROR="Error: Passwords did not match."
GRABKEYBOARD="0"
+
+rofi_cmd="rofi -dmenu -input /dev/null -password"
+
# convert Assuan protocol error into an ERR number, e.g. echo -n $(( (5 << 24) | $1 ))
assuan_result() {
case $1 in
@@ -87,6 +91,8 @@ getpassword() {
local creduser="--not yet defined--"
fi
fi
+ # $rofi_cmd -title $TITLE -p "$PINERROR$DESCRIPTION"
+ # Put somewhere $creduser
local cmd_prompt=$(cat <<-DLM
\$cred = \$Host.ui.PromptForCredential("$TITLE",
"$PINERROR$DESCRIPTION",
@@ -111,31 +117,19 @@ DLM
}
DLM
)
- local cmd_lookup=$(cat <<-DLM
- \$cred = Get-StoredCredential -Target "$CACHEPREFIX$KEYINFO" -Type GENERIC
- if (\$cred) {
- Write-Output \$cred.GetNetworkCredential().Password
- }
-DLM
+# PORT local cmd_lookup=$(cat <<-DLM
+# PORT \$cred = Get-StoredCredential -Target "$CACHEPREFIX$KEYINFO" -Type GENERIC
+# PORT if (\$cred) {
+# PORT Write-Output \$cred.GetNetworkCredential().Password
+# PORT }
+# PORT DLM
)
- local cmd_store=$(cat <<-DLM
- \$pw = \$Input | Select-Object -First 1
- \$securepw = ConvertTo-SecureString \$pw -AsPlainText -Force
- New-StoredCredential -Target "$CACHEPREFIX$KEYINFO" -Type GENERIC -UserName "$creduser" -SecurePassword \$securepw -Persist $PERSISTENCE |
- out-null
-DLM
- )
- # idea from http://thewindowscollege.com/display-toast-notifications-windows-10.html
- # alt1: https://gist.github.com/loge5/7ec41e2e2f0e0293fdcc5155499e9072
- # alt2: https://gist.github.com/Windos/9aa6a684ac583e0d38a8fa68196bc2dc
- local cmd_toast=$(cat <<-DLM
- [reflection.assembly]::loadwithpartialname("System.Windows.Forms")
- [reflection.assembly]::loadwithpartialname("System.Drawing")
- \$notify = new-object system.windows.forms.notifyicon
- \$notify.icon = [System.Drawing.SystemIcons]::Information
- \$notify.visible = \$true
- \$notify.showballoontip(10, "GPG pinentry-wsl-ps1", "GPG password retrieved from Windows Credential Manager", [system.windows.forms.tooltipicon]::Info)
-DLM
+# PORT local cmd_store=$(cat <<-DLM
+# PORT \$pw = \$Input | Select-Object -First 1
+# PORT \$securepw = ConvertTo-SecureString \$pw -AsPlainText -Force
+# PORT New-StoredCredential -Target "$CACHEPREFIX$KEYINFO" -Type GENERIC -UserName "$creduser" -SecurePassword \$securepw -Persist $PERSISTENCE |
+# PORT out-null
+# PORT DLM
)
local credpassword
local credpasswordrepeat
@@ -172,7 +166,7 @@ DLM
if [ -n "$KEYINFO" ]; then
# avoid setting password on visible param
# alt is to always save on the single or last-of-repeat dialog. And if the repeat fails, then immediately delete it from the cred store
- builtin echo -n "$credpassword" | powershell.exe -nologo -noprofile -noninteractive -command "$cmd_store"
+ # PORT builtin echo -n "$credpassword" | powershell.exe -nologo -noprofile -noninteractive -command "$cmd_store"
fi
fi
else
@@ -348,9 +342,6 @@ setoption() {
local value="$(echo "$1" | cut -d'=' -s -f2-)"
case $key in
allow-external-password-cache)
- if [ -n "$PERSISTENCE" ]; then
- EXTPASSCACHE=1
- fi
echo "OK"
;;
default-ok)
@@ -379,12 +370,6 @@ setoption() {
esac
}
-# check that we are running within WSL
-if ! cat /proc/sys/kernel/osrelease | grep -q -i Microsoft; then
- echo "$(assuan_result 257)"
- exit 1
-fi
-
# main loop to read stdin and respond
echo "OK Your orders please"
while IFS= read -r line; do