Recv / send on raw socket before SSL wrap (), Python

I am wondering if I can return / send data on a raw socket before packing it - I looked at the documentation and looked for it, but could not find anything specific. What I basically want to do:

client, addr = listeningSocket.accept()
client.recv(32)
client.send(b'hello')
client.setblocking(0)
sslSocket = ssl.wrap_socket(client, keyfile='key.pem', certfile='cert.pem', server_side=True, ssl_version=ssl.PROTOCOL_TLSv1)
sslSocket.write(b'hello')

The problem is that I get an error message that I am sure is related to client.recv () before porting (or at least I think this is because I don't get it before adding recv?)

sslSocket = ssl.wrap_socket(client, keyfile='key.pem', certfile='cert.pem', server_side=True, ssl_version=ssl.PROTOCOL_TLSv1)
  File "/usr/lib/python3.1/ssl.py", line 381, in wrap_socket
    suppress_ragged_eofs=suppress_ragged_eofs)
  File "/usr/lib/python3.1/ssl.py", line 135, in __init__
    raise x
  File "/usr/lib/python3.1/ssl.py", line 131, in __init__
    self.do_handshake()
  File "/usr/lib/python3.1/ssl.py", line 327, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [Errno 8] _ssl.c:488: EOF occurred in violation of protocol

Is it legal? Is there any need to do this (I really need to send it before packing, since the client expects an unprocessed string before the SSL data starts to flood). Please rate any recommendations.

Note. I need to respond to a flash policy request. The flash connection will be secure, but the policy request is not

+3
2

do_handshake (http://docs.python.org/library/ssl.html#ssl.SSLSocket.do_handshake), wrap_socket ( -) ssl.SSLError , try/except, , . , , , , do_handshake_on_connect = False wrap_socket , :

client, addr = listeningSocket.accept()
client.recv(32)
client.send(b'hello')
sslSocket = ssl.wrap_socket(client, keyfile='key.pem', certfile='cert.pem', server_side=True, ssl_version=ssl.PROTOCOL_TLSv1)
client.setblocking(0)
sslSocket.write(b'hello')

:

client, addr = listeningSocket.accept()
client.recv(32)
client.send(b'hello')
client.setblocking(0)

while True:
    try:
        client.do_handshake()
        break
    except ssl.SSLError, err:
        if err.args[0] == ssl.SSL_ERROR_WANT_READ:
            select.select([client], [], [])
        elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
            select.select([], [client], [])
        else:
            raise

sslSocket = ssl.wrap_socket(client, do_handshake_on_connect=False, keyfile='key.pem', certfile='cert.pem', server_side=True, ssl_version=ssl.PROTOCOL_TLSv1)
sslSocket.write(b'hello')

- Flash 843.

+1

, Flash, Flash .

0

Source: https://habr.com/ru/post/1754367/


All Articles