Skip to content

Commit

Permalink
Set GPG_TTY
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikschulz committed Nov 10, 2017
1 parent 2bb2b6a commit f9d83c7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions action/otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (s *Action) OTP(ctx context.Context, c *cli.Context) error {

if c.String("qr") != "" {
var qr []byte
var err error
switch otp.Type() {
case twofactor.OATH_HOTP:
hotp := otp.(*twofactor.HOTP)
Expand All @@ -92,11 +93,12 @@ func (s *Action) OTP(ctx context.Context, c *cli.Context) error {
qr, err = totp.QR(label)
default:
err = errors.New("QR codes can only be generated for OATH OTPs")
}
if err != nil {
return s.exitError(ctx, ExitIO, err, "%s", err)
}

err := ioutil.WriteFile(c.String("qr"), qr, 0600)
if err != nil {
if err := ioutil.WriteFile(c.String("qr"), qr, 0600); err != nil {
return s.exitError(ctx, ExitIO, err, "failed to write QR code: %s", err)
}
}
Expand Down
7 changes: 7 additions & 0 deletions backend/gpg/cli/gpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func New(cfg Config) *GPG {
// this setting should be inherited by sub-processes
umask(077)

// make sure GPG_TTY is set (if possible)
if gt := os.Getenv("GPG_TTY"); gt == "" {
if t := tty(); t != "" {
_ = os.Setenv("GPG_TTY", t)
}
}

if len(cfg.Args) < 1 {
cfg.Args = defaultArgs
}
Expand Down
11 changes: 11 additions & 0 deletions backend/gpg/cli/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -42,3 +43,13 @@ func splitPacket(in string) map[string]string {
}
return m
}

// see https://www.gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html
func tty() string {
fd0 := "/proc/self/fd/0"
dest, err := os.Readlink(fd0)
if err != nil {
return ""
}
return dest
}
1 change: 0 additions & 1 deletion utils/termwiz/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func GetSelection(ctx context.Context, prompt, usage string, choices []string) (
}
defer termbox.Close()

termbox.SetInputMode(termbox.InputEsc)
const coldef = termbox.ColorDefault
termbox.Clear(coldef, coldef)

Expand Down

0 comments on commit f9d83c7

Please sign in to comment.