PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/gdata/tlslite/integration/IntegrationHelper.py

http://radioappz.googlecode.com/
Python | 52 lines | 37 code | 10 blank | 5 comment | 29 complexity | 7a847a087c11086c05118415431b0446 MD5 | raw file
 1
 2class 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