~pablo-elenya/exaile/diacritica

« back to all changes in this revision

Viewing changes to plugins/gcalc/gdata/tlslite/integration/IntegrationHelper.py

  • Committer: Pablo Ruiz Múzquiz
  • Date: 2010-01-11 19:53:01 UTC
  • Revision ID: pruiz@ubuntuvm-20100111195301-pm1d2ppe36gytu77
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
b'\\ No newline at end of file'