Python ssl.SSL_ERROR_WANT_READ Examples
The following are 30
code examples of ssl.SSL_ERROR_WANT_READ().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ssl
, or try the search function
.
Example #1
Source File: test_ftplib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _do_ssl_shutdown(self): self._ssl_closing = True try: self.socket = self.socket.unwrap() except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return except OSError as err: # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return # from OpenSSL's SSL_shutdown(), corresponding to a # closed socket condition. See also: # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html pass self._ssl_closing = False if getattr(self, '_ccc', False) is False: super(SSLConnection, self).close() else: pass
Example #2
Source File: cores.py From aws-iot-device-sdk-python with Apache License 2.0 | 6 votes |
def _hasCredentialsNecessaryForWebsocket(self, allKeys): awsAccessKeyIdCandidate = allKeys.get("aws_access_key_id") awsSecretAccessKeyCandidate = allKeys.get("aws_secret_access_key") # None value is NOT considered as valid entries validEntries = awsAccessKeyIdCandidate is not None and awsAccessKeyIdCandidate is not None if validEntries: # Empty value is NOT considered as valid entries validEntries &= (len(awsAccessKeyIdCandidate) != 0 and len(awsSecretAccessKeyCandidate) != 0) return validEntries # This is an internal class that buffers the incoming bytes into an # internal buffer until it gets the full desired length of bytes. # At that time, this bufferedReader will be reset. # *Error handling: # For retry errors (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE, EAGAIN), # leave them to the paho _packet_read for further handling (ignored and try # again when data is available. # For other errors, leave them to the paho _packet_read for error reporting.
Example #3
Source File: providers.py From aws-iot-device-sdk-python with Apache License 2.0 | 6 votes |
def _receive_until(self, ssl_sock, criteria_function, extra_data=None): start_time = time.time() response = bytearray() number_bytes_read = 0 while True: # Python does not have do-while try: response.append(self._convert_to_int_py3(ssl_sock.read(1))) number_bytes_read += 1 except socket.error as err: if err.errno == ssl.SSL_ERROR_WANT_READ or err.errno == ssl.SSL_ERROR_WANT_WRITE: pass if criteria_function((number_bytes_read, response, extra_data)): return self.LOW_LEVEL_RC_COMPLETE, response if start_time + self._timeout_sec < time.time(): return self.LOW_LEVEL_RC_TIMEOUT, response
Example #4
Source File: providers.py From aws-iot-device-sdk-python with Apache License 2.0 | 6 votes |
def _send_discovery_request(self, ssl_sock, thing_name): request = self.REQUEST_TYPE_PREFIX + \ self.PAYLOAD_PREFIX + \ thing_name + \ self.PAYLOAD_SUFFIX + \ self.HOST_PREFIX + \ self._host + ":" + str(self._port) + \ self.HOST_SUFFIX self._logger.debug("Sending discover request: " + request) start_time = time.time() desired_length_to_write = len(request) actual_length_written = 0 while True: try: length_written = ssl_sock.write(request.encode("utf-8")) actual_length_written += length_written except socket.error as err: if err.errno == ssl.SSL_ERROR_WANT_READ or err.errno == ssl.SSL_ERROR_WANT_WRITE: pass if actual_length_written == desired_length_to_write: return self.LOW_LEVEL_RC_COMPLETE if start_time + self._timeout_sec < time.time(): return self.LOW_LEVEL_RC_TIMEOUT
Example #5
Source File: iostream.py From teleport with Apache License 2.0 | 6 votes |
def read_from_fd(self, buf): try: if self._ssl_accepting: # If the handshake hasn't finished yet, there can't be anything # to read (attempting to read may or may not raise an exception # depending on the SSL version) return None try: return self.socket.recv_into(buf) except ssl.SSLError as e: # SSLError is a subclass of socket.error, so this except # block must come first. if e.args[0] == ssl.SSL_ERROR_WANT_READ: return None else: raise except socket.error as e: if e.args[0] in _ERRNO_WOULDBLOCK: return None else: raise finally: buf = None
Example #6
Source File: transport.py From python-for-android with Apache License 2.0 | 6 votes |
def _continue_tls_handshake(self): """Continue a TLS handshake.""" try: logger.debug(" do_handshake()") self._socket.do_handshake() except ssl.SSLError as err: if err.args[0] == ssl.SSL_ERROR_WANT_READ: self._tls_state = "want_read" logger.debug(" want_read") self._state_cond.notify() return elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE: self._tls_state = "want_write" logger.debug(" want_write") self._write_queue.appendleft(TLSHandshake) return else: raise self._tls_state = "connected" self._set_state("connected") self.event(TLSConnectedEvent(self._socket.cipher(), self._socket.getpeercert()))
Example #7
Source File: test_ftplib.py From ironpython3 with Apache License 2.0 | 6 votes |
def _do_ssl_shutdown(self): self._ssl_closing = True try: self.socket = self.socket.unwrap() except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return except OSError as err: # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return # from OpenSSL's SSL_shutdown(), corresponding to a # closed socket condition. See also: # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html pass self._ssl_closing = False if getattr(self, '_ccc', False) is False: super(SSLConnection, self).close() else: pass
Example #8
Source File: test_ftplib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def _do_ssl_shutdown(self): self._ssl_closing = True try: self.socket = self.socket.unwrap() except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return except OSError as err: # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return # from OpenSSL's SSL_shutdown(), corresponding to a # closed socket condition. See also: # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html pass self._ssl_closing = False if getattr(self, '_ccc', False) is False: super(SSLConnection, self).close() else: pass
Example #9
Source File: iostream.py From teleport with Apache License 2.0 | 6 votes |
def read_from_fd(self, buf: Union[bytearray, memoryview]) -> Optional[int]: try: if self._ssl_accepting: # If the handshake hasn't finished yet, there can't be anything # to read (attempting to read may or may not raise an exception # depending on the SSL version) return None try: return self.socket.recv_into(buf, len(buf)) except ssl.SSLError as e: # SSLError is a subclass of socket.error, so this except # block must come first. if e.args[0] == ssl.SSL_ERROR_WANT_READ: return None else: raise except socket.error as e: if e.args[0] in _ERRNO_WOULDBLOCK: return None else: raise finally: del buf
Example #10
Source File: iostream.py From opendevops with GNU General Public License v3.0 | 6 votes |
def read_from_fd(self, buf: Union[bytearray, memoryview]) -> Optional[int]: try: if self._ssl_accepting: # If the handshake hasn't finished yet, there can't be anything # to read (attempting to read may or may not raise an exception # depending on the SSL version) return None try: return self.socket.recv_into(buf, len(buf)) except ssl.SSLError as e: # SSLError is a subclass of socket.error, so this except # block must come first. if e.args[0] == ssl.SSL_ERROR_WANT_READ: return None else: raise except socket.error as e: if e.args[0] in _ERRNO_WOULDBLOCK: return None else: raise finally: del buf
Example #11
Source File: iostream.py From pySINDy with MIT License | 6 votes |
def read_from_fd(self, buf): try: if self._ssl_accepting: # If the handshake hasn't finished yet, there can't be anything # to read (attempting to read may or may not raise an exception # depending on the SSL version) return None try: return self.socket.recv_into(buf) except ssl.SSLError as e: # SSLError is a subclass of socket.error, so this except # block must come first. if e.args[0] == ssl.SSL_ERROR_WANT_READ: return None else: raise except socket.error as e: if e.args[0] in _ERRNO_WOULDBLOCK: return None else: raise finally: buf = None
Example #12
Source File: common.py From ufora with Apache License 2.0 | 6 votes |
def readIntoBufferNonblock(sock, buff): read = 0 while True: try: msg = sock.recv(4096) if len(msg): read += len(msg) buff.append(msg) else: raise SocketClosed('socket was closed remotely') # returning '' is basically the same as a EAGAIN return read except ssl.SSLError as e: if e.errno == ssl.SSL_ERROR_WANT_READ: return read raise e except socket.error as e: if e.errno in (errno.EWOULDBLOCK, errno.EAGAIN): return read raise e
Example #13
Source File: TLSClient.py From pycepa with GNU General Public License v3.0 | 6 votes |
def readable(self, client): """ Callback when the socket is readable. If we need to do the TLS handshake, it will start that, otherwise it will attempt to read data from the socket. If we need more data to decrypt the data, it will save and continue. See core.TCPClient.readable() for more information. """ if not self.handshook: self.do_handshake() if not self.handshook: return try: super(TLSClient, self).readable(client) except ssl.SSLError as err: if err.args[0] != ssl.SSL_ERROR_WANT_READ: self.die() except socket.error as e: print(traceback.print_exc(e)) log.error('socket error: %s' % e) self.die()
Example #14
Source File: test_ftplib.py From ironpython2 with Apache License 2.0 | 6 votes |
def _do_ssl_shutdown(self): self._ssl_closing = True try: self.socket = self.socket.unwrap() except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return except socket.error as err: # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return # from OpenSSL's SSL_shutdown(), corresponding to a # closed socket condition. See also: # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html pass self._ssl_closing = False if getattr(self, '_ccc', False) is False: super(SSLConnection, self).close() else: pass
Example #15
Source File: TLSClient.py From pycepa with GNU General Public License v3.0 | 6 votes |
def do_handshake(self): """ Does the TLS handshake on a fresh connection. Local events raised: * handshook - indicates that the TLS handshake has completed and the socket is ready for use. """ try: self.sock.do_handshake() self.handshook = True self.trigger_local('handshook') except ssl.SSLError as err: if err.args[0] != ssl.SSL_ERROR_WANT_READ: self.die() except socket.error: self.die()
Example #16
Source File: XAsyncSockets.py From MicroWebSrv2 with MIT License | 6 votes |
def _doSSLHandshake(self) : count = 0 while count < 10 : try : self._socket.do_handshake() break except ssl.SSLError as sslErr : count += 1 if sslErr.args[0] == ssl.SSL_ERROR_WANT_READ : select([self._socket], [], [], 1) elif sslErr.args[0] == ssl.SSL_ERROR_WANT_WRITE : select([], [self._socket], [], 1) else : raise XAsyncTCPClientException('SSL : Bad handshake : %s' % sslErr) except Exception as ex : raise XAsyncTCPClientException('SSL : Handshake error : %s' % ex) # ------------------------------------------------------------------------
Example #17
Source File: tls.py From nsq-py with MIT License | 6 votes |
def wrap_socket(cls, socket): sock = ssl.wrap_socket(socket, ssl_version=ssl.PROTOCOL_TLSv1) while True: try: logger.info('Performing TLS handshade...') sock.do_handshake() break except ssl.SSLError as err: errs = ( ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE) if err.args[0] not in (errs): raise else: logger.info('Continuing TLS handshake...') logger.info('Socket wrapped') return sock
Example #18
Source File: test_ftplib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def send(self, data): try: return super(SSLConnection, self).send(data) except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN, ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return 0 raise
Example #19
Source File: test_ftplib.py From ironpython3 with Apache License 2.0 | 5 votes |
def _do_ssl_handshake(self): try: self.socket.do_handshake() except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return elif err.args[0] == ssl.SSL_ERROR_EOF: return self.handle_close() raise except OSError as err: if err.args[0] == errno.ECONNABORTED: return self.handle_close() else: self._ssl_accepting = False
Example #20
Source File: test_connection.py From nsq-py with MIT License | 5 votes |
def test_read_would_block_ssl_read(self): '''Returns no results if it would block on a SSL socket''' with mock.patch.object(self.connection, '_socket') as mock_socket: mock_socket.recv.side_effect = ssl.SSLError(ssl.SSL_ERROR_WANT_READ) self.assertEqual(self.connection.read(), [])
Example #21
Source File: test_connection.py From nsq-py with MIT License | 5 votes |
def test_flush_would_block_ssl_read(self): '''Honors ssl.SSL_ERROR_WANT_READ''' pending = deque([b'1', b'2', b'3']) with mock.patch.object(self.connection, '_socket') as mock_socket: with mock.patch.object(self.connection, '_pending', pending): mock_socket.send.side_effect = ssl.SSLError( ssl.SSL_ERROR_WANT_READ) self.assertEqual(self.connection.flush(), 0)
Example #22
Source File: test_ftplib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def send(self, data): try: return super(SSLConnection, self).send(data) except ssl.SSLError, err: if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN, ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return 0 raise
Example #23
Source File: test_ftplib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def _do_ssl_shutdown(self): self._ssl_closing = True try: self.socket = self.socket.unwrap() except ssl.SSLError, err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return
Example #24
Source File: test_ftplib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def _do_ssl_handshake(self): try: self.socket.do_handshake() except ssl.SSLError, err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return elif err.args[0] == ssl.SSL_ERROR_EOF: return self.handle_close() raise
Example #25
Source File: test_ftplib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def recv(self, buffer_size): try: return super(SSLConnection, self).recv(buffer_size) except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return b'' if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN): self.handle_close() return b'' raise
Example #26
Source File: test_ftplib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def recv(self, buffer_size): try: return super(SSLConnection, self).recv(buffer_size) except ssl.SSLError, err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return '' if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN): self.handle_close() return '' raise
Example #27
Source File: test_ftplib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _do_ssl_shutdown(self): self._ssl_closing = True try: self.socket = self.socket.unwrap() except ssl.SSLError, err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return
Example #28
Source File: test_ftplib.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def send(self, data): try: return super(SSLConnection, self).send(data) except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN, ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return 0 raise
Example #29
Source File: test_ftplib.py From ironpython3 with Apache License 2.0 | 5 votes |
def recv(self, buffer_size): try: return super(SSLConnection, self).recv(buffer_size) except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return b'' if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN): self.handle_close() return b'' raise
Example #30
Source File: test_ftplib.py From ironpython3 with Apache License 2.0 | 5 votes |
def send(self, data): try: return super(SSLConnection, self).send(data) except ssl.SSLError as err: if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN, ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return 0 raise