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: Two Layers of SSL/TLS
Type: Stage: resolved
Components: SSL Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: christian.heimes, mjbmr
Priority: normal Keywords:

Created on 2021-08-25 19:25 by mjbmr, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg400291 - (view) Author: Mjbmr (mjbmr) Date: 2021-08-25 19:25
A simple script, trying connect to second ssl through first sever doesn't work:

import socket, ssl

sock = socket.socket()
sock.connect(('<FIRST_SERVER>', 443))
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
sock = ctx.wrap_socket(sock)
sock.send(b'CONNECT <SECOND_SERVER>:443 HTTP/1.1\r\n\r\n')
print(sock.recv(1024))
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
sock = ctx.wrap_socket(sock)
sock.do_handshake()
sock.send(b'CONNECT ifconf.me:80 HTTP/1.1\r\n\r\n')
print(sock.recv(1024))


b'HTTP/1.1 200 Connection established\r\n\r\n'
Traceback (most recent call last):
  File "C:\Users\Javad\Desktop\4.py", line 15, in <module>
    sock = ctx.wrap_socket(sock)
  File "E:\Categories\Python\Python3.9.6\lib\ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "E:\Categories\Python\Python3.9.6\lib\ssl.py", line 1040, in _create
    self.do_handshake()
  File "E:\Categories\Python\Python3.9.6\lib\ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
msg400293 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-08-25 19:30
You cannot wrap an SSLSocket in another SSLSocket. It doesn't work due to the way how OpenSSL's BIO layer wraps the system socket. You have to use  SSLObject and SSLContext.wrap_bio() for the inner layer.
msg400295 - (view) Author: Mjbmr (mjbmr) Date: 2021-08-25 19:50
Is there any public document about this or can you give me an example? I can't figure it out what's the incoming and outgoing.
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89168
2021-08-25 21:03:59mjbmrsetstatus: closed -> open
resolution: wont fix ->
2021-08-25 19:50:04mjbmrsetmessages: + msg400295
2021-08-25 19:30:50christian.heimessetstatus: open -> closed
resolution: wont fix
messages: + msg400293

stage: resolved
2021-08-25 19:25:56mjbmrcreate