Compare commits
No commits in common. "9ead860d17381767575194f66cc18eb2c5eee029" and "d9316afe6ba42f078398b148c96e624a5dfbb05c" have entirely different histories.
9ead860d17
...
d9316afe6b
|
@ -1,4 +1,4 @@
|
|||
//+build darwin
|
||||
//+build !android !linux
|
||||
|
||||
package main
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
//+build !darwin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
|
||||
"golang.org/x/image/font/gofont/goregular"
|
||||
"golang.org/x/image/font/sfnt"
|
||||
)
|
||||
|
||||
var (
|
||||
regular *sfnt.Font
|
||||
confDir string
|
||||
)
|
||||
|
||||
func init() {
|
||||
regular, err = sfnt.Parse(goregular.TTF)
|
||||
if err != nil {
|
||||
log(Fatal, "Cannot parse default font: ", err)
|
||||
}
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
log(Fatal, "Cannot get current user: ", err)
|
||||
}
|
||||
confDir = path.Join(usr.HomeDir, ".config/passgo")
|
||||
if _, err := os.Stat(confDir); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(confDir, 0700)
|
||||
if err != nil {
|
||||
log(Info, "Cannot create configuration directory ", confDir)
|
||||
log(Fatal, err)
|
||||
} else {
|
||||
log(Info, "Configuration directory created")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -65,7 +65,6 @@ func main() {
|
|||
|
||||
reload = make(chan struct{})
|
||||
updated = make(chan struct{})
|
||||
passch = make(chan []byte)
|
||||
|
||||
go Updater()
|
||||
log(Info, "Staring event loop")
|
||||
|
@ -81,7 +80,6 @@ var (
|
|||
store passgo.Store
|
||||
reload chan struct{}
|
||||
updated chan struct{}
|
||||
passch chan []byte
|
||||
black = color.RGBA{A: 0xff, R: 0, G: 0, B: 0}
|
||||
white = color.RGBA{A: 0xff, R: 0xff, G: 0xff, B: 0xff}
|
||||
gray = color.RGBA{A: 0xff, R: 0xf0, G: 0xf0, B: 0xf0}
|
||||
|
@ -286,13 +284,7 @@ func eventLoop() {
|
|||
Background: darkgray,
|
||||
Alignment: text.Middle,
|
||||
}
|
||||
cleared := &Overlay{Face: face, Text: "clipboard cleared",
|
||||
Color: black,
|
||||
Background: darkgray,
|
||||
Alignment: text.Middle,
|
||||
}
|
||||
overlay := copied
|
||||
var overlayStart time.Time
|
||||
var copiedWhen time.Time
|
||||
|
||||
updateBtns := func() {
|
||||
passBtns = passBtns[:0]
|
||||
|
@ -342,16 +334,6 @@ func eventLoop() {
|
|||
Background: gray,
|
||||
}
|
||||
|
||||
promptLabel := &text.Label{Face: face, Text: "passphrase"}
|
||||
promptEd := &text.Editor{Face: face, SingleLine: true}
|
||||
okBtn := &Button{
|
||||
Face: face,
|
||||
Label: "ok",
|
||||
Alignment: text.End,
|
||||
Color: black,
|
||||
Background: gray,
|
||||
}
|
||||
|
||||
anim := &time.Ticker{}
|
||||
animating := false
|
||||
animOn := func() {
|
||||
|
@ -364,14 +346,8 @@ func eventLoop() {
|
|||
animating = false
|
||||
}
|
||||
|
||||
var listPage, confPage, promptPage, page func()
|
||||
|
||||
prompt := func() []byte {
|
||||
page = promptPage
|
||||
promptEd.SetText("")
|
||||
w.Invalidate()
|
||||
return <-passch
|
||||
}
|
||||
var listPage, confPage, page func()
|
||||
_ = confPage
|
||||
|
||||
listPage = func() {
|
||||
cs = flex.Flexible(1.0)
|
||||
|
@ -397,20 +373,12 @@ func eventLoop() {
|
|||
log(Info, "Clicked ", btn.Label)
|
||||
// don't block UI thread on decryption attempt
|
||||
go func(name string) {
|
||||
p,err := store.Decrypt(name, prompt)
|
||||
//p, err := store.Decrypt(name)
|
||||
//p,err := store.Decrypt(name, prompt)
|
||||
p, err := store.Decrypt(name)
|
||||
if err == nil {
|
||||
passgo.Clip(p)
|
||||
overlayStart = time.Now()
|
||||
overlay = copied
|
||||
copiedWhen = time.Now()
|
||||
animOn()
|
||||
go func() {
|
||||
time.Sleep(time.Second * 45)
|
||||
passgo.Clip("")
|
||||
overlay = cleared
|
||||
overlayStart = time.Now()
|
||||
animOn()
|
||||
}()
|
||||
} else {
|
||||
log(Info, "Can't decrypt ", name)
|
||||
log(Info, err)
|
||||
|
@ -427,27 +395,29 @@ func eventLoop() {
|
|||
page = confPage
|
||||
}
|
||||
flex.Layout(c1, c2)
|
||||
x := time.Since(overlayStart).Seconds()
|
||||
x := time.Since(copiedWhen).Seconds()
|
||||
start, end := 1.5, 1.75
|
||||
switch {
|
||||
case x > start && x < end:
|
||||
fade := (end - x) / (end - start)
|
||||
overlay.Color.R = uint8(float64(black.R) * fade)
|
||||
overlay.Color.G = uint8(float64(black.G) * fade)
|
||||
overlay.Color.B = uint8(float64(black.B) * fade)
|
||||
overlay.Color.A = uint8(float64(black.A) * fade)
|
||||
overlay.Background.R = uint8(float64(darkgray.R) * fade)
|
||||
overlay.Background.G = uint8(float64(darkgray.G) * fade)
|
||||
overlay.Background.B = uint8(float64(darkgray.B) * fade)
|
||||
overlay.Background.A = uint8(float64(darkgray.A) * fade)
|
||||
copied.Color.R = uint8(float64(black.R) * fade)
|
||||
copied.Color.G = uint8(float64(black.G) * fade)
|
||||
copied.Color.B = uint8(float64(black.B) * fade)
|
||||
copied.Color.A = uint8(float64(black.A) * fade)
|
||||
copied.Background.R = uint8(float64(darkgray.R) * fade)
|
||||
copied.Background.G = uint8(float64(darkgray.G) * fade)
|
||||
copied.Background.B = uint8(float64(darkgray.B) * fade)
|
||||
copied.Background.A = uint8(float64(darkgray.A) * fade)
|
||||
fallthrough
|
||||
case x <= start:
|
||||
cs = margincs
|
||||
al := layout.Align{Alignment: layout.SE}
|
||||
cs = al.Begin(ops, cs)
|
||||
cs.Width.Min = cs.Width.Max
|
||||
dims = al.End(overlay.Layout(c, ops, cs))
|
||||
dims = al.End(copied.Layout(c, ops, cs))
|
||||
case animating:
|
||||
copied.Color = black
|
||||
copied.Background = darkgray
|
||||
animOff()
|
||||
}
|
||||
}
|
||||
|
@ -489,41 +459,6 @@ func eventLoop() {
|
|||
}
|
||||
}
|
||||
|
||||
promptPage = func() {
|
||||
cs = flex.Rigid()
|
||||
c2 := flex.End(promptLabel.Layout(ops, cs))
|
||||
cs = flex.Rigid()
|
||||
c3 := flex.End(promptEd.Layout(c, q, ops, cs))
|
||||
cs = flex.Rigid()
|
||||
al := &layout.Align{Alignment: layout.E}
|
||||
cs = al.Begin(ops, cs)
|
||||
btnflx := &layout.Flex{Axis: layout.Horizontal}
|
||||
btnflx.Init(ops, cs)
|
||||
cs = btnflx.Rigid()
|
||||
bc1 := btnflx.End(backBtn.Layout(c, q, ops, cs))
|
||||
cs = btnflx.Rigid()
|
||||
bc2 := btnflx.End(okBtn.Layout(c, q, ops, cs))
|
||||
dims = btnflx.Layout(bc1, bc2)
|
||||
c4 := flex.End(al.End(dims))
|
||||
flex.Layout(c1, c2, c3, c4)
|
||||
if okBtn.Clicked() {
|
||||
log(Info, "Ok")
|
||||
go func() { // do not block UI thread
|
||||
passch <-[]byte(promptEd.Text())
|
||||
}()
|
||||
w.Invalidate()
|
||||
page = listPage
|
||||
}
|
||||
if backBtn.Clicked() {
|
||||
log(Info, "Back")
|
||||
go func() {
|
||||
passch <- nil // cancel prompt
|
||||
}()
|
||||
w.Invalidate()
|
||||
page = listPage
|
||||
}
|
||||
}
|
||||
|
||||
page = listPage
|
||||
|
||||
for {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//+build darwin
|
||||
//+build !android !linux
|
||||
|
||||
package passgo
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
//+build !darwin
|
||||
|
||||
package passgo
|
||||
|
||||
import (
|
||||
"log"
|
||||
)
|
||||
|
||||
//Clip copies a string to the clipboard
|
||||
func Clip(x string) {
|
||||
log(Info,"Clipboard not implemented for this platform")
|
||||
}
|
21
main.go
21
main.go
|
@ -122,18 +122,15 @@ func AskPass(prompts ...func() []byte) openpgp.PromptFunction {
|
|||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
var passphrase []byte
|
||||
dec := func(p *packet.PrivateKey) error {
|
||||
dec := func(p *packet.PrivateKey) {
|
||||
for i := 0; i < 3; i++ {
|
||||
if err := p.Decrypt(passphrase); err == nil {
|
||||
return err
|
||||
if err = p.Decrypt(passphrase); err == nil {
|
||||
break
|
||||
}
|
||||
passphrase = prompt()
|
||||
if passphrase == nil {
|
||||
return fmt.Errorf("Passphrase entry aborted")
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("Passphrase entry failed")
|
||||
}
|
||||
|
||||
var ret openpgp.PromptFunction
|
||||
|
@ -141,20 +138,16 @@ func AskPass(prompts ...func() []byte) openpgp.PromptFunction {
|
|||
if !symmetric {
|
||||
for _, k := range keys {
|
||||
if p := k.PrivateKey; p != nil && p.Encrypted {
|
||||
if err := dec(p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dec(p)
|
||||
}
|
||||
for _, s := range k.Entity.Subkeys {
|
||||
if p := s.PrivateKey; p != nil && p.Encrypted {
|
||||
if err := dec(p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dec(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return passphrase, nil
|
||||
return passphrase, err
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user