aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDale Phurrough <dale@hidale.com>2018-02-09 02:31:05 +0100
committerDale Phurrough <dale@hidale.com>2018-02-13 16:07:20 +0100
commit8355b07e1a87e01381676b81343c8c0c6c76ca93 (patch)
treeaf2334c93b7ed0ea32c3711e1dd52d2ceeea7dc5
parentc3dd89707006cb3e6fc74626e5f609c97aa775e6 (diff)
downloadpinentry-rofi-8355b07e1a87e01381676b81343c8c0c6c76ca93.tar.gz
fixed cache error loops, text formatting
- fixed cache loop on error - fixed line feeds on description and error text - fixed button accelerator parsing - changed back to 6 param Prompt...Cred() to prevent user format validation
-rw-r--r--pinentry-wsl-ps1.sh56
1 files changed, 34 insertions, 22 deletions
diff --git a/pinentry-wsl-ps1.sh b/pinentry-wsl-ps1.sh
index bbf2f40..87f8b70 100644
--- a/pinentry-wsl-ps1.sh
+++ b/pinentry-wsl-ps1.sh
@@ -1,11 +1,11 @@
-#/bin/bash
+#!/bin/bash
VERSION="0.1.0"
TIMEOUT="0"
DESCRIPTION="Enter password for GPG key"
PROMPT="Password:"
TITLE="GPG Key Credentials"
-CREDENTIALPREFIX="gpgkey://"
+CACHEPREFIX="gpgcache://"
KEYINFO=""
OKBUTTON="&OK"
CANCELBUTTON="&Cancel"
@@ -51,7 +51,9 @@ getpassword() {
\$cred = \$Host.ui.PromptForCredential("$TITLE",
"$PINERROR$DESCRIPTION",
"$KEYINFO",
- "")
+ "",
+ "Generic",
+ "None,ReadOnlyUserName")
if (\$cred) {
Write-Output \$cred.GetNetworkCredential().Password
}
@@ -61,14 +63,16 @@ DLM
\$cred = \$Host.ui.PromptForCredential("$TITLE",
"$REPEATDESCRIPTION",
"$KEYINFO",
- "")
+ "",
+ "Generic",
+ "None,ReadOnlyUserName")
if (\$cred) {
Write-Output \$cred.GetNetworkCredential().Password
}
DLM
)
local cmd_lookup=$(cat <<-DLM
- \$cred = Get-StoredCredential -Target "$CREDENTIALPREFIX$KEYINFO" -Type GENERIC
+ \$cred = Get-StoredCredential -Target "$CACHEPREFIX$KEYINFO" -Type GENERIC
if (\$cred) {
Write-Output \$cred.GetNetworkCredential().Password
}
@@ -77,25 +81,27 @@ DLM
local cmd_store=$(cat <<-DLM
\$pw = \$Input | Select-Object -First 1
\$securepw = ConvertTo-SecureString \$pw -AsPlainText -Force
- New-StoredCredential -Target "$CREDENTIALPREFIX$KEYINFO" -Type GENERIC -UserName "$KEYINFO" -SecurePassword \$securepw -Persist LocalMachine |
+ New-StoredCredential -Target "$CACHEPREFIX$KEYINFO" -Type GENERIC -UserName "$KEYINFO" -SecurePassword \$securepw -Persist LocalMachine |
out-null
DLM
)
- PINERROR=""
local credpassword
local credpasswordrepeat
local passwordfromcache=0
- if [ "$REPEATPASSWORD" -eq "0" ]; then
- if [ "$EXTPASSCACHE" -eq "1" ]; then
- if [ -n "$KEYINFO" ]; then
- credpassword="$(powershell.exe -nologo -noprofile -noninteractive -command "$cmd_lookup")"
- if [ -n "$credpassword" ]; then
- echo -e "S PASSWORD_FROM_CACHE\nD $credpassword\nOK"
- return
+ if [ -z "$PINERROR" ]; then
+ if [ "$REPEATPASSWORD" -eq "0" ]; then
+ if [ "$EXTPASSCACHE" -eq "1" ]; then
+ if [ -n "$KEYINFO" ]; then
+ credpassword="$(powershell.exe -nologo -noprofile -noninteractive -command "$cmd_lookup")"
+ if [ -n "$credpassword" ]; then
+ echo -e "S PASSWORD_FROM_CACHE\nD $credpassword\nOK"
+ return
+ fi
fi
fi
fi
fi
+ PINERROR=""
credpassword="$(powershell.exe -nologo -noprofile -noninteractive -command "$cmd_prompt")"
if [ -n "$credpassword" ]; then
if [ "$REPEATPASSWORD" -eq "1" ]; then
@@ -129,7 +135,7 @@ removepassword() {
fi
local cmd_remove=$(cat <<-DLM
try {
- Remove-StoredCredential -Target "$CREDENTIALPREFIX$1" -Type GENERIC -ErrorAction Stop
+ Remove-StoredCredential -Target "$CACHEPREFIX$1" -Type GENERIC -ErrorAction Stop
}
catch {
Write-Output "$(assuan_result 261)"
@@ -193,7 +199,10 @@ settimeout() {
}
setdescription() {
- DESCRIPTION="$1"
+ local prep1="${1//%0A/%0D%0A}" # convert LF into Windows CRLF
+ local prep2="${prep1//%/\\x}" # convert hex encoding style
+ local decode="$(echo -en "$prep2")" # decode hex
+ DESCRIPTION="${decode//\"/\`\"}" # escape double quotes for powershell
echo "OK"
}
@@ -208,7 +217,11 @@ settitle() {
}
setpinerror() {
- PINERROR="** $1 ** "
+ local prep1="** $1 **"
+ local prep2="${prep1//%0A/%0D%0A}" # convert LF into Windows CRLF
+ local prep3="${prep2//%/\\x}" # convert hex encoding style
+ local decode="$(echo -e "$prep3")" # decode hex
+ PINERROR="${decode//\"/\`\"}"$'\r'$'\n' # escape double quotes for powershell; add CRLF to separate line
echo "OK"
}
@@ -233,17 +246,17 @@ setrepeaterror () {
}
setokbutton() {
- OKBUTTON="${$1//_/&}"
+ OKBUTTON="${1//_/&}"
echo "OK"
}
setcancelbutton() {
- CANCELBUTTON="${$1//_/&}"
+ CANCELBUTTON="${1//_/&}"
echo "OK"
}
setnotokbutton() {
- NOTOKBUTTON="${$1//_/&}"
+ NOTOKBUTTON="${1//_/&}"
echo "OK"
}
@@ -283,13 +296,12 @@ setoption() {
esac
}
+#rm -f /home/dalep/tracepin.txt
echo "OK Your orders please"
while IFS= read -r line; do
#echo "$line" >> /home/dalep/tracepin.txt
action="$(echo $line | cut -d' ' -f1)"
args="$(echo $line | cut -d' ' -s -f2-)"
- #echo "action:$action:"
- #echo "args:$args:"
case $action in
BYE)
echo "OK closing connection"