From 670630de57469d90826cc3d46924530e8578b0b3 Mon Sep 17 00:00:00 2001 From: Dominik Schulz Date: Mon, 18 Jan 2021 23:02:53 +0100 Subject: [PATCH] Add Pinentry CLI fallback (#1697) Fixes #1655 RELEASE_NOTES=[ENHANCEMENT] Add Pinentry CLI fallback Signed-off-by: Dominik Schulz --- internal/backend/crypto/age/askpass.go | 8 ++++- pkg/pinentry/cli/fallback.go | 42 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 pkg/pinentry/cli/fallback.go diff --git a/internal/backend/crypto/age/askpass.go b/internal/backend/crypto/age/askpass.go index a6d5df023d..95eea9d6c9 100644 --- a/internal/backend/crypto/age/askpass.go +++ b/internal/backend/crypto/age/askpass.go @@ -8,6 +8,7 @@ import ( "github.com/gopasspw/gopass/internal/cache" "github.com/gopasspw/gopass/pkg/debug" "github.com/gopasspw/gopass/pkg/pinentry" + "github.com/gopasspw/gopass/pkg/pinentry/cli" ) type piner interface { @@ -38,7 +39,12 @@ func newAskPass() *askPass { return &askPass{ cache: cache.NewInMemTTL(time.Hour, 24*time.Hour), pinentry: func() (piner, error) { - return pinentry.New() + p, err := pinentry.New() + if err == nil { + return p, nil + } + debug.Log("Pinentry not found: %q", err) + return cli.New() }, } } diff --git a/pkg/pinentry/cli/fallback.go b/pkg/pinentry/cli/fallback.go new file mode 100644 index 0000000000..bc229b24c9 --- /dev/null +++ b/pkg/pinentry/cli/fallback.go @@ -0,0 +1,42 @@ +package cli + +import ( + "context" + + "github.com/gopasspw/gopass/pkg/termio" +) + +// Client is pinentry CLI drop-in +type Client struct{} + +// New creates a new client +func New() (*Client, error) { + return &Client{}, nil +} + +// Close is a no-op +func (c *Client) Close() {} + +// Confirm is a no-op +func (c *Client) Confirm() bool { + return true +} + +// Set is a no-op +func (c *Client) Set(string, string) error { + return nil +} + +// Option is a no-op +func (c *Client) Option(string) error { + return nil +} + +// GetPin prompts for the pin in the termnial and returns the output +func (c *Client) GetPin() ([]byte, error) { + pw, err := termio.AskForPassword(context.TODO(), "Please enter your PIN") + if err != nil { + return nil, err + } + return []byte(pw), nil +}