Some python scrips for demonstrating chap protocol
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

chap-server.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python2
  2. import uuid
  3. import hashlib
  4. from xmlrpc.server import SimpleXMLRPCServer
  5. from xmlrpc.server import SimpleXMLRPCRequestHandler
  6. # Restrict to a particular path.
  7. class RequestHandler(SimpleXMLRPCRequestHandler):
  8. rpc_paths = ('/RPC2',)
  9. # Create server
  10. server = SimpleXMLRPCServer(("localhost", 8000),
  11. requestHandler=RequestHandler)
  12. server.register_introspection_functions()
  13. # Register an instance; all the methods of the instance are
  14. # published as XML-RPC methods
  15. class CHAP:
  16. test_password = 'Test123'
  17. # initializes class-instance and instance variables
  18. def __init__(self):
  19. self.key = '';
  20. self.authenticated = 0;
  21. # tells the server to start the autentification process
  22. # and send the generated random salt
  23. def init(self):
  24. self.key = str( uuid.uuid4() )
  25. return self.key
  26. # checks if send hash is same as internally generated to validate if the correct
  27. # password was used
  28. def auth(self, password_hash):
  29. combined = CHAP.test_password + self.key
  30. passhash = hashlib.sha256( combined.encode( 'utf-8' ) ).hexdigest()
  31. print( passhash )
  32. print( password_hash )
  33. self.authenticated = passhash == password_hash
  34. return self.authenticated
  35. server.register_instance(CHAP())
  36. # Run the server's main loop
  37. server.serve_forever()