79
85
self._report_activity(len(s), 'read')
82
def readline(self, size=-1):
83
s = self.filesock.readline(size)
89
# This should be readline(self, size=-1), but httplib in python 2.4 and
90
# 2.5 defines a SSLFile wrapper whose readline method lacks the size
91
# parameter. So until we drop support for 2.4 and 2.5 and since we
92
# don't *need* the size parameter we'll stay with readline(self)
94
s = self.filesock.readline()
84
95
self._report_activity(len(s), 'read')
687
698
connect.proxied_host, self.host))
689
700
connection.cleanup_pipe()
690
# Establish the connection encryption
701
# Establish the connection encryption
691
702
connection.connect_to_origin()
692
703
# Propagate the connection to the original request
693
704
request.connection = connection
938
949
preventively set authentication headers after the first
939
950
successful authentication.
941
This can be used for http and proxy, as well as for basic and
952
This can be used for http and proxy, as well as for basic, negotiate and
942
953
digest authentications.
944
955
This provides an unified interface for all authentication handlers
1058
1069
(digest's nonce is an example, digest's nonce_count is a
1059
1070
*counter-example*). Such parameters must be updated by
1060
1071
using the update_auth() method.
1062
1073
:param header: The authentication header sent by the server.
1063
1074
:param auth: The auth parameters already known. They may be
1138
1149
https_request = http_request # FIXME: Need test
1152
class NegotiateAuthHandler(AbstractAuthHandler):
1153
"""A authentication handler that handles WWW-Authenticate: Negotiate.
1155
At the moment this handler supports just Kerberos. In the future,
1156
NTLM support may also be added.
1161
def auth_match(self, header, auth):
1162
scheme = header.lower()
1163
if scheme != 'negotiate':
1165
self.update_auth(auth, 'scheme', scheme)
1166
resp = self._auth_match_kerberos(auth)
1169
# Optionally should try to authenticate using NTLM here
1170
self.update_auth(auth, 'negotiate_response', resp)
1173
def _auth_match_kerberos(self, auth):
1174
"""Try to create a GSSAPI response for authenticating against a host."""
1175
if not have_kerberos:
1177
ret, vc = kerberos.authGSSClientInit("HTTP@%(host)s" % auth)
1179
trace.warning('Unable to create GSSAPI context for %s: %d',
1182
ret = kerberos.authGSSClientStep(vc, "")
1184
trace.mutter('authGSSClientStep failed: %d', ret)
1186
return kerberos.authGSSClientResponse(vc)
1188
def build_auth_header(self, auth, request):
1189
return "Negotiate %s" % auth['negotiate_response']
1191
def auth_params_reusable(self, auth):
1192
# If the auth scheme is known, it means a previous
1193
# authentication was successful, all information is
1194
# available, no further checks are needed.
1195
return (auth.get('scheme', None) == 'negotiate' and
1196
auth.get('negotiate_response', None) is not None)
1141
1199
class BasicAuthHandler(AbstractAuthHandler):
1142
1200
"""A custom basic authentication handler."""
1363
1421
"""Custom proxy basic authentication handler"""
1424
class HTTPNegotiateAuthHandler(NegotiateAuthHandler, HTTPAuthHandler):
1425
"""Custom http negotiate authentication handler"""
1428
class ProxyNegotiateAuthHandler(NegotiateAuthHandler, ProxyAuthHandler):
1429
"""Custom proxy negotiate authentication handler"""
1366
1432
class HTTPErrorProcessor(urllib2.HTTPErrorProcessor):
1367
1433
"""Process HTTP error responses.