mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-06 09:07:14 -04:00
Split TOTP key generation into its own function
This commit is contained in:
+12
-12
@@ -27,18 +27,8 @@ func CopyArgument(targetLocation string, field int, executableName string) {
|
|||||||
if field != 5 { // TODO Update field after removed from notes (breaking sshyp entry compatibility)
|
if field != 5 { // TODO Update field after removed from notes (breaking sshyp entry compatibility)
|
||||||
copySubject = decryptedEntry[field]
|
copySubject = decryptedEntry[field]
|
||||||
} else { // TOTP mode
|
} else { // TOTP mode
|
||||||
var err error
|
for { // keep field copied to clipboard, refresh on 30-second intervals
|
||||||
var copied bool // track whether the TOTP code has been copied to the clipboard for the first time
|
copyField(genTOTP(decryptedEntry[5]), "")
|
||||||
for { // keep field copied to clipboard, refresh on 30-second intervals
|
|
||||||
copySubject, err = totp.GenerateCode(decryptedEntry[5], time.Now())
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(AnsiError + "Error generating TOTP code" + AnsiReset)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
copyField(copySubject, "")
|
|
||||||
if !copied {
|
|
||||||
copied = true
|
|
||||||
}
|
|
||||||
// sleep until next 30-second interval
|
// sleep until next 30-second interval
|
||||||
time.Sleep(time.Duration(30-(time.Now().Second()%30)) * time.Second)
|
time.Sleep(time.Duration(30-(time.Now().Second()%30)) * time.Second)
|
||||||
}
|
}
|
||||||
@@ -64,3 +54,13 @@ func ClipClearArgument() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// genTOTP generates a TOTP token from a secret
|
||||||
|
func genTOTP(secret string) string {
|
||||||
|
totpToken, err := totp.GenerateCode(secret, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(AnsiError + "Error generating TOTP code" + AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return totpToken
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user