123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package main
- import (
- "flag"
- "fmt"
- "log"
- "net"
- "os"
- "os/signal"
- "path"
- "syscall"
- "github.com/ncruces/zenity"
- "golang.org/x/crypto/ssh/agent"
- )
- func confirm(comment string) bool {
- return zenity.Question(
- fmt.Sprintf("Are you sure you want to allow using the SSH key '%s'?", comment),
- zenity.Title("Allow SSH Key"),
- zenity.QuestionIcon,
- ) == nil
- }
- func getTmpDir() string {
- dir, ok := os.LookupEnv("XDG_RUNTIME_DIR")
- if ok {
- return dir
- }
- dir, ok = os.LookupEnv("TMPDIR")
- if ok {
- return dir
- }
- return "/tmp"
- }
- func main() {
- sock := flag.String(
- "sock",
- path.Join(getTmpDir(), "agent.sock"),
- "Path to socket",
- )
- secretiveSock := flag.String(
- "secretive-sock",
- path.Join(os.Getenv("HOME"), "Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh"),
- "Path to secretive agent socket",
- )
- keyring := NewKeyring(confirm)
- conn, err := net.Dial("unix", *secretiveSock)
- if err != nil {
- log.Fatal(err)
- }
- secretive := agent.NewClient(conn)
- proxy := NewProxy(secretive, keyring)
- socket, err := net.Listen("unix", *sock)
- if err != nil {
- log.Fatal(err)
- }
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt, syscall.SIGTERM)
- go func() {
- <-c
- os.Remove(*sock)
- os.Exit(1)
- }()
- for {
- conn, err := socket.Accept()
- if err != nil {
- log.Fatal(err)
- }
- agent.ServeAgent(proxy, conn)
- }
- }
|