-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver
More file actions
executable file
·63 lines (50 loc) · 1.8 KB
/
server
File metadata and controls
executable file
·63 lines (50 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python3
from authenticator.data import ClientData, ClientFile
from authenticator.hotp import HOTP
from authenticator.cli import CLI
from bottle import route, request, run
import os
class Authenticator:
def __init__(self, passphrase):
cli = CLI()
self.__data_dir = cli._locate_data_dir()
self.__data_file = os.path.join(self.__data_dir, 'authenticator.data')
# Load the ClientData objects
self.__cf = ClientFile(passphrase)
self.cds = self.__cf.load(self.__data_file)
def generate_once(self):
"""Generate a HOTP for each configuration in cds.
"""
if 0 == len(self.cds):
# None found; just get out
return "<p>No HOTP/TOTP configurations found.</p>"
result = ""
for cd in self.cds:
if cd.counter_from_time():
hotp = HOTP()
code_string, remaining_seconds = hotp.generate_code_from_time(
cd.shared_secret(),
code_length=cd.password_length(),
period=cd.period())
result += "<p>{0}: {1} (expires in {2} seconds)</p>".format(
cd.client_id(), code_string, remaining_seconds)
return result
def check_login(passphrase):
return True
@route('/')
def login():
return '''
<form action="/login" method="post">
Passphrase: <input name="passphrase" type="password" />
<input value="Submit" type="submit" />
</form>
'''
@route('/login', method='POST')
def do_login():
passphrase = request.forms.get('passphrase')
try:
authenticator = Authenticator(passphrase)
except:
return "<p>Invalid passphrase</p>"
return authenticator.generate_once()
run(host='0.0.0.0', port=8080)