feat: add timeout to close wallet for the security

This commit is contained in:
Adrien Waksberg 2019-09-01 17:00:19 +02:00
parent 3f9d4850b6
commit 87bfdf0505
2 changed files with 45 additions and 23 deletions

View file

@ -11,6 +11,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
- Test build with travis
- Add entry's fields Create and LastUpdate
- Add timeout to close wallet for the security
### Changed

View file

@ -24,6 +24,7 @@ import (
"os"
"strconv"
"syscall"
"time"
)
// Cli contain config and wallet to use
@ -112,13 +113,24 @@ func (c *Cli) selectEntry() Entry {
return entries[0]
}
c1 := make(chan int, 1)
go func(max int) {
for 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
}
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]
}
@ -244,6 +256,7 @@ func (c *Cli) copyEntry() {
c.loadWallet()
entry := c.selectEntry()
go func() {
for true {
choice := c.input("select one action: ", "", true)
switch choice {
@ -256,6 +269,7 @@ func (c *Cli) copyEntry() {
fmt.Printf("this OTP code is available for %d seconds\n", time)
clipboard.WriteAll(code)
case "q":
clipboard.WriteAll("")
os.Exit(0)
default:
fmt.Println("l -> copy login")
@ -264,6 +278,13 @@ func (c *Cli) copyEntry() {
fmt.Println("q -> quit")
}
}
}()
select {
case <-time.After(90 * time.Second):
clipboard.WriteAll("")
os.Exit(1)
}
}
// Import entries from json file