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

View File

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

View File

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

View File

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

30
main.go
View File

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