mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-01 06:46:33 -04:00
Implement Steam TOTP support using github.com/fortis/go-steam-totp
This commit is contained in:
+25
-4
@@ -3,8 +3,10 @@ package offline
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
steamtotp "github.com/fortis/go-steam-totp"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -27,9 +29,19 @@ func CopyArgument(targetLocation string, field int, executableName string) {
|
||||
if field != 5 { // TODO Update field after removed from notes (breaking sshyp entry compatibility)
|
||||
copySubject = decryptedEntry[field]
|
||||
} else { // TOTP mode
|
||||
var secret string // stores secret for TOTP generation
|
||||
var forSteam bool // indicates whether to generate TOTP in Steam format
|
||||
|
||||
if strings.HasPrefix(decryptedEntry[5], "steam@") {
|
||||
secret = decryptedEntry[5][6:]
|
||||
forSteam = true
|
||||
} else {
|
||||
secret = decryptedEntry[5]
|
||||
}
|
||||
|
||||
for { // keep field copied to clipboard, refresh on 30-second intervals
|
||||
currentTime := time.Now()
|
||||
copyField(genTOTP(decryptedEntry[5], currentTime), "")
|
||||
copyField(genTOTP(secret, currentTime, forSteam), "")
|
||||
// sleep until next 30-second interval
|
||||
time.Sleep(time.Duration(30-(currentTime.Second()%30)) * time.Second)
|
||||
}
|
||||
@@ -56,12 +68,21 @@ func ClipClearArgument() {
|
||||
}
|
||||
}
|
||||
|
||||
// genTOTP generates a TOTP token from a secret
|
||||
func genTOTP(secret string, time time.Time) string {
|
||||
totpToken, err := totp.GenerateCode(secret, time)
|
||||
// genTOTP generates a TOTP token from a secret (supports standard and Steam TOTP)
|
||||
func genTOTP(secret string, time time.Time, forSteam bool) string {
|
||||
var totpToken string
|
||||
var err error
|
||||
|
||||
if forSteam {
|
||||
totpToken, err = steamtotp.GenerateAuthCode(secret, time)
|
||||
} else {
|
||||
totpToken, err = totp.GenerateCode(secret, time)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Error generating TOTP code" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return totpToken
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user