Skip to content

Commit

Permalink
Add Pinentry CLI fallback (gopasspw#1697)
Browse files Browse the repository at this point in the history
Fixes gopasspw#1655

RELEASE_NOTES=[ENHANCEMENT] Add Pinentry CLI fallback

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz authored Jan 18, 2021
1 parent 6974917 commit 670630d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/backend/crypto/age/askpass.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
},
}
}
Expand Down
42 changes: 42 additions & 0 deletions pkg/pinentry/cli/fallback.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 670630d

Please sign in to comment.