Initial commit
This commit is contained in:
commit
aa6b79e2cd
|
@ -0,0 +1,25 @@
|
|||
import otp
|
||||
import os
|
||||
|
||||
when isMainModule:
|
||||
var
|
||||
args = commandLineParams()
|
||||
|
||||
if args.len != 1:
|
||||
quit "I need a machine name"
|
||||
|
||||
try:
|
||||
var
|
||||
keyFileName = args[0]
|
||||
fin = open getEnv("HOME") / "life" / "crypto" / "totp" / keyFileName
|
||||
key = fin.readLine
|
||||
totp = newTotp key
|
||||
|
||||
echo totp.now()
|
||||
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
quit "Couldn't do that for " & args[0] & ". Does that machine exist in the store?"
|
||||
|
||||
else:
|
||||
quit "invalid"
|
|
@ -0,0 +1,20 @@
|
|||
import base32
|
||||
import nuuid
|
||||
import otp
|
||||
import random
|
||||
import strutils
|
||||
|
||||
var res = generateUUID().replace("-")[0 .. 19]
|
||||
|
||||
try:
|
||||
discard newTOTP(encode res).now()
|
||||
except:
|
||||
quit "it failed"
|
||||
|
||||
echo encode res
|
||||
echo """" RATE_LIMIT 3 30 1441950209
|
||||
" WINDOW_SIZE 3
|
||||
" DISALLOW_REUSE 48065007
|
||||
" TOTP_AUTH"""
|
||||
for i in countup(0, 4, 1):
|
||||
echo randomInt(10000000, 99999999)
|
|
@ -0,0 +1,87 @@
|
|||
import os
|
||||
import parseopt2
|
||||
|
||||
# Subcommands
|
||||
import cmds/code
|
||||
import cmds/gen
|
||||
|
||||
const usageHelp =
|
||||
"""Usage: totptool [options] <command> [args]
|
||||
|
||||
Options:
|
||||
-h --help Show this screen
|
||||
-r --root:path Use path as the totp root for Nim
|
||||
-v --version Show version of totptool
|
||||
|
||||
Subcommands:
|
||||
code <name>
|
||||
Generate a two-factor auth code for <name>
|
||||
|
||||
gen <name>
|
||||
Generate a new two-factor auth secret for
|
||||
<name>
|
||||
|
||||
ls
|
||||
List all the names of the secrets that
|
||||
totptool tracks
|
||||
"""
|
||||
|
||||
proc writeHelp() =
|
||||
echo usageHelp
|
||||
quit 2
|
||||
|
||||
proc writeVersion() =
|
||||
const
|
||||
gitlog = staticExec "git log -1"
|
||||
|
||||
echo gitlog
|
||||
quit 1
|
||||
|
||||
var
|
||||
totpRoot: string = getHomeDir() / "life" / "crypto" / "totp"
|
||||
command: string
|
||||
args: seq[string]
|
||||
|
||||
for kind, key, val in getopt():
|
||||
case kind
|
||||
of cmdArgument:
|
||||
if command == nil:
|
||||
command = key
|
||||
else:
|
||||
args = args & key
|
||||
|
||||
of cmdLongOption, cmdShortOption:
|
||||
case key
|
||||
of "help", "h":
|
||||
case command
|
||||
of "code":
|
||||
code.help()
|
||||
of "gen":
|
||||
gen.help()
|
||||
of "ls": discard
|
||||
else:
|
||||
writeHelp()
|
||||
|
||||
of "version", "v": writeVersion()
|
||||
of "root", "r":
|
||||
totpRoot = val
|
||||
else: discard
|
||||
|
||||
of cmdEnd: assert(false) # cannot happen
|
||||
|
||||
if command == nil:
|
||||
writeHelp()
|
||||
else: discard
|
||||
|
||||
if not existsDir(totpRoot):
|
||||
totpRoot.createDir
|
||||
echo "Created totp root " & totpRoot
|
||||
|
||||
case command
|
||||
of "code":
|
||||
code(totpRoot, args)
|
||||
of "gen":
|
||||
gen(totpRoot, args)
|
||||
else:
|
||||
echo "Command " & command & " not found."
|
||||
writeHelp()
|
|
@ -0,0 +1,10 @@
|
|||
[Package]
|
||||
name = "totptool"
|
||||
version = "0.1.0"
|
||||
author = "Anonymous"
|
||||
description = "New Nimble project for Nim"
|
||||
license = "MIT"
|
||||
bin = "totptool"
|
||||
|
||||
[Deps]
|
||||
Requires: "nim >= 0.10.0, otp"
|
Loading…
Reference in New Issue