Philipp Hörist pushed to branch master at gajim / gajim

Commits:

5 changed files:

Changes:

  • gajim/common/client.py
    ... ... @@ -33,7 +33,6 @@ from gajim.common.helpers import get_custom_host
    33 33
     from gajim.common.helpers import get_user_proxy
    
    34 34
     from gajim.common.helpers import warn_about_plain_connection
    
    35 35
     from gajim.common.helpers import get_resource
    
    36
    -from gajim.common.helpers import get_ignored_tls_errors
    
    37 36
     from gajim.common.helpers import get_idle_status_message
    
    38 37
     from gajim.common.idle import Monitor
    
    39 38
     from gajim.common.i18n import _
    
    ... ... @@ -79,8 +78,6 @@ class Client(ConnectionHandlers):
    79 78
             self._destroy_client = False
    
    80 79
             self._remove_account = False
    
    81 80
     
    
    82
    -        self._tls_errors = set()
    
    83
    -
    
    84 81
             self._destroyed = False
    
    85 82
     
    
    86 83
             self.available_transports = {}
    
    ... ... @@ -177,9 +174,6 @@ class Client(ConnectionHandlers):
    177 174
             self._client.set_accepted_certificates(
    
    178 175
                 app.cert_store.get_certificates())
    
    179 176
     
    
    180
    -        self._client.set_ignored_tls_errors(
    
    181
    -            get_ignored_tls_errors(self._account))
    
    182
    -
    
    183 177
             if app.config.get_per('accounts', self._account,
    
    184 178
                                   'use_plain_connection'):
    
    185 179
                 self._client.set_connection_types([ConnectionType.PLAIN])
    
    ... ... @@ -200,17 +194,6 @@ class Client(ConnectionHandlers):
    200 194
             for handler in modules.get_handlers(self):
    
    201 195
                 self._client.register_handler(handler)
    
    202 196
     
    
    203
    -    def process_tls_errors(self):
    
    204
    -        if not self._tls_errors:
    
    205
    -            self.connect(ignore_all_errors=True)
    
    206
    -            return
    
    207
    -
    
    208
    -        open_window('SSLErrorDialog',
    
    209
    -                    account=self._account,
    
    210
    -                    connection=self,
    
    211
    -                    cert=self._client.peer_certificate[0],
    
    212
    -                    error_num=self._tls_errors.pop())
    
    213
    -
    
    214 197
         def _on_resume_failed(self, _client, _signal_name):
    
    215 198
             log.info('Resume failed')
    
    216 199
             app.nec.push_incoming_event(NetworkEvent(
    
    ... ... @@ -261,13 +244,16 @@ class Client(ConnectionHandlers):
    261 244
                 self._reconnect = False
    
    262 245
     
    
    263 246
             elif domain == StreamError.BAD_CERTIFICATE:
    
    264
    -            self._tls_errors = self._client.peer_certificate[1]
    
    265
    -            self.get_module('Chatstate').enabled = False
    
    266 247
                 self._reconnect = False
    
    267
    -            self._after_disconnect()
    
    268
    -            app.nec.push_incoming_event(NetworkEvent(
    
    269
    -                'our-show', account=self._account, show='offline'))
    
    270
    -            self.process_tls_errors()
    
    248
    +            self._destroy_client = True
    
    249
    +
    
    250
    +            cert, errors = self._client.peer_certificate
    
    251
    +
    
    252
    +            open_window('SSLErrorDialog',
    
    253
    +                        account=self._account,
    
    254
    +                        client=self,
    
    255
    +                        cert=cert,
    
    256
    +                        error=errors.pop())
    
    271 257
     
    
    272 258
             elif domain in (StreamError.STREAM, StreamError.BIND):
    
    273 259
                 if error == 'conflict':
    
    ... ... @@ -277,6 +263,7 @@ class Client(ConnectionHandlers):
    277 263
     
    
    278 264
             elif domain == StreamError.SASL:
    
    279 265
                 self._reconnect = False
    
    266
    +            self._destroy_client = True
    
    280 267
     
    
    281 268
                 if error in ('not-authorized', 'no-password'):
    
    282 269
                     def _on_password(password):
    
    ... ... @@ -511,29 +498,29 @@ class Client(ConnectionHandlers):
    511 498
                 message.stanza = stanza
    
    512 499
                 self._send_message(message)
    
    513 500
     
    
    514
    -    def connect(self, ignore_all_errors=False):
    
    501
    +    def connect(self, ignored_tls_errors=None):
    
    515 502
             if self._state not in (ClientState.DISCONNECTED,
    
    516 503
                                    ClientState.RECONNECT_SCHEDULED):
    
    517 504
                 # Do not try to reco while we are already trying
    
    518 505
                 return
    
    519 506
     
    
    520 507
             log.info('Connect')
    
    508
    +
    
    509
    +        self._client.set_ignored_tls_errors(ignored_tls_errors)
    
    521 510
             self._reconnect = True
    
    522 511
             self._disable_reconnect_timer()
    
    523 512
             self._set_state(ClientState.CONNECTING)
    
    524
    -        if ignore_all_errors:
    
    525
    -            self._client.set_ignore_tls_errors(True)
    
    526
    -            self._client.connect()
    
    527
    -        else:
    
    528
    -            if warn_about_plain_connection(self._account,
    
    529
    -                                           self._client.connection_types):
    
    530
    -                app.nec.push_incoming_event(NetworkEvent(
    
    531
    -                    'plain-connection',
    
    532
    -                    account=self._account,
    
    533
    -                    connect=self._client.connect,
    
    534
    -                    abort=self._abort_reconnect))
    
    535
    -                return
    
    536
    -            self._client.connect()
    
    513
    +
    
    514
    +        if warn_about_plain_connection(self._account,
    
    515
    +                                       self._client.connection_types):
    
    516
    +            app.nec.push_incoming_event(NetworkEvent(
    
    517
    +                'plain-connection',
    
    518
    +                account=self._account,
    
    519
    +                connect=self._client.connect,
    
    520
    +                abort=self._abort_reconnect))
    
    521
    +            return
    
    522
    +
    
    523
    +        self._client.connect()
    
    537 524
     
    
    538 525
         def _schedule_reconnect(self):
    
    539 526
             self._set_state(ClientState.RECONNECT_SCHEDULED)
    

  • gajim/common/config.py
    ... ... @@ -278,7 +278,6 @@ class Config:
    278 278
                 'keyname': [opt_str, '', '', True],
    
    279 279
                 'use_plain_connection': [opt_bool, False, _('Use an unencrypted connection to the server')],
    
    280 280
                 'action_when_plain_connection': [opt_str, 'warn', _('Show a warning dialog before sending password on an plaintext connection. Can be \'warn\', or \'none\'.')],
    
    281
    -            'ignore_ssl_errors': [opt_str, '', _('List of SSL errors to ignore (space separated).')],
    
    282 281
                 'use_custom_host': [opt_bool, False, '', True],
    
    283 282
                 'custom_port': [opt_int, 5222, '', True],
    
    284 283
                 'custom_host': [opt_str, '', '', True],
    

  • gajim/common/helpers.py
    ... ... @@ -1402,12 +1402,6 @@ def warn_about_plain_connection(account, connection_types):
    1402 1402
         return False
    
    1403 1403
     
    
    1404 1404
     
    
    1405
    -def get_ignored_tls_errors(account):
    
    1406
    -    ignore_ssl_errors = app.config.get_per(
    
    1407
    -        'accounts', account, 'ignore_ssl_errors').split()
    
    1408
    -    return {Gio.TlsCertificateFlags(int(err)) for err in ignore_ssl_errors}
    
    1409
    -
    
    1410
    -
    
    1411 1405
     def get_idle_status_message(state, status_message):
    
    1412 1406
         message = app.config.get(f'auto{state}_message')
    
    1413 1407
         if not message:
    

  • gajim/data/gui/ssl_error_dialog.ui
    ... ... @@ -80,6 +80,7 @@
    80 80
             <property name="margin_right">15</property>
    
    81 81
             <property name="use_underline">True</property>
    
    82 82
             <property name="draw_indicator">True</property>
    
    83
    +        <signal name="toggled" handler="_on_add_certificate_toggled" swapped="no"/>
    
    83 84
           </object>
    
    84 85
           <packing>
    
    85 86
             <property name="expand">False</property>
    
    ... ... @@ -88,22 +89,7 @@
    88 89
           </packing>
    
    89 90
         </child>
    
    90 91
         <child>
    
    91
    -      <object class="GtkCheckButton" id="ignore_error_checkbutton">
    
    92
    -        <property name="label" translatable="yes">_Ignore this error for this certificate</property>
    
    93
    -        <property name="visible">True</property>
    
    94
    -        <property name="can_focus">True</property>
    
    95
    -        <property name="receives_default">False</property>
    
    96
    -        <property name="halign">start</property>
    
    97
    -        <property name="margin_left">15</property>
    
    98
    -        <property name="margin_right">15</property>
    
    99
    -        <property name="use_underline">True</property>
    
    100
    -        <property name="draw_indicator">True</property>
    
    101
    -      </object>
    
    102
    -      <packing>
    
    103
    -        <property name="expand">False</property>
    
    104
    -        <property name="fill">True</property>
    
    105
    -        <property name="position">5</property>
    
    106
    -      </packing>
    
    92
    +      <placeholder/>
    
    107 93
         </child>
    
    108 94
         <child>
    
    109 95
           <object class="GtkBox">
    
    ... ... @@ -133,6 +119,7 @@
    133 119
               <object class="GtkButton" id="connect_button">
    
    134 120
                 <property name="label" translatable="yes">_Connect</property>
    
    135 121
                 <property name="visible">True</property>
    
    122
    +            <property name="sensitive">False</property>
    
    136 123
                 <property name="can_focus">True</property>
    
    137 124
                 <property name="receives_default">True</property>
    
    138 125
                 <property name="halign">end</property>
    

  • gajim/gtk/ssl_error_dialog.py
    ... ... @@ -26,7 +26,7 @@ from gajim.gtk.util import open_window
    26 26
     
    
    27 27
     
    
    28 28
     class SSLErrorDialog(Gtk.ApplicationWindow):
    
    29
    -    def __init__(self, account, connection, cert, error_num):
    
    29
    +    def __init__(self, account, client, cert, error):
    
    30 30
             Gtk.ApplicationWindow.__init__(self)
    
    31 31
             self.set_name('SSLErrorDialog')
    
    32 32
             self.set_application(app.app)
    
    ... ... @@ -39,8 +39,8 @@ class SSLErrorDialog(Gtk.ApplicationWindow):
    39 39
             self.add(self._ui.ssl_error_box)
    
    40 40
     
    
    41 41
             self.account = account
    
    42
    -        self._error_num = error_num
    
    43
    -        self._con = connection
    
    42
    +        self._error = error
    
    43
    +        self._client = client
    
    44 44
             self._cert = cert
    
    45 45
             self._server = app.config.get_per('accounts', self.account, 'hostname')
    
    46 46
     
    
    ... ... @@ -54,30 +54,36 @@ class SSLErrorDialog(Gtk.ApplicationWindow):
    54 54
                 _('There was an error while attempting to verify the SSL '
    
    55 55
                   'certificate of your XMPP server (%s).') % self._server)
    
    56 56
     
    
    57
    -        unknown_error = _('Unknown SSL error \'%s\'') % self._error_num
    
    58
    -        ssl_error = GIO_TLS_ERRORS.get(self._error_num, unknown_error)
    
    57
    +        unknown_error = _('Unknown SSL error \'%s\'') % self._error
    
    58
    +        ssl_error = GIO_TLS_ERRORS.get(self._error, unknown_error)
    
    59 59
             self._ui.ssl_error.set_text(ssl_error)
    
    60 60
     
    
    61
    -        if self._error_num == Gio.TlsCertificateFlags.UNKNOWN_CA:
    
    61
    +        if self._error == Gio.TlsCertificateFlags.UNKNOWN_CA:
    
    62 62
                 self._ui.add_certificate_checkbutton.show()
    
    63 63
     
    
    64
    +        elif self._error == Gio.TlsCertificateFlags.EXPIRED:
    
    65
    +            self._ui.connect_button.set_sensitive(True)
    
    66
    +
    
    67
    +        else:
    
    68
    +            self._ui.connect_button.set_no_show_all(True)
    
    69
    +            self._ui.connect_button.hide()
    
    70
    +
    
    64 71
         def _on_view_cert_clicked(self, _button):
    
    65 72
             open_window('CertificateDialog',
    
    66 73
                         account=self.account,
    
    67 74
                         transient_for=self,
    
    68 75
                         cert=self._cert)
    
    69 76
     
    
    70
    -    def _on_connect_clicked(self, _button):
    
    71
    -        # Ignore this error
    
    72
    -        if self._ui.ignore_error_checkbutton.get_active():
    
    73
    -            ignore_ssl_errors = app.config.get_per(
    
    74
    -                'accounts', self.account, 'ignore_ssl_errors').split()
    
    75
    -            ignore_ssl_errors.append(str(int(self._error_num)))
    
    76
    -            app.config.set_per('accounts', self.account, 'ignore_ssl_errors',
    
    77
    -                               ' '.join(ignore_ssl_errors))
    
    77
    +    def _on_add_certificate_toggled(self, checkbutton):
    
    78
    +        self._ui.connect_button.set_sensitive(checkbutton.get_active())
    
    78 79
     
    
    80
    +    def _on_connect_clicked(self, _button):
    
    79 81
             if self._ui.add_certificate_checkbutton.get_active():
    
    80 82
                 app.cert_store.add_certificate(self._cert)
    
    81 83
     
    
    84
    +        ignored_tls_errors = None
    
    85
    +        if self._error == Gio.TlsCertificateFlags.EXPIRED:
    
    86
    +            ignored_tls_errors = set([Gio.TlsCertificateFlags.EXPIRED])
    
    87
    +
    
    82 88
             self.destroy()
    
    83
    -        self._con.process_tls_errors()
    89
    +        self._client.connect(ignored_tls_errors=ignored_tls_errors)