This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ssl do_handshake fails on https-proxy (aka. https over https-proxy)
Type: behavior Stage: resolved
Components: SSL Versions: Python 3.5, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Cannot tunnel TLS connection through TLS connection
View: 29394
Assigned To: christian.heimes Nosy List: Phus Lu, christian.heimes, martin.panter
Priority: normal Keywords:

Created on 2017-02-21 03:29 by Phus Lu, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg288259 - (view) Author: Phus Lu (Phus Lu) Date: 2017-02-21 03:29
Background:

I'm working on adding https-proxy[1] support to python-requests https://github.com/phuslu/requests_httpsproxy

Issue:
ssl module(python 2.7) counld establish ssl handshakes over a https-proxy

Reproduce Steps:
I setup a https-proxy in bwg.phus.lu:443

>>> import socket,ssl
>>> sock = ssl.wrap_socket(socket.create_connection(('bwg.phus.lu', 443)))
>>> sock.sendall('CONNECT httpbin.org:443 HTTP/1.0\r\n\r\n')
36
>>> sock.recv()
'HTTP/1.1 200 OK\r\n\r\n'
>>> ssl.wrap_socket(sock)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    ssl.wrap_socket(sock)
  File "/usr/lib/python2.7/ssl.py", line 943, in wrap_socket
    ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 611, in __init__
    self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 840, in do_handshake
    self._sslobj.do_handshake()
SSLError: [SSL: UNKNOWN_ALERT_TYPE] unknown alert type (_ssl.c:661)


[1] https://www.chromium.org/developers/design-documents/secure-web-proxy
msg288265 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-02-21 04:30
It looks like you are trying to tunnel one SSL or TLS connection through another SSL/TLS connection (instead of through a plain OS socket). There is already a bug recently opened about this: Issue 29394.

Basically, the SSL module doesn’t support this, and the documentation should be clarified to say something like wrap_socket() only accepts basic socket.socket() objects, not subclasses. However, in Python 3.5+ I think you could use the BIO layer to hook in your intermediate SSL socket (or any other transport).
History
Date User Action Args
2022-04-11 14:58:43adminsetgithub: 73796
2017-02-21 04:30:22martin.pantersetstatus: open -> closed

superseder: Cannot tunnel TLS connection through TLS connection

nosy: + martin.panter
messages: + msg288265
resolution: duplicate
stage: resolved
2017-02-21 04:26:46Phus Lusetassignee: christian.heimes

nosy: + christian.heimes
components: + SSL
versions: + Python 3.5
2017-02-21 03:29:07Phus Lucreate