Skip to content

Commit

Permalink
Add optional pinentry unescaping
Browse files Browse the repository at this point in the history
Fixes gopasspw#1621

RELEASE_NOTES=[ENHANCEMENT] Add optional pinentry unescaping

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz committed Jan 14, 2021
1 parent ddfe7bf commit 8211c06
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pkg/pinentry/pinentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@ import (
"bytes"
"fmt"
"io"
"net/url"
"os"
"os/exec"
"strings"

"github.com/pkg/errors"
)

var (
// Enable unescaping of percent encoded values, disabled by default
// for backwards compatability. See #1621
Unescape bool
)

func init() {
if sv := os.Getenv("GOPASS_PINENTRY_UNESCAPE"); sv == "on" || sv == "true" {
Unescape = true
}
}

// Client is a pinentry client
type Client struct {
cmd *exec.Cmd
Expand Down Expand Up @@ -134,5 +148,15 @@ func (c *Client) GetPin() ([]byte, error) {
if !bytes.HasPrefix(ok, []byte("OK")) {
return nil, fmt.Errorf("unexpected response: %s", ok)
}
return pin[2:], nil
pin = pin[2:]

// Handle unescaping, if enabled
if bytes.Contains(pin, []byte("%")) && Unescape {
sv, err := url.QueryUnescape(string(pin))
if err != nil {
return nil, fmt.Errorf("failed to unescape pin: %q", err)
}
pin = []byte(sv)
}
return pin, nil
}

0 comments on commit 8211c06

Please sign in to comment.