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