39 lines
594 B
Go
39 lines
594 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.cycore.io/scm/pass-totp/internal/otp"
|
|
)
|
|
|
|
type Token struct {
|
|
Token string `json:"token"`
|
|
TTLSeconds uint64 `json:"ttl_seconds"`
|
|
}
|
|
|
|
func main() {
|
|
var key string
|
|
|
|
fmt.Scan(&key)
|
|
|
|
key = strings.ToUpper(key)
|
|
|
|
totp := &otp.TOTP{
|
|
Secret: key,
|
|
IsBase32Secret: true,
|
|
}
|
|
|
|
token := totp.Get()
|
|
|
|
if err := json.NewEncoder(os.Stdout).Encode(&Token{
|
|
Token: token,
|
|
TTLSeconds: uint64(30 - time.Now().Unix()%30),
|
|
}); err != nil {
|
|
log.Println("failed to encode token to json:", err)
|
|
}
|
|
}
|