This commit is contained in:
Greg 2019-09-10 11:36:03 -04:00
parent 2c4c708b3a
commit 12b57d263f
5 changed files with 51 additions and 53 deletions

View File

@ -84,7 +84,7 @@ var (
store passgo.Store store passgo.Store
reload chan struct{} reload chan struct{}
updated chan struct{} updated chan struct{}
chdir chan struct{} chdir chan struct{}
passch chan []byte passch chan []byte
) )
@ -223,7 +223,7 @@ func eventLoop() {
log(Info, err) log(Info, err)
return return
} }
for i,n := range ids { for i, n := range ids {
if i >= len(idBtns) { if i >= len(idBtns) {
idBtns = append(idBtns, &Button{ idBtns = append(idBtns, &Button{
Face: face, Face: face,
@ -443,7 +443,7 @@ func eventLoop() {
c2 := flex.End(idLabel.Layout(ops, cs)) c2 := flex.End(idLabel.Layout(ops, cs))
var c3 layout.FlexChild var c3 layout.FlexChild
//if len(idBtns) == 0 { //if len(idBtns) == 0 {
updateIdBtns() updateIdBtns()
//} //}
cs = flex.Rigid() cs = flex.Rigid()
if len(idBtns) == 0 { // still zero after update if len(idBtns) == 0 { // still zero after update
@ -496,7 +496,7 @@ func eventLoop() {
insValue = passvalEd.Text() insValue = passvalEd.Text()
for _, n := range pathnames { for _, n := range pathnames {
if insName == n { if insName == n {
log(Info,"Password exists") log(Info, "Password exists")
page = confirmPage page = confirmPage
w.Invalidate() w.Invalidate()
return return

View File

@ -69,7 +69,7 @@ func main() {
if opts.clip { if opts.clip {
passgo.Clip(p) passgo.Clip(p)
} else { } else {
fmt.Print(p) fmt.Println(p)
} }
default: default:
usage() usage()

View File

@ -22,4 +22,3 @@ func (s *Store) nativeEncrypt(pw string) ([]byte, error) {
func nativeIdentities() ([]string, error) { func nativeIdentities() ([]string, error) {
return nil, fmt.Errorf("NOT IMPLEMENTED") return nil, fmt.Errorf("NOT IMPLEMENTED")
} }

View File

@ -11,14 +11,14 @@ import (
"os/exec" "os/exec"
"os/user" "os/user"
"path" "path"
"strings"
"strconv" "strconv"
"strings"
"sync" "sync"
"golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp"
"github.com/jcmdev0/gpgagent"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/jcmdev0/gpgagent"
) )
func (s *Store) nativeDecrypt(name string) (string, error) { func (s *Store) nativeDecrypt(name string) (string, error) {
@ -51,7 +51,7 @@ func (s *Store) nativeEncrypt(pw string) ([]byte, error) {
} }
var ( var (
idMux sync.Mutex idMux sync.Mutex
cachedIdentities []string cachedIdentities []string
) )
@ -59,11 +59,11 @@ func nativeIdentities() ([]string, error) {
idMux.Lock() idMux.Lock()
defer idMux.Unlock() defer idMux.Unlock()
if cachedIdentities != nil { if cachedIdentities != nil {
ret := make([]string,len(cachedIdentities)) ret := make([]string, len(cachedIdentities))
copy(ret, cachedIdentities) copy(ret, cachedIdentities)
return ret, nil return ret, nil
} }
ret := make([]string,0) ret := make([]string, 0)
fmt.Println("calling gpg") fmt.Println("calling gpg")
output, err := exec.Command("gpg", "--list-secret-keys", "--with-colons").Output() output, err := exec.Command("gpg", "--list-secret-keys", "--with-colons").Output()
if err != nil { if err != nil {
@ -71,9 +71,9 @@ func nativeIdentities() ([]string, error) {
} }
scanner := bufio.NewScanner(bytes.NewBuffer(output)) scanner := bufio.NewScanner(bytes.NewBuffer(output))
for scanner.Scan() { for scanner.Scan() {
fs := strings.Split(scanner.Text(),":") fs := strings.Split(scanner.Text(), ":")
if fs[0] == "uid" { if fs[0] == "uid" {
fmt.Printf("%s: %s\n",fs[0], fs[9]) fmt.Printf("%s: %s\n", fs[0], fs[9])
ret = append(ret, fs[9]) ret = append(ret, fs[9])
} }
} }
@ -151,31 +151,31 @@ func setAgentInfo() {
} }
func GPGPrompt(keys []openpgp.Key, symmetric bool) ([]byte, error) { func GPGPrompt(keys []openpgp.Key, symmetric bool) ([]byte, error) {
conn, err := gpgagent.NewGpgAgentConn() conn, err := gpgagent.NewGpgAgentConn()
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer conn.Close() defer conn.Close()
for _, key := range keys { for _, key := range keys {
cacheId := strings.ToUpper(hex.EncodeToString(key.PublicKey.Fingerprint[:])) cacheId := strings.ToUpper(hex.EncodeToString(key.PublicKey.Fingerprint[:]))
request := gpgagent.PassphraseRequest{CacheKey: cacheId} request := gpgagent.PassphraseRequest{CacheKey: cacheId}
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
var passphrase string var passphrase string
passphrase, err = conn.GetPassphrase(&request) passphrase, err = conn.GetPassphrase(&request)
if err != nil { if err != nil {
continue continue
} }
err = key.PrivateKey.Decrypt([]byte(passphrase)) err = key.PrivateKey.Decrypt([]byte(passphrase))
if err != nil { if err != nil {
conn.RemoveFromCache(cacheId) conn.RemoveFromCache(cacheId)
continue continue
} }
return []byte(passphrase), nil return []byte(passphrase), nil
} }
return nil, err return nil, err
} }
return nil, fmt.Errorf("Unable to find key") return nil, fmt.Errorf("Unable to find key")
} }
func init() { func init() {
@ -211,4 +211,3 @@ func Clip(x string) {
cmd.Stdin = b cmd.Stdin = b
cmd.Run() cmd.Run()
} }

30
main.go
View File

@ -19,12 +19,12 @@ import (
) )
var ( var (
basename *regexp.Regexp basename *regexp.Regexp
ask openpgp.PromptFunction ask openpgp.PromptFunction
Keyring openpgp.KeyRing Keyring openpgp.KeyRing
krTime time.Time krTime time.Time
useNative bool useNative bool
homeDir string homeDir string
) )
func init() { func init() {
@ -33,8 +33,8 @@ func init() {
} }
type Store struct { type Store struct {
Dir string Dir string
Id string Id string
Empty bool Empty bool
} }
@ -107,7 +107,7 @@ func (s *Store) SetID(id string) error {
return err return err
} }
} }
return ioutil.WriteFile(path.Join(s.Dir, ".gpg-id"), []byte(id + "\n"), 0644) return ioutil.WriteFile(path.Join(s.Dir, ".gpg-id"), []byte(id+"\n"), 0644)
} }
type caseInsensitive []os.FileInfo type caseInsensitive []os.FileInfo
@ -279,11 +279,11 @@ func (s *Store) Insert(name, value string) error {
var enc []byte var enc []byte
var err error var err error
//if useNative { // golang openpgp code not implemented yet //if useNative { // golang openpgp code not implemented yet
fmt.Println("Calling nativeEncrypt") fmt.Println("Calling nativeEncrypt")
enc, err = s.nativeEncrypt(value) enc, err = s.nativeEncrypt(value)
if err != nil { if err != nil {
return err return err
} }
//} //}
return ioutil.WriteFile(path.Join(s.Dir, name + ".gpg"), enc, 0644) return ioutil.WriteFile(path.Join(s.Dir, name+".gpg"), enc, 0644)
} }