Fix animation code. Retry GPG agent password prompt and clear
cache if the passphrase does not work.
This commit is contained in:
parent
666d127584
commit
b9e9373b04
|
@ -15,7 +15,7 @@ err := passgo.GetStore(&store)
|
||||||
if err != nil { ... }
|
if err != nil { ... }
|
||||||
passlist := store.List()
|
passlist := store.List()
|
||||||
for _,x := range passlist {
|
for _,x := range passlist {
|
||||||
if x.Pathname = "myPass" {
|
if x.Pathname == "myPass" {
|
||||||
p, err := store.Decrypt(x.Pathname)
|
p, err := store.Decrypt(x.Pathname)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
passgo.Clip(p) // put on the clipboard
|
passgo.Clip(p) // put on the clipboard
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
|
|
||||||
type conf struct {
|
type conf struct {
|
||||||
StoreDir string
|
StoreDir string
|
||||||
|
ClearDelay int
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -50,6 +51,9 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(Fatal, err)
|
log(Fatal, err)
|
||||||
}
|
}
|
||||||
|
if Config.ClearDelay == 0 {
|
||||||
|
Config.ClearDelay = 45
|
||||||
|
}
|
||||||
|
|
||||||
if fd != nil { // we still have an empty conf file open:
|
if fd != nil { // we still have an empty conf file open:
|
||||||
Config.StoreDir = store.Dir
|
Config.StoreDir = store.Dir
|
||||||
|
@ -156,13 +160,8 @@ func eventLoop() {
|
||||||
titleflex := &layout.Flex{Axis: layout.Horizontal}
|
titleflex := &layout.Flex{Axis: layout.Horizontal}
|
||||||
|
|
||||||
flex := &layout.Flex{Axis: layout.Vertical}
|
flex := &layout.Flex{Axis: layout.Vertical}
|
||||||
passInput := &text.Editor{Face: face, SingleLine: true}
|
|
||||||
passInput.SetText("passphrase")
|
|
||||||
passSubmit := &Button{Face: face, Label: "submit", Color: black}
|
|
||||||
lst := &layout.List{Axis: layout.Vertical}
|
lst := &layout.List{Axis: layout.Vertical}
|
||||||
passBtns := make([]*Button, 0)
|
passBtns := make([]*Button, 0)
|
||||||
_ = passInput
|
|
||||||
_ = passSubmit
|
|
||||||
pathnames := make([]string, 0)
|
pathnames := make([]string, 0)
|
||||||
copied := &Overlay{Face: face, Text: "copied to clipboard",
|
copied := &Overlay{Face: face, Text: "copied to clipboard",
|
||||||
Color: black,
|
Color: black,
|
||||||
|
@ -226,7 +225,7 @@ func eventLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
promptLabel := &text.Label{Face: face, Text: "passphrase"}
|
promptLabel := &text.Label{Face: face, Text: "passphrase"}
|
||||||
promptEd := &text.Editor{Face: face, SingleLine: true}
|
promptEd := &text.Editor{Face: face, SingleLine: true, Submit: true}
|
||||||
okBtn := &Button{
|
okBtn := &Button{
|
||||||
Face: face,
|
Face: face,
|
||||||
Label: "ok",
|
Label: "ok",
|
||||||
|
@ -238,11 +237,13 @@ func eventLoop() {
|
||||||
anim := &time.Ticker{}
|
anim := &time.Ticker{}
|
||||||
animating := false
|
animating := false
|
||||||
animOn := func() {
|
animOn := func() {
|
||||||
|
log(Info,"animOn()")
|
||||||
anim = time.NewTicker(time.Second / 120)
|
anim = time.NewTicker(time.Second / 120)
|
||||||
animating = true
|
animating = true
|
||||||
w.Invalidate()
|
w.Invalidate()
|
||||||
}
|
}
|
||||||
animOff := func() {
|
animOff := func() {
|
||||||
|
log(Info,"animOff()")
|
||||||
anim.Stop()
|
anim.Stop()
|
||||||
animating = false
|
animating = false
|
||||||
}
|
}
|
||||||
|
@ -286,13 +287,13 @@ func eventLoop() {
|
||||||
passgo.Clip(p)
|
passgo.Clip(p)
|
||||||
overlayStart = time.Now()
|
overlayStart = time.Now()
|
||||||
overlay = copied
|
overlay = copied
|
||||||
|
overlay.Color = black
|
||||||
|
overlay.Background = darkgray
|
||||||
animOn()
|
animOn()
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Second * 45)
|
time.Sleep(time.Second * time.Duration(Config.ClearDelay))
|
||||||
|
log(Info, "clearing clipboard")
|
||||||
passgo.Clip("")
|
passgo.Clip("")
|
||||||
overlay = cleared
|
|
||||||
overlayStart = time.Now()
|
|
||||||
animOn()
|
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
log(Info, "Can't decrypt ", name)
|
log(Info, "Can't decrypt ", name)
|
||||||
|
@ -311,10 +312,19 @@ func eventLoop() {
|
||||||
}
|
}
|
||||||
flex.Layout(c1, c2)
|
flex.Layout(c1, c2)
|
||||||
x := time.Since(overlayStart).Seconds()
|
x := time.Since(overlayStart).Seconds()
|
||||||
start, end := 1.5, 1.75
|
fade1a, fade1b := 1.5, 1.75
|
||||||
|
start2 := float64(Config.ClearDelay)
|
||||||
|
fade2a, end := start2 + 1.5, start2 + 1.75
|
||||||
switch {
|
switch {
|
||||||
case x > start && x < end:
|
case x > fade1a && x < fade1b ||
|
||||||
fade := (end - x) / (end - start)
|
x > fade2a && x < end:
|
||||||
|
var fade float64
|
||||||
|
switch {
|
||||||
|
case x < fade1b:
|
||||||
|
fade = (fade1b - x) / (fade1b - fade1a)
|
||||||
|
case x > fade2a:
|
||||||
|
fade = (end - x) / (end - fade2a)
|
||||||
|
}
|
||||||
overlay.Color.R = uint8(float64(black.R) * fade)
|
overlay.Color.R = uint8(float64(black.R) * fade)
|
||||||
overlay.Color.G = uint8(float64(black.G) * fade)
|
overlay.Color.G = uint8(float64(black.G) * fade)
|
||||||
overlay.Color.B = uint8(float64(black.B) * fade)
|
overlay.Color.B = uint8(float64(black.B) * fade)
|
||||||
|
@ -324,13 +334,19 @@ func eventLoop() {
|
||||||
overlay.Background.B = uint8(float64(darkgray.B) * fade)
|
overlay.Background.B = uint8(float64(darkgray.B) * fade)
|
||||||
overlay.Background.A = uint8(float64(darkgray.A) * fade)
|
overlay.Background.A = uint8(float64(darkgray.A) * fade)
|
||||||
fallthrough
|
fallthrough
|
||||||
case x <= start:
|
case x <= fade1b ||
|
||||||
|
x > start2 && x < end:
|
||||||
|
if x > start2 && overlay == copied {
|
||||||
|
overlay = cleared
|
||||||
|
overlay.Color = black
|
||||||
|
overlay.Background = darkgray
|
||||||
|
}
|
||||||
cs = margincs
|
cs = margincs
|
||||||
al := layout.Align{Alignment: layout.SE}
|
al := layout.Align{Alignment: layout.SE}
|
||||||
cs = al.Begin(ops, cs)
|
cs = al.Begin(ops, cs)
|
||||||
cs.Width.Min = cs.Width.Max
|
cs.Width.Min = cs.Width.Max
|
||||||
dims = al.End(overlay.Layout(c, ops, cs))
|
dims = al.End(overlay.Layout(c, ops, cs))
|
||||||
case animating:
|
case animating && x > end:
|
||||||
animOff()
|
animOff()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,6 +389,14 @@ func eventLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
promptPage = func() {
|
promptPage = func() {
|
||||||
|
submit := false
|
||||||
|
for e, ok := promptEd.Next(c, q); ok; e, ok = promptEd.Next(c, q) {
|
||||||
|
switch e.(type) {
|
||||||
|
case text.SubmitEvent:
|
||||||
|
log(Info, "Submit")
|
||||||
|
submit = true
|
||||||
|
}
|
||||||
|
}
|
||||||
cs = flex.Rigid()
|
cs = flex.Rigid()
|
||||||
c2 := flex.End(promptLabel.Layout(ops, cs))
|
c2 := flex.End(promptLabel.Layout(ops, cs))
|
||||||
cs = flex.Rigid()
|
cs = flex.Rigid()
|
||||||
|
@ -389,7 +413,7 @@ func eventLoop() {
|
||||||
dims = btnflx.Layout(bc1, bc2)
|
dims = btnflx.Layout(bc1, bc2)
|
||||||
c4 := flex.End(al.End(dims))
|
c4 := flex.End(al.End(dims))
|
||||||
flex.Layout(c1, c2, c3, c4)
|
flex.Layout(c1, c2, c3, c4)
|
||||||
if okBtn.Clicked() {
|
if submit || okBtn.Clicked() {
|
||||||
log(Info, "Ok")
|
log(Info, "Ok")
|
||||||
go func() { // do not block UI thread
|
go func() { // do not block UI thread
|
||||||
passch <-[]byte(promptEd.Text())
|
passch <-[]byte(promptEd.Text())
|
||||||
|
|
24
main.go
24
main.go
|
@ -126,13 +126,16 @@ func AskPass(prompts ...func() []byte) openpgp.PromptFunction {
|
||||||
dec := func(p *packet.PrivateKey) error {
|
dec := func(p *packet.PrivateKey) error {
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
if err := p.Decrypt(passphrase); err == nil {
|
if err := p.Decrypt(passphrase); err == nil {
|
||||||
|
passphrase = nil
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
passphrase = prompt()
|
passphrase = prompt()
|
||||||
if passphrase == nil {
|
if passphrase == nil {
|
||||||
|
passphrase = nil
|
||||||
return fmt.Errorf("Passphrase entry aborted")
|
return fmt.Errorf("Passphrase entry aborted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
passphrase = nil
|
||||||
return fmt.Errorf("Passphrase entry failed")
|
return fmt.Errorf("Passphrase entry failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,15 +173,20 @@ func GPGPrompt(keys []openpgp.Key, symmetric bool) ([]byte, error) {
|
||||||
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}
|
||||||
passphrase, err := conn.GetPassphrase(&request)
|
for i := 0; i < 3; i++ {
|
||||||
if err != nil {
|
var passphrase string
|
||||||
return nil, err
|
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
|
||||||
}
|
}
|
||||||
err = key.PrivateKey.Decrypt([]byte(passphrase))
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return []byte(passphrase), nil
|
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("Unable to find key")
|
return nil, fmt.Errorf("Unable to find key")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user