Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits: 45197eaf by lovetox at 2020-03-10T20:04:53+01:00 Remove trailing whitespace
- - - - - 7b97addb by lovetox at 2020-03-10T20:12:31+01:00 Remove unused import
- - - - - 6113c4f5 by lovetox at 2020-03-10T21:13:48+01:00 TCP: Consider failed TLS handshake as connection-failed
- - - - -
2 changed files:
- nbxmpp/client.py - nbxmpp/tcp.py
Changes:
===================================== nbxmpp/client.py ===================================== @@ -307,7 +307,7 @@ class Client(Observable): def connect(self): if self._state != StreamState.DISCONNECTED: log.error('Stream can't reconnect, stream state: %s', self._state) - return + return
if self._connect_successful: log.info('Reconnect') @@ -384,7 +384,6 @@ class Client(Observable): return self.send_stanza(stanza)
def _on_connected(self, _connection, _signal_name): - self._connect_successful = True self.set_state(StreamState.CONNECTED)
def _on_disconnected(self, _connection, _signal_name): @@ -545,6 +544,14 @@ class Client(Observable): 'Invalid stream header') return
+ if (self._stream_secure or + self.current_connection_type == ConnectionType.PLAIN): + # TLS Negotiation succeeded or we are connected PLAIN + # We received the stream header and consider this as + # successfully connected, this means we will not try + # other connection methods if an error happensafterwards + self._connect_successful = True + self.state = StreamState.WAIT_FOR_FEATURES
elif self.state == StreamState.WAIT_FOR_FEATURES:
===================================== nbxmpp/tcp.py ===================================== @@ -16,7 +16,6 @@ # along with this program; If not, see http://www.gnu.org/licenses/.
import logging -import struct from collections import deque
from gi.repository import GLib @@ -56,6 +55,7 @@ class TCPConnection(Connection): self._connect_cancellable = Gio.Cancellable() self._read_cancellable = Gio.Cancellable()
+ self._tls_handshake_in_progress = False self._input_closed = False self._output_closed = False
@@ -103,6 +103,7 @@ class TCPConnection(Connection): self._peer_certificate = connection.props.peer_certificate self._peer_certificate_errors = convert_tls_error_flags( connection.props.peer_certificate_errors) + self._tls_handshake_in_progress = False self.notify('certificate-set')
def _on_connect_finished(self, client, result, _user_data): @@ -154,6 +155,7 @@ class TCPConnection(Connection):
def start_tls_negotiation(self): log.info('Start TLS negotiation') + self._tls_handshake_in_progress = True remote_address = self._con.get_remote_address() identity = Gio.NetworkAddress.new(self._address.domain, remote_address.props.port) @@ -193,6 +195,12 @@ class TCPConnection(Connection): return
quark = GLib.quark_try_string('g-tls-error-quark') + if error.matches(quark, Gio.TlsError.MISC): + if self._tls_handshake_in_progress: + log.error('Handshake failed: %s', error) + self._finalize('connection-failed') + return + if error.matches(quark, Gio.TlsError.EOF): log.info('Incoming stream closed: TLS EOF') self._finalize('disconnected')
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/compare/b2f3eeddd79dec534e508c41...