瀏覽代碼

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 查看文件

#!/usr/bin/env python2 #!/usr/bin/env python2


import xmlrpc.client import xmlrpc.client
import hashlib


# connects to the XMLRPC Server
s = xmlrpc.client.ServerProxy('http://localhost:8000') 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 list of available methods
print( s.system.listMethods() ) print( s.system.listMethods() )

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

#!/usr/bin/env python2 #!/usr/bin/env python2


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


# Register an instance; all the methods of the instance are # Register an instance; all the methods of the instance are
# published as XML-RPC methods # published as XML-RPC methods
class CHAP: class CHAP:
test_password = 'Test123'
# initializes class-instance and instance variables
def __init__(self): 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): def init(self):
self.key = str( uuid.uuid4() ) self.key = str( uuid.uuid4() )
return self.key 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()) server.register_instance(CHAP())
# Run the server's main loop # Run the server's main loop
server.serve_forever() server.serve_forever()

Loading…
取消
儲存