/gdata/tlslite/integration/IntegrationHelper.py

http://radioappz.googlecode.com/ · Python · 52 lines · 37 code · 10 blank · 5 comment · 25 complexity · 7a847a087c11086c05118415431b0446 MD5 · raw file

  1. class IntegrationHelper:
  2. def __init__(self,
  3. username=None, password=None, sharedKey=None,
  4. certChain=None, privateKey=None,
  5. cryptoID=None, protocol=None,
  6. x509Fingerprint=None,
  7. x509TrustList=None, x509CommonName=None,
  8. settings = None):
  9. self.username = None
  10. self.password = None
  11. self.sharedKey = None
  12. self.certChain = None
  13. self.privateKey = None
  14. self.checker = None
  15. #SRP Authentication
  16. if username and password and not \
  17. (sharedKey or certChain or privateKey):
  18. self.username = username
  19. self.password = password
  20. #Shared Key Authentication
  21. elif username and sharedKey and not \
  22. (password or certChain or privateKey):
  23. self.username = username
  24. self.sharedKey = sharedKey
  25. #Certificate Chain Authentication
  26. elif certChain and privateKey and not \
  27. (username or password or sharedKey):
  28. self.certChain = certChain
  29. self.privateKey = privateKey
  30. #No Authentication
  31. elif not password and not username and not \
  32. sharedKey and not certChain and not privateKey:
  33. pass
  34. else:
  35. raise ValueError("Bad parameters")
  36. #Authenticate the server based on its cryptoID or fingerprint
  37. if sharedKey and (cryptoID or protocol or x509Fingerprint):
  38. raise ValueError("Can't use shared keys with other forms of"\
  39. "authentication")
  40. self.checker = Checker(cryptoID, protocol, x509Fingerprint,
  41. x509TrustList, x509CommonName)
  42. self.settings = settings