feat: add timeout to close wallet for the security
This commit is contained in:
parent
3f9d4850b6
commit
87bfdf0505
2 changed files with 45 additions and 23 deletions
|
@ -11,6 +11,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
||||||
|
|
||||||
- Test build with travis
|
- Test build with travis
|
||||||
- Add entry's fields Create and LastUpdate
|
- Add entry's fields Create and LastUpdate
|
||||||
|
- Add timeout to close wallet for the security
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
23
gpm/cli.go
23
gpm/cli.go
|
@ -24,6 +24,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cli contain config and wallet to use
|
// Cli contain config and wallet to use
|
||||||
|
@ -112,13 +113,24 @@ func (c *Cli) selectEntry() Entry {
|
||||||
return entries[0]
|
return entries[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c1 := make(chan int, 1)
|
||||||
|
go func(max int) {
|
||||||
for true {
|
for true {
|
||||||
index, err := strconv.Atoi(c.input("Select the entry: ", "", true))
|
index, err := strconv.Atoi(c.input("Select the entry: ", "", true))
|
||||||
if err == nil && index >= 0 && index+1 <= len(entries) {
|
if err == nil && index >= 0 && index+1 <= max {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
fmt.Println("your choice is not an integer or is out of range")
|
fmt.Println("your choice is not an integer or is out of range")
|
||||||
}
|
}
|
||||||
|
c1 <- index
|
||||||
|
}(len(entries))
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-c1:
|
||||||
|
index = res
|
||||||
|
case <-time.After(30 * time.Second):
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
return entries[index]
|
return entries[index]
|
||||||
}
|
}
|
||||||
|
@ -244,6 +256,7 @@ func (c *Cli) copyEntry() {
|
||||||
c.loadWallet()
|
c.loadWallet()
|
||||||
entry := c.selectEntry()
|
entry := c.selectEntry()
|
||||||
|
|
||||||
|
go func() {
|
||||||
for true {
|
for true {
|
||||||
choice := c.input("select one action: ", "", true)
|
choice := c.input("select one action: ", "", true)
|
||||||
switch choice {
|
switch choice {
|
||||||
|
@ -256,6 +269,7 @@ func (c *Cli) copyEntry() {
|
||||||
fmt.Printf("this OTP code is available for %d seconds\n", time)
|
fmt.Printf("this OTP code is available for %d seconds\n", time)
|
||||||
clipboard.WriteAll(code)
|
clipboard.WriteAll(code)
|
||||||
case "q":
|
case "q":
|
||||||
|
clipboard.WriteAll("")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
default:
|
default:
|
||||||
fmt.Println("l -> copy login")
|
fmt.Println("l -> copy login")
|
||||||
|
@ -264,6 +278,13 @@ func (c *Cli) copyEntry() {
|
||||||
fmt.Println("q -> quit")
|
fmt.Println("q -> quit")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-time.After(90 * time.Second):
|
||||||
|
clipboard.WriteAll("")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import entries from json file
|
// Import entries from json file
|
||||||
|
|
Loading…
Reference in a new issue