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 os
|
||||
|
||||
when isMainModule:
|
||||
var
|
||||
args = commandLineParams()
|
||||
const codeUsage =
|
||||
"""Usage: totptool code <name>
|
||||
|
||||
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:
|
||||
quit "I need a machine name"
|
||||
|
||||
try:
|
||||
var
|
||||
keyFileName = args[0]
|
||||
fin = open getEnv("HOME") / "life" / "crypto" / "totp" / keyFileName
|
||||
fin = open root / keyFileName
|
||||
key = fin.readLine
|
||||
totp = newTotp key
|
||||
|
||||
|
@ -20,6 +28,3 @@ when isMainModule:
|
|||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
quit "Couldn't do that for " & args[0] & ". Does that machine exist in the store?"
|
||||
|
||||
else:
|
||||
quit "invalid"
|
||||
|
|
48
cmds/gen.nim
48
cmds/gen.nim
|
@ -1,20 +1,48 @@
|
|||
import base32
|
||||
import nuuid
|
||||
import os
|
||||
import otp
|
||||
import random
|
||||
import strutils
|
||||
|
||||
var res = generateUUID().replace("-")[0 .. 19]
|
||||
const genUsage =
|
||||
"""Usage: totptool gen <name>
|
||||
|
||||
try:
|
||||
This will generate a new secret and recovery codes
|
||||
for a given service name. This will then write it
|
||||
to your configured secret store and make it
|
||||
available for `totptool code` instantly.
|
||||
"""
|
||||
|
||||
proc help*() =
|
||||
echo genUsage
|
||||
quit 2
|
||||
|
||||
proc gen*(root: string, args: seq[string]) =
|
||||
if args.len != 1:
|
||||
quit "I need a machine name"
|
||||
|
||||
|
||||
var
|
||||
res = generateUUID().replace("-")[0 .. 19]
|
||||
body: string
|
||||
name = args[0]
|
||||
|
||||
try:
|
||||
discard newTOTP(encode res).now()
|
||||
except:
|
||||
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)
|
||||
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:
|
||||
-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
|
||||
|
||||
Subcommands:
|
||||
|
|
|
@ -7,4 +7,4 @@ license = "MIT"
|
|||
bin = "totptool"
|
||||
|
||||
[Deps]
|
||||
Requires: "nim >= 0.10.0, otp"
|
||||
Requires: "nim >= 0.10.0, otp, nuuid, random"
|
||||
|
|
Loading…
Reference in New Issue