1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 '''
20 Parts of the following are inspired by urllib2_kerberos,
21 which is also under the Apache 2.0 License,
22 see http://limedav.com/hg/urllib2_kerberos
23 '''
24
25 from caldavclientlibrary.protocol.http.authentication.authenticator import Authenticator
26 from caldavclientlibrary.protocol.http.definitions import headers
27 import re
28 import kerberos
29
31
35
43
45 """checks for "Negotiate" in proper auth header
46 taken from urllib2_kerberos, see http://limedav.com/hg/urllib2_kerberos
47 """
48 authreq = None
49 for hdr in headers:
50 if hdr[0].lower == "www-authenticate" and "Negotiate" in hdr[1]:
51 authreq = hdr[1]
52
53 if authreq:
54 rx = re.compile('(?:.*,)*\s*Negotiate\s*([^,]*),?', re.I)
55 mo = rx.search(authreq)
56 if mo:
57 return mo.group(1)
58 else:
59
60 pass
61
62 else:
63 pass
64
65
66 return None
67
69 """
70 taken from urllib2_kerberos, see http://limedav.com/hg/urllib2_kerberos
71 """
72
73 host = None
74
75 for hdr in headers:
76 if hdr[0] == "Host":
77 host = hdr[1]
78
79 tail, _ignore_sep, head = host.rpartition(':')
80 domain = tail if tail else head
81
82
83 result, self.context = kerberos.authGSSClientInit("http@%s" % domain)
84
85 if result < 1:
86
87 return None
88
89
90 data = ""
91 if neg_value != None:
92 data = neg_value
93 result = kerberos.authGSSClientStep(self.context, data)
94
95 if result < 0:
96
97 return None
98
99
100
101 response = kerberos.authGSSClientResponse(self.context)
102
103
104 return "Negotiate %s" % response
105
106 - def clean_context(self):
107 """
108 taken from urllib2_kerberos, see http://limedav.com/hg/urllib2_kerberos
109 """
110 if self.context is not None:
111 kerberos.authGSSClientClean(self.context)
112 self.context = None
113