- cleaned up auth-codes in class statuscodes
- added passwd_request() and passwd_reply() to class comm - updated authentication process to fit protocol - fixed version numbers for each *.py-file
This commit is contained in:
parent
4259e5836b
commit
745c313fd5
5 changed files with 63 additions and 26 deletions
|
@ -25,8 +25,8 @@
|
|||
# aSRC (Aliased Server Remote Control)
|
||||
# - SERVER -
|
||||
#
|
||||
# program version: 0.0.0.20130617
|
||||
# protocol version: 0.2.20130617
|
||||
# program version: 0.0.0.20130625
|
||||
# protocol version: 0.2.20130625
|
||||
#
|
||||
#
|
||||
|
||||
|
@ -51,10 +51,13 @@ class ThreadedRequestHandler(socketserver.StreamRequestHandler):
|
|||
print("Client connected: " + str(self.client_address))
|
||||
|
||||
# send motd
|
||||
self.request.sendall(bytes((comm.motd(MOTD) + "\n"), ENCODING))
|
||||
self.request.sendall(bytes((comm.motd(MOTD)), ENCODING))
|
||||
|
||||
self.request.sendall(bytes((comm.passwd_request()), ENCODING))
|
||||
if not auth.check_passwd(self.rfile.readline().strip()):
|
||||
self.request.sendall(bytes((comm.passwd_reply(False)), ENCODING))
|
||||
return
|
||||
self.request.sendall(bytes((comm.passwd_reply(True)), ENCODING))
|
||||
|
||||
repeat = True
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# includes/argparser.py
|
||||
#
|
||||
# module version: 1.0.20130425
|
||||
# module version: 1.1.20130625
|
||||
#
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
# includes/auth.py
|
||||
#
|
||||
# module version: 0.0.20130617
|
||||
# for protocol version 0.2.20130617
|
||||
# module version: 1.0.20130625
|
||||
# for protocol version 0.2.20130625
|
||||
#
|
||||
#
|
||||
# contains:
|
||||
# init()
|
||||
# check_passwd()
|
||||
# mkpasswd()
|
||||
#
|
||||
|
||||
|
||||
import hashlib
|
||||
|
||||
|
@ -11,7 +18,6 @@ class auth:
|
|||
passwd = ""
|
||||
|
||||
def init(password):
|
||||
#from Crypto.Hash import Hash
|
||||
|
||||
global passwd
|
||||
passwd = password
|
||||
|
@ -21,7 +27,6 @@ class auth:
|
|||
"""
|
||||
checks a given password
|
||||
"""
|
||||
#return hashlib.sha512(incpass).hexdigest()
|
||||
if hashlib.sha512(incpass).hexdigest() == passwd: return True
|
||||
else: return False
|
||||
|
||||
|
|
|
@ -1,17 +1,27 @@
|
|||
# includes/comm.py
|
||||
#
|
||||
# module version: 0.0.20130617
|
||||
# for protocol version 0.2.20130617
|
||||
# module version: 0.0.20130625
|
||||
# for protocol version 0.2.20130625
|
||||
#
|
||||
#
|
||||
# contains:
|
||||
# init()
|
||||
# header()
|
||||
# encode_message()
|
||||
# decode_message()
|
||||
# motd()
|
||||
# passwd_request()
|
||||
# passwd_reply()
|
||||
# command()
|
||||
#
|
||||
|
||||
|
||||
from .statuscodes import statuscodes
|
||||
#from .auth import auth
|
||||
|
||||
|
||||
class comm:
|
||||
|
||||
# some settings
|
||||
# just some settings
|
||||
aliases = dict()
|
||||
server_version = ""
|
||||
protocol_version = ""
|
||||
|
@ -29,10 +39,9 @@ class comm:
|
|||
protocol_version = ProtocolVersion
|
||||
verbosity = Verbosity
|
||||
|
||||
#auth.init(Password)
|
||||
|
||||
# builds an header
|
||||
def header(CodeList, AdditionalHeaderLines = ""):
|
||||
def header(CodeList, AdditionalHeaderLines = "", Newlines = True):
|
||||
"""
|
||||
returns the header with one ore mode given status codes
|
||||
and optional additional header lines
|
||||
|
@ -42,8 +51,10 @@ class comm:
|
|||
"asrcp" + protocol_version + "\n"
|
||||
for i in range(0, len(CodeList)):
|
||||
ret += CodeList[int(i)] + " " +\
|
||||
statuscodes.description['s' + CodeList[int(i)]] + "\n"
|
||||
ret += AdditionalHeaderLines + "\n\n"
|
||||
statuscodes.description['s' + CodeList[int(i)]]
|
||||
if AdditionalHeaderLines:
|
||||
ret += "\n" + AdditionalHeaderLines
|
||||
if Newlines: ret += "\n\n"
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -68,7 +79,25 @@ class comm:
|
|||
"""
|
||||
builds and returns a motd package
|
||||
"""
|
||||
return comm.header(['202', '003']) + comm.encode_message(motd) + "\n{END}"
|
||||
return comm.header(['202', '003'], "", False) + comm.encode_message(motd) + "\n{END}\n"
|
||||
|
||||
|
||||
def passwd_request():
|
||||
"""
|
||||
sends a password request
|
||||
"""
|
||||
return comm.header(['101'], "", False) + "\n{END}\n"
|
||||
pass
|
||||
|
||||
|
||||
def passwd_reply(valid):
|
||||
"""
|
||||
replies to a password
|
||||
"""
|
||||
if valid:
|
||||
return comm.header(['102'], "", False) + "\n{END}\n"
|
||||
else:
|
||||
return comm.header(['103'], "", False) + "\n{END}\n"
|
||||
|
||||
|
||||
# handles the content
|
||||
|
@ -143,6 +172,6 @@ class comm:
|
|||
if verbosity >= 2: print("Got invalid command from",
|
||||
str(client_address), ": ", data)
|
||||
|
||||
ret = comm.encode_message(ret) + "{END}\n\n"
|
||||
ret = comm.encode_message(ret) + "{END}\n"
|
||||
|
||||
return hdr + ret
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# include/statuscodes.py
|
||||
#
|
||||
# module version: 1.0.20130617
|
||||
# for protocol version 0.2.20130617
|
||||
# module version: 1.1.20130625
|
||||
# for protocol version 0.2.20130625
|
||||
#
|
||||
|
||||
|
||||
|
@ -14,10 +14,10 @@ class statuscodes:
|
|||
s003 = "MOTD",
|
||||
s004 = "Exit",
|
||||
# 100 authentication and maintenance
|
||||
s101 = "Challenge",
|
||||
s102 = "Success",
|
||||
s103 = "Failure",
|
||||
s104 = "To Many Tries",
|
||||
s101 = "AuthRequest",
|
||||
s102 = "AuthSuccess",
|
||||
s103 = "AuthFailure",
|
||||
#s104 = "To Many Tries",
|
||||
# 200 command
|
||||
s201 = "Valid",
|
||||
s202 = "Valid Service Command",
|
||||
|
|
Loading…
Reference in a new issue