浏览代码

implemented auth method and client workflow

base-functionality is done
master
DragonSkills99 5 年前
父节点
当前提交
60c53ad487
共有 2 个文件被更改,包括 23 次插入4 次删除
  1. 6
    3
      chap-client.py
  2. 17
    1
      chap-server.py

+ 6
- 3
chap-client.py 查看文件

@@ -1,11 +1,14 @@
#!/usr/bin/env python2

import xmlrpc.client
import hashlib

# connects to the XMLRPC Server
s = xmlrpc.client.ServerProxy('http://localhost:8000')
print( s.pow(2,3) ) # Returns 2**3 = 8
print( s.add(2,3) ) # Returns 5
print( s.div(5,2) ) # Returns 5//2 = 2
# initalized the login process
key = s.init()
# does the actual authentication
print( s.auth( hashlib.sha256( ( 'Test123' + key ).encode( 'utf-8' ) ).hexdigest() ) )

# Print list of available methods
print( s.system.listMethods() )

+ 17
- 1
chap-server.py 查看文件

@@ -1,6 +1,7 @@
#!/usr/bin/env python2

import uuid
import hashlib
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler

@@ -17,13 +18,28 @@ server.register_introspection_functions()
# Register an instance; all the methods of the instance are
# published as XML-RPC methods
class CHAP:
test_password = 'Test123'
# initializes class-instance and instance variables
def __init__(self):
self.key = 0;
self.key = '';
self.authenticated = 0;

# tells the server to start the autentification process
# and send the generated random salt
def init(self):
self.key = str( uuid.uuid4() )
return self.key

# checks if send hash is same as internally generated to validate if the correct
# password was used
def auth(self, password_hash):
combined = CHAP.test_password + self.key
passhash = hashlib.sha256( combined.encode( 'utf-8' ) ).hexdigest()
print( passhash )
print( password_hash )
self.authenticated = passhash == password_hash
return self.authenticated

server.register_instance(CHAP())
# Run the server's main loop
server.serve_forever()

正在加载...
取消
保存