Skip to content

Commit

Permalink
feat: fallback to pinentry-mac if no touchID (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
troyanov committed Aug 4, 2022
1 parent 8b8f5c7 commit 0235243
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
35 changes: 29 additions & 6 deletions go-assuan/pinentry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,28 @@ func (c *Client) Apply(s Settings) {

// GetPIN shows window with password textbox, Cancel and Ok buttons.
// Error is returned if Cancel is pressed.
func (c *Client) GetPIN() (string, error) {
func (c *Client) GetPIN(s Settings) (string, *common.Error) {
if c.qualityBar {
return c.getPINWithQualBar()
pin, err := c.getPINWithQualBar()
if err != nil {
return "", &common.Error{
Src: common.ErrSrcPinentry,
SrcName: "pinentry",
Code: common.ErrCanceled,
Message: err.Error(),
}
}
return pin, nil
}

dat, err := c.Session.SimpleCmd("GETPIN", "")
if err != nil {
return "", err
return "", &common.Error{
Src: common.ErrSrcPinentry,
SrcName: "pinentry",
Code: common.ErrCanceled,
Message: err.Error(),
}
}
return string(dat), nil
}
Expand Down Expand Up @@ -193,12 +207,21 @@ func (c *Client) getPINWithQualBar() (string, error) {

// Confirm shows window with Cancel and Ok buttons but without password
// textbox, error is returned if Cancel is pressed (as usual).
func (c *Client) Confirm() error {
func (c *Client) Confirm(s Settings) (bool, *common.Error) {
_, err := c.Session.SimpleCmd("CONFIRM", "")
return err
if err != nil {
return false, &common.Error{
Src: common.ErrSrcPinentry,
SrcName: "pinentry",
Code: common.ErrCanceled,
Message: err.Error(),
}
}
return true, nil
}

// Message just shows window with only OK button.
func (c *Client) Message() {
func (c *Client) Message(s Settings) *common.Error {
c.Session.SimpleCmd("MESSAGE", "")
return nil
}
18 changes: 15 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,21 @@ func fixPINBinary(oldPath string) error {
func main() {
flag.Parse()
if !sensor.IsTouchIDAvailable() {
fmt.Fprintf(os.Stderr,
"%v pinentry-touchid does not support devices without a Touch ID sensor!\n", emoji.CrossMark)
os.Exit(-1)
client, err := pinentry.LaunchCustom("pinentry-mac")
if err != nil {
fmt.Fprintf(os.Stderr, "Pinentry Launch returned error: %v\n", err)
os.Exit(-1)
}
callbacks := pinentry.Callbacks{
GetPIN: client.GetPIN,
Confirm: client.Confirm,
Msg: client.Message,
}

if err := pinentry.Serve(callbacks, "Hi from pinentry-mac!"); err != nil {
fmt.Fprintf(os.Stderr, "Pinentry Serve returned error: %v\n", err)
os.Exit(-1)
}
}

if *fixSymlink {
Expand Down

0 comments on commit 0235243

Please sign in to comment.