Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python urllib2 HTTPS and proxy NTLM authentication

urllib2 doesn't seem to support HTTPS with proxy authentication in general, even less with NTLM authentication. Anyone knows if there is a patch somewhere for HTTPS on proxy with NTLM authentication.

Regards,

Laurent

like image 906
Laurent Luce Avatar asked Sep 26 '09 15:09

Laurent Luce


3 Answers

Late reply. Urllib2 does not support NTLM proxying but pycurl does. Excerpt:

self._connection = pycurl.Curl()
self._connection.setopt(pycurl.PROXY, PROXY_HOST)
self._connection.setopt(pycurl.PROXYPORT, PROXY_PORT)
self._connection.setopt(pycurl.PROXYUSERPWD,
                        "%s:%s" % (PROXY_USER, PROXY_PASS))
...
like image 178
lemonad Avatar answered Oct 31 '22 04:10

lemonad


http://code.google.com/p/python-ntlm/

I never tried with HTTPS but I think it should work.

EDIT: If you are using SSL Tunneling, proxy authentication is a bad idea.

Proxy using Basic Auth over HTTPS is not secure when the SSL is tunneled. Your password will be sent in clear (Base64-encoded) to proxy. Lots of people assumes the password will be encrypted inside SSL. It's not true in this case.

It's almost impossible to support other encrypted or hashed mechanisms like Digest/NTLM because they all require negotiation (multiple exchanges) and that's not defined in CONNECT protocol. This negotiation happens out of the band of the HTTP connection. It's very hard to implement in proxy/browser also.

If this is an enterprise proxy, IP ACL is the only secure solution.

like image 31
ZZ Coder Avatar answered Oct 31 '22 04:10

ZZ Coder


Good recipe (for HTTPS w/proxy) and discussion here, it should be possible to meld that with the python-nltm code @ZZ has already suggested.

like image 25
Alex Martelli Avatar answered Oct 31 '22 04:10

Alex Martelli