692
698
connect.proxied_host, self.host))
694
700
connection.cleanup_pipe()
695
# Establish the connection encryption
701
# Establish the connection encryption
696
702
connection.connect_to_origin()
697
703
# Propagate the connection to the original request
698
704
request.connection = connection
943
949
preventively set authentication headers after the first
944
950
successful authentication.
946
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
947
953
digest authentications.
949
955
This provides an unified interface for all authentication handlers
1063
1069
(digest's nonce is an example, digest's nonce_count is a
1064
1070
*counter-example*). Such parameters must be updated by
1065
1071
using the update_auth() method.
1067
1073
:param header: The authentication header sent by the server.
1068
1074
:param auth: The auth parameters already known. They may be
1143
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)
1146
1199
class BasicAuthHandler(AbstractAuthHandler):
1147
1200
"""A custom basic authentication handler."""
1368
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"""
1371
1432
class HTTPErrorProcessor(urllib2.HTTPErrorProcessor):
1372
1433
"""Process HTTP error responses.