Commit 88617bc1 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

feat: Expose TLS version and ciphersuite

parent c5ee15c1
......@@ -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
......
......@@ -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
......
......@@ -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):
......
......@@ -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
......
......@@ -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_
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment