-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthServer.py
More file actions
74 lines (57 loc) · 1.41 KB
/
AuthServer.py
File metadata and controls
74 lines (57 loc) · 1.41 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
63
64
65
66
67
68
69
70
71
72
73
### Implements Authentication Server ###
from TLSServer import TLSServer
from pprint import pprint
from datetime import datetime
## Temporarly ##
from config import *
import json
import base64
class AuthServer(TLSServer):
def __init__(self, host, port, key, crt, db):
super(AuthServer, self).__init__(host, port, key, crt)
self.db = db
def handleRequest(self, req):
print "AuthServer: This is my turn!!"
try:
dreq = json.loads(base64.b64decode(req))
if not self.isAuth(dreq):
print "Authentication failed!!"
except Exception as e:
print str(e)
def isAuth(self, req):
try:
if ("uid" in req) and ("sid" in req) and ("addr" in req):
q = (req["uid"], req["sid"], req["addr"])
return self.db.isAuthExist(q)
else:
print "Wrong request type: " + str(req)
return False
except Exception as e:
print str(e)
def prepAuthResponse(self, req):
try:
resp = \
{
"ticket": None,
"session": None
}
resp["ticket"] = self.prepTicketResponse(req)
resp["session"] = self.prepSessionResponse(req)
return resp
except Exception as e:
print str(e)
def prepTicketResponse(self, req):
try:
resp = \
{
"uid": req["uid"],
"sid": req["sid"],
"stamp": datetime.now(),
"addr": req["addr"],
"ticket_expr": req["ticket_expr"],
"session_key": None
}
except Exception as e:
print str(e)
def prepSessionResponse(self, req):
pass