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 - 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

View file

@ -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,12 +113,23 @@ func (c *Cli) selectEntry() Entry {
return entries[0] return entries[0]
} }
for true { c1 := make(chan int, 1)
index, err := strconv.Atoi(c.input("Select the entry: ", "", true)) go func(max int) {
if err == nil && index >= 0 && index+1 <= len(entries) { for true {
break index, err := strconv.Atoi(c.input("Select the entry: ", "", true))
if err == nil && index >= 0 && index+1 <= max {
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,25 +256,34 @@ func (c *Cli) copyEntry() {
c.loadWallet() c.loadWallet()
entry := c.selectEntry() entry := c.selectEntry()
for true { go func() {
choice := c.input("select one action: ", "", true) for true {
switch choice { choice := c.input("select one action: ", "", true)
case "l": switch choice {
clipboard.WriteAll(entry.User) case "l":
case "p": clipboard.WriteAll(entry.User)
clipboard.WriteAll(entry.Password) case "p":
case "o": clipboard.WriteAll(entry.Password)
code, time, _ := entry.OTPCode() case "o":
fmt.Printf("this OTP code is available for %d seconds\n", time) code, time, _ := entry.OTPCode()
clipboard.WriteAll(code) fmt.Printf("this OTP code is available for %d seconds\n", time)
case "q": clipboard.WriteAll(code)
os.Exit(0) case "q":
default: clipboard.WriteAll("")
fmt.Println("l -> copy login") os.Exit(0)
fmt.Println("p -> copy password") default:
fmt.Println("o -> copy OTP code") fmt.Println("l -> copy login")
fmt.Println("q -> quit") fmt.Println("p -> copy password")
fmt.Println("o -> copy OTP code")
fmt.Println("q -> quit")
}
} }
}()
select {
case <-time.After(90 * time.Second):
clipboard.WriteAll("")
os.Exit(1)
} }
} }