From 745c313fd58ce77f769002db2c1670c5a7562117 Mon Sep 17 00:00:00 2001 From: Christian Damken Date: Tue, 25 Jun 2013 14:03:28 +0200 Subject: [PATCH] - 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 --- asrc-server.py | 9 +++++--- include/argparser.py | 2 +- include/auth.py | 15 ++++++++----- include/comm.py | 51 +++++++++++++++++++++++++++++++++--------- include/statuscodes.py | 12 +++++----- 5 files changed, 63 insertions(+), 26 deletions(-) diff --git a/asrc-server.py b/asrc-server.py index 526cb03..a64a6fb 100755 --- a/asrc-server.py +++ b/asrc-server.py @@ -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 diff --git a/include/argparser.py b/include/argparser.py index 2133fd4..4cc08da 100644 --- a/include/argparser.py +++ b/include/argparser.py @@ -1,6 +1,6 @@ # includes/argparser.py # -# module version: 1.0.20130425 +# module version: 1.1.20130625 # diff --git a/include/auth.py b/include/auth.py index 10359d4..80c98eb 100644 --- a/include/auth.py +++ b/include/auth.py @@ -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 @@ -29,4 +34,4 @@ class auth: """ encodes a password with SHA512 """ - return hashlib.sha512(incpass).hexdigest() \ No newline at end of file + return hashlib.sha512(incpass).hexdigest() diff --git a/include/comm.py b/include/comm.py index 3d6332e..3b6eaa7 100644 --- a/include/comm.py +++ b/include/comm.py @@ -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 = "" @@ -28,11 +38,10 @@ class comm: server_version = ServerVersion 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 diff --git a/include/statuscodes.py b/include/statuscodes.py index d3a9ad8..feda70a 100644 --- a/include/statuscodes.py +++ b/include/statuscodes.py @@ -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",