Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Update pinentry dependency and add Windows support (#113)
Browse files Browse the repository at this point in the history
* add windows build
* Swap pinentry library tp twpayne/go-pinentry as gopasspw/pinentry is deprecated
* cmd/login: Use `pinentry-mac` on Darwin, regardless.
* Bump version

Co-authored-by: paul david <[email protected]>
  • Loading branch information
lokulin and toothbrush committed Aug 18, 2022
1 parent 893d304 commit e2a87f5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ builds:
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION ?= 1.6.0
VERSION ?= 1.6.1
GIT_HASH = $(shell git rev-parse --short HEAD)
DELIVERY_ENGINEERING_GPG_KEY = 0x877817E441F4F9B0

Expand Down
33 changes: 24 additions & 9 deletions cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"runtime"
"strconv"
"strings"
"syscall"
"time"

"github.com/gopasspw/pinentry"
"github.com/spf13/viper"
"github.com/twpayne/go-pinentry"
"golang.org/x/crypto/ssh/terminal"

"github.com/redbubble/yak/cache"
Expand Down Expand Up @@ -409,19 +411,32 @@ func promptOrPinentry(prompt string, secret bool) (string, error) {
}

func getPinentry(prompt string, secret bool) (string, error) {
p, err := pinentry.New()
clientOptions := pinentry.WithBinaryNameFromGnuPGAgentConf()

// Rather that rely on darwin users having a gpgagent conf just look for pinentry-mac.
// Simplifies config for the most common use case.
// Users that are specifically asking for pinentry to be used almost certainly need the GUI version, whereas the default is the CLI version. This is for e.g., GUI database clients that call yak in the background where stdout and stdin are unavailable.
if runtime.GOOS == "darwin" {
pinentry_absolute, err := exec.LookPath("pinentry-mac")
if err != nil {
return "", err
}
clientOptions = pinentry.WithBinaryName(pinentry_absolute)
}

p, err := pinentry.NewClient(clientOptions,
pinentry.WithDesc(prompt),
pinentry.WithPrompt(""),
pinentry.WithTitle("Yak"))

if err != nil {
return "", fmt.Errorf("pinentry (%s) error: %w", pinentry.GetBinary(), err)
return "", fmt.Errorf("pinentry error: %w", err)
}
defer p.Close()

_ = p.Set("title", "yak")
_ = p.Set("desc", prompt)
_ = p.Set("prompt", "Input:")
_ = p.Set("ok", "OK")
pw, err := p.GetPin()
pw, _, err := p.GetPIN()
if err != nil {
return "", fmt.Errorf("pinentry (%s) error: %w", pinentry.GetBinary(), err)
return "", fmt.Errorf("pinentry error: %w", err)
}

pass := string(pw)
Expand Down
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/redbubble/yak
go 1.18

require (
github.com/aws/aws-sdk-go v1.44.78
github.com/gopasspw/pinentry v0.0.2
github.com/aws/aws-sdk-go v1.44.79
github.com/mitchellh/go-homedir v1.1.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.12.0
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
github.com/twpayne/go-pinentry v0.2.0
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8
golang.org/x/net v0.0.0-20220812174116-3211cb980234
)

Expand All @@ -20,14 +20,19 @@ require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.3 // indirect
github.com/rs/zerolog v1.27.0 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.7 // indirect
Expand All @@ -36,5 +41,3 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/gopasspw/pinentry => github.com/redbubble/pinentry v0.0.3-0.20211015012734-36081cf01f93
Loading

0 comments on commit e2a87f5

Please sign in to comment.