|
|
|
|
|
|
|
|
#!/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() |