Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits: c5ee15c1 by Philipp Hörist at 2022-09-06T20:06:41+02:00 fix: Add missing __init__.py to examples
This makes `python -m nbxmpp.examples.client` work
- - - - - 88617bc1 by Philipp Hörist at 2022-09-06T21:41:46+02:00 feat: Expose TLS version and ciphersuite
- - - - - c78455d0 by Philipp Hörist at 2022-09-06T21:47:13+02:00 change: Add packaging as dependency
- - - - - e9c38fe4 by Philipp Hörist at 2022-09-06T21:47:30+02:00 ci: Update debian control file
- - - - -
9 changed files:
- README.md - debian/control - nbxmpp/client.py - nbxmpp/connection.py - nbxmpp/const.py - + nbxmpp/examples/__init__.py - nbxmpp/tcp.py - nbxmpp/util.py - setup.cfg
Changes:
===================================== README.md ===================================== @@ -9,6 +9,7 @@ - GLib >= 2.60 - libsoup - precis-i18n +- packaging - idna
## Optional Runtime Requirements
===================================== debian/control ===================================== @@ -1,15 +1,16 @@ Source: python3-nbxmpp-nightly -Section: python +Section: net Priority: optional Maintainer: Gajim Maintainers ci@gajim.org -Build-Depends: debhelper-compat (= 13), +Build-Depends: + debhelper (>= 13), dh-python, libglib2.0-0 (>= 2.60), gir1.2-soup-2.4, python3-all, python3-gi, - python3-gssapi, python3-idna, + python3-packaging, python3-precis-i18n, python3-setuptools, Standards-Version: 4.1.4 @@ -22,10 +23,14 @@ Package: python3-nbxmpp-nightly Architecture: all Depends: ${misc:Depends}, ${python3:Depends}, + libglib2.0-0 (>= 2.60), gir1.2-soup-2.4, - python3-gi + python3-gi, + python3-idna, + python3-packaging, + python3-precis-i18n, Recommends: python3-gssapi, Breaks: gajim (<< 1.4~) Description: Non blocking XMPP Python library - nbxmpp is a Python library that provides a way for Python applications - to use the XMPP network. This library was initially a fork of xmpppy. + python-nbxmpp is a Python library that provides a way for Python applications + to use the XMPP network. This library was initially a fork of xmpppy. \ No newline at end of file
===================================== nbxmpp/client.py ===================================== @@ -212,6 +212,14 @@ class Client(Observable): def ignore_tls_errors(self): return self._ignore_tls_errors
+ @property + def tls_version(self): + return self._con.tls_version + + @property + def ciphersuite(self): + return self._con.ciphersuite + def set_ignore_tls_errors(self, ignore): self._ignore_tls_errors = ignore
===================================== nbxmpp/connection.py ===================================== @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see http://www.gnu.org/licenses/.
+from typing import Optional + import logging
from gi.repository import Gio @@ -65,6 +67,14 @@ class Connection(Observable): self._ignore_tls_errors = ignore_tls_errors self._ignored_tls_errors = ignored_tls_errors
+ @property + def tls_version(self) -> Optional[int]: + return None + + @property + def ciphersuite(self) -> Optional[int]: + return None + @property def local_address(self): return self._local_address
===================================== nbxmpp/const.py ===================================== @@ -19,7 +19,14 @@ from enum import Enum from enum import IntEnum from functools import total_ordering
+from packaging.version import Version + from gi.repository import Gio +from gi.repository import GLib + + +GLIB_VERSION = Version( + f'{GLib.MAJOR_VERSION}.{GLib.MINOR_VERSION}.{GLib.MICRO_VERSION}')
class IqType(Enum):
===================================== nbxmpp/examples/__init__.py =====================================
===================================== nbxmpp/tcp.py ===================================== @@ -17,6 +17,7 @@
import logging from collections import deque +from typing import Optional
from gi.repository import GLib from gi.repository import Gio @@ -26,6 +27,7 @@ from nbxmpp.const import TCPState from nbxmpp.const import ConnectionType from nbxmpp.util import utf8_decode from nbxmpp.util import convert_tls_error_flags +from nbxmpp.util import min_version from nbxmpp.connection import Connection
log = logging.getLogger('nbxmpp.tcp') @@ -62,6 +64,24 @@ class TCPConnection(Connection):
self._keepalive_id = None
+ @property + def tls_version(self) -> Optional[int]: + if self._con is None: + return None + + if min_version('GLib', '2.69.0'): + tls_con = self._con.get_base_io_stream() + return tls_con.get_protocol_version() + + @property + def ciphersuite(self) -> Optional[int]: + if self._con is None: + return None + + if min_version('GLib', '2.69.0'): + tls_con = self._con.get_base_io_stream() + return tls_con.get_ciphersuite_name() + def connect(self): self.state = TCPState.CONNECTING
===================================== nbxmpp/util.py ===================================== @@ -31,13 +31,15 @@ import logging from logging import LoggerAdapter from collections import defaultdict import xml.etree.ElementTree as ET - from functools import lru_cache
+from packaging.version import Version + from gi.repository import Gio
from nbxmpp.protocol import DiscoInfoMalformed from nbxmpp.const import GIO_TLS_ERRORS +from nbxmpp.const import GLIB_VERSION from nbxmpp.namespaces import Namespace from nbxmpp.protocol import StanzaMalformed from nbxmpp.protocol import StreamHeader @@ -405,6 +407,12 @@ def is_websocket_stream_error(stanza: Node) -> bool: stanza.getNamespace() == Namespace.STREAMS)
+def min_version(name: str, min_version: str) -> bool: + if name == 'GLib': + return GLIB_VERSION >= Version(min_version) + raise ValueError('Unknown library name') + + class Observable: def __init__(self, log_: logging.Logger): self._log = log_
===================================== setup.cfg ===================================== @@ -18,6 +18,7 @@ python_requires = >=3.9 packages = find: install_requires = precis-i18n>=1.0.0 + packaging idna
[options.extras_require]
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/compare/1cc53fba4101075f5d9c95bd...