- 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)
|
# aSRC (Aliased Server Remote Control)
|
||||||
# - SERVER -
|
# - SERVER -
|
||||||
#
|
#
|
||||||
# program version: 0.0.0.20130617
|
# program version: 0.0.0.20130625
|
||||||
# protocol version: 0.2.20130617
|
# protocol version: 0.2.20130625
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -51,10 +51,13 @@ class ThreadedRequestHandler(socketserver.StreamRequestHandler):
|
||||||
print("Client connected: " + str(self.client_address))
|
print("Client connected: " + str(self.client_address))
|
||||||
|
|
||||||
# send motd
|
# 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()):
|
if not auth.check_passwd(self.rfile.readline().strip()):
|
||||||
|
self.request.sendall(bytes((comm.passwd_reply(False)), ENCODING))
|
||||||
return
|
return
|
||||||
|
self.request.sendall(bytes((comm.passwd_reply(True)), ENCODING))
|
||||||
|
|
||||||
repeat = True
|
repeat = True
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# includes/argparser.py
|
# includes/argparser.py
|
||||||
#
|
#
|
||||||
# module version: 1.0.20130425
|
# module version: 1.1.20130625
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
# includes/auth.py
|
# includes/auth.py
|
||||||
#
|
#
|
||||||
# module version: 0.0.20130617
|
# module version: 1.0.20130625
|
||||||
# for protocol version 0.2.20130617
|
# for protocol version 0.2.20130625
|
||||||
#
|
#
|
||||||
|
#
|
||||||
|
# contains:
|
||||||
|
# init()
|
||||||
|
# check_passwd()
|
||||||
|
# mkpasswd()
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
@ -11,7 +18,6 @@ class auth:
|
||||||
passwd = ""
|
passwd = ""
|
||||||
|
|
||||||
def init(password):
|
def init(password):
|
||||||
#from Crypto.Hash import Hash
|
|
||||||
|
|
||||||
global passwd
|
global passwd
|
||||||
passwd = password
|
passwd = password
|
||||||
|
@ -21,7 +27,6 @@ class auth:
|
||||||
"""
|
"""
|
||||||
checks a given password
|
checks a given password
|
||||||
"""
|
"""
|
||||||
#return hashlib.sha512(incpass).hexdigest()
|
|
||||||
if hashlib.sha512(incpass).hexdigest() == passwd: return True
|
if hashlib.sha512(incpass).hexdigest() == passwd: return True
|
||||||
else: return False
|
else: return False
|
||||||
|
|
||||||
|
@ -29,4 +34,4 @@ class auth:
|
||||||
"""
|
"""
|
||||||
encodes a password with SHA512
|
encodes a password with SHA512
|
||||||
"""
|
"""
|
||||||
return hashlib.sha512(incpass).hexdigest()
|
return hashlib.sha512(incpass).hexdigest()
|
||||||
|
|
|
@ -1,17 +1,27 @@
|
||||||
# includes/comm.py
|
# includes/comm.py
|
||||||
#
|
#
|
||||||
# module version: 0.0.20130617
|
# module version: 0.0.20130625
|
||||||
# for protocol version 0.2.20130617
|
# for protocol version 0.2.20130625
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# contains:
|
||||||
|
# init()
|
||||||
|
# header()
|
||||||
|
# encode_message()
|
||||||
|
# decode_message()
|
||||||
|
# motd()
|
||||||
|
# passwd_request()
|
||||||
|
# passwd_reply()
|
||||||
|
# command()
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
from .statuscodes import statuscodes
|
from .statuscodes import statuscodes
|
||||||
#from .auth import auth
|
|
||||||
|
|
||||||
|
|
||||||
class comm:
|
class comm:
|
||||||
|
|
||||||
# some settings
|
# just some settings
|
||||||
aliases = dict()
|
aliases = dict()
|
||||||
server_version = ""
|
server_version = ""
|
||||||
protocol_version = ""
|
protocol_version = ""
|
||||||
|
@ -28,11 +38,10 @@ class comm:
|
||||||
server_version = ServerVersion
|
server_version = ServerVersion
|
||||||
protocol_version = ProtocolVersion
|
protocol_version = ProtocolVersion
|
||||||
verbosity = Verbosity
|
verbosity = Verbosity
|
||||||
|
|
||||||
#auth.init(Password)
|
|
||||||
|
|
||||||
# builds an header
|
# builds an header
|
||||||
def header(CodeList, AdditionalHeaderLines = ""):
|
def header(CodeList, AdditionalHeaderLines = "", Newlines = True):
|
||||||
"""
|
"""
|
||||||
returns the header with one ore mode given status codes
|
returns the header with one ore mode given status codes
|
||||||
and optional additional header lines
|
and optional additional header lines
|
||||||
|
@ -42,8 +51,10 @@ class comm:
|
||||||
"asrcp" + protocol_version + "\n"
|
"asrcp" + protocol_version + "\n"
|
||||||
for i in range(0, len(CodeList)):
|
for i in range(0, len(CodeList)):
|
||||||
ret += CodeList[int(i)] + " " +\
|
ret += CodeList[int(i)] + " " +\
|
||||||
statuscodes.description['s' + CodeList[int(i)]] + "\n"
|
statuscodes.description['s' + CodeList[int(i)]]
|
||||||
ret += AdditionalHeaderLines + "\n\n"
|
if AdditionalHeaderLines:
|
||||||
|
ret += "\n" + AdditionalHeaderLines
|
||||||
|
if Newlines: ret += "\n\n"
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +79,25 @@ class comm:
|
||||||
"""
|
"""
|
||||||
builds and returns a motd package
|
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
|
# handles the content
|
||||||
|
@ -143,6 +172,6 @@ class comm:
|
||||||
if verbosity >= 2: print("Got invalid command from",
|
if verbosity >= 2: print("Got invalid command from",
|
||||||
str(client_address), ": ", data)
|
str(client_address), ": ", data)
|
||||||
|
|
||||||
ret = comm.encode_message(ret) + "{END}\n\n"
|
ret = comm.encode_message(ret) + "{END}\n"
|
||||||
|
|
||||||
return hdr + ret
|
return hdr + ret
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# include/statuscodes.py
|
# include/statuscodes.py
|
||||||
#
|
#
|
||||||
# module version: 1.0.20130617
|
# module version: 1.1.20130625
|
||||||
# for protocol version 0.2.20130617
|
# for protocol version 0.2.20130625
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@ class statuscodes:
|
||||||
s003 = "MOTD",
|
s003 = "MOTD",
|
||||||
s004 = "Exit",
|
s004 = "Exit",
|
||||||
# 100 authentication and maintenance
|
# 100 authentication and maintenance
|
||||||
s101 = "Challenge",
|
s101 = "AuthRequest",
|
||||||
s102 = "Success",
|
s102 = "AuthSuccess",
|
||||||
s103 = "Failure",
|
s103 = "AuthFailure",
|
||||||
s104 = "To Many Tries",
|
#s104 = "To Many Tries",
|
||||||
# 200 command
|
# 200 command
|
||||||
s201 = "Valid",
|
s201 = "Valid",
|
||||||
s202 = "Valid Service Command",
|
s202 = "Valid Service Command",
|
||||||
|
|
Loading…
Reference in a new issue