-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
59 lines (49 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"io"
"os"
"github.com/foxcpp/go-assuan/pinentry"
"github.com/apex/log"
"github.com/apex/log/handlers/discard"
"github.com/apex/log/handlers/json"
)
const pmp = "/usr/local/MacGPG2/libexec/pinentry-mac.app/Contents/MacOS/pinentry-mac"
// File path to write debug info to, use
//
// go install -ldflags "-X main.logfile=$HOME/pinentry.log"
//
// to build with debug output.
var logfile = ""
func main() {
var err error
// Logging setup
if logfile != "" {
var f *os.File
f, err = os.OpenFile(logfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
defer func() {
err = f.Close()
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}()
log.SetHandler(json.New(f))
} else {
log.SetHandler(discard.New())
}
cbks := pinentry.Callbacks{
// Where the hijacking happens
GetPIN: GetPIN,
// Pass through functions
Confirm: Confirm,
Msg: Message,
}
err = pinentry.Serve(cbks, "pinentry-map-keychain")
if err != nil && err != io.EOF {
log.WithError(err).Error("Failed to run pinentry.Serve")
os.Exit(1)
}
}