basic functionality
This commit is contained in:
parent
aa6b79e2cd
commit
506b46e0fe
|
@ -0,0 +1,2 @@
|
||||||
|
nimcache/
|
||||||
|
totptool
|
|
@ -0,0 +1,19 @@
|
||||||
|
Copyright (c) 2015 Christine Dodrill <xena@yolo-swag.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
|
@ -1,17 +1,25 @@
|
||||||
import otp
|
import otp
|
||||||
import os
|
import os
|
||||||
|
|
||||||
when isMainModule:
|
const codeUsage =
|
||||||
var
|
"""Usage: totptool code <name>
|
||||||
args = commandLineParams()
|
|
||||||
|
|
||||||
|
This will generate a TOTP code for the given secret
|
||||||
|
name in the secret store.
|
||||||
|
"""
|
||||||
|
|
||||||
|
proc help*() =
|
||||||
|
echo codeUsage
|
||||||
|
quit 2
|
||||||
|
|
||||||
|
proc code*(root: string, args: seq[string]) =
|
||||||
if args.len != 1:
|
if args.len != 1:
|
||||||
quit "I need a machine name"
|
quit "I need a machine name"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
var
|
var
|
||||||
keyFileName = args[0]
|
keyFileName = args[0]
|
||||||
fin = open getEnv("HOME") / "life" / "crypto" / "totp" / keyFileName
|
fin = open root / keyFileName
|
||||||
key = fin.readLine
|
key = fin.readLine
|
||||||
totp = newTotp key
|
totp = newTotp key
|
||||||
|
|
||||||
|
@ -20,6 +28,3 @@ when isMainModule:
|
||||||
except:
|
except:
|
||||||
echo getCurrentExceptionMsg()
|
echo getCurrentExceptionMsg()
|
||||||
quit "Couldn't do that for " & args[0] & ". Does that machine exist in the store?"
|
quit "Couldn't do that for " & args[0] & ". Does that machine exist in the store?"
|
||||||
|
|
||||||
else:
|
|
||||||
quit "invalid"
|
|
||||||
|
|
52
cmds/gen.nim
52
cmds/gen.nim
|
@ -1,20 +1,48 @@
|
||||||
import base32
|
import base32
|
||||||
import nuuid
|
import nuuid
|
||||||
|
import os
|
||||||
import otp
|
import otp
|
||||||
import random
|
import random
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
var res = generateUUID().replace("-")[0 .. 19]
|
const genUsage =
|
||||||
|
"""Usage: totptool gen <name>
|
||||||
|
|
||||||
try:
|
This will generate a new secret and recovery codes
|
||||||
discard newTOTP(encode res).now()
|
for a given service name. This will then write it
|
||||||
except:
|
to your configured secret store and make it
|
||||||
quit "it failed"
|
available for `totptool code` instantly.
|
||||||
|
"""
|
||||||
|
|
||||||
echo encode res
|
proc help*() =
|
||||||
echo """" RATE_LIMIT 3 30 1441950209
|
echo genUsage
|
||||||
" WINDOW_SIZE 3
|
quit 2
|
||||||
" DISALLOW_REUSE 48065007
|
|
||||||
" TOTP_AUTH"""
|
proc gen*(root: string, args: seq[string]) =
|
||||||
for i in countup(0, 4, 1):
|
if args.len != 1:
|
||||||
echo randomInt(10000000, 99999999)
|
quit "I need a machine name"
|
||||||
|
|
||||||
|
|
||||||
|
var
|
||||||
|
res = generateUUID().replace("-")[0 .. 19]
|
||||||
|
body: string
|
||||||
|
name = args[0]
|
||||||
|
|
||||||
|
try:
|
||||||
|
discard newTOTP(encode res).now()
|
||||||
|
except:
|
||||||
|
quit "it failed"
|
||||||
|
|
||||||
|
body = encode res & "\n"
|
||||||
|
body = body & """" RATE_LIMIT 3 30 1441950209
|
||||||
|
" WINDOW_SIZE 3
|
||||||
|
" DISALLOW_REUSE 48065007
|
||||||
|
" TOTP_AUTH""" & "\n"
|
||||||
|
|
||||||
|
for i in countup(0, 4, 1):
|
||||||
|
body = body & $randomInt(10000000, 99999999) & "\n"
|
||||||
|
|
||||||
|
try:
|
||||||
|
writeFile(root / name, body)
|
||||||
|
except:
|
||||||
|
quit getCurrentExceptionMsg()
|
||||||
|
|
|
@ -10,7 +10,7 @@ const usageHelp =
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h --help Show this screen
|
-h --help Show this screen
|
||||||
-r --root:path Use path as the totp root for Nim
|
-r --root:path Use path as the totp root for secrets
|
||||||
-v --version Show version of totptool
|
-v --version Show version of totptool
|
||||||
|
|
||||||
Subcommands:
|
Subcommands:
|
||||||
|
|
|
@ -7,4 +7,4 @@ license = "MIT"
|
||||||
bin = "totptool"
|
bin = "totptool"
|
||||||
|
|
||||||
[Deps]
|
[Deps]
|
||||||
Requires: "nim >= 0.10.0, otp"
|
Requires: "nim >= 0.10.0, otp, nuuid, random"
|
||||||
|
|
Loading…
Reference in New Issue