Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlovetox <philipp@hoerist.com>2020-04-18 22:44:59 +0300
committerlovetox <philipp@hoerist.com>2020-04-18 22:44:59 +0300
commitf64707859b018a0b4ad04aa09eb0d802345ca325 (patch)
tree7cd9ed52ebd93079fcb6d197748a292d9f462848
parent442eae7e26344df4a4b88611670731b79f616c68 (diff)
Use IDNA2008 for domain validation
-rw-r--r--README.md1
-rw-r--r--nbxmpp/protocol.py27
-rw-r--r--setup.cfg1
3 files changed, 13 insertions, 16 deletions
diff --git a/README.md b/README.md
index 389b986..7871307 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@
- GLib >= 2.60
- libsoup
- precis-i18n
+- idna
## Features
diff --git a/nbxmpp/protocol.py b/nbxmpp/protocol.py
index 79008f3..2b09aa3 100644
--- a/nbxmpp/protocol.py
+++ b/nbxmpp/protocol.py
@@ -22,9 +22,8 @@ import time
import hashlib
import socket
import functools
-import stringprep
+import idna
from base64 import b64encode
-from encodings import idna
from precis_i18n import get_profile
from nbxmpp.simplexml import Node
@@ -789,6 +788,9 @@ def validate_resourcepart(resourcepart):
@functools.lru_cache(maxsize=4096)
def validate_domainpart(domainpart):
+ if not domainpart:
+ raise DomainpartByteLimit
+
# Check if this is a IPV4 address
try:
socket.inet_aton(domainpart)
@@ -804,27 +806,20 @@ def validate_domainpart(domainpart):
except Exception:
pass
- if not domainpart or len(domainpart.encode()) > 1023:
- raise DomainpartByteLimit
-
if domainpart.endswith('.'): # RFC7622, 3.2
domainpart = domainpart[:-1]
try:
- new_labels = []
- for label in idna.dots.split(domainpart):
- new_label = idna.nameprep(label)
-
- # Check unassigned
- if any(stringprep.in_table_a1(x) for x in new_label):
- raise DomainpartNotAllowedChar
-
- new_labels.append(new_label)
-
- return ".".join(new_labels)
+ domainpart = idna.encode(domainpart)
except Exception:
raise DomainpartNotAllowedChar
+ length = len(domainpart)
+ if length == 0 or length > 1023:
+ raise DomainpartByteLimit
+
+ return domainpart.decode()
+
class JID:
"""
diff --git a/setup.cfg b/setup.cfg
index 4f20db0..767e97b 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -15,6 +15,7 @@ python_requires = >=3.7
packages = find:
install_requires =
precis-i18n>=1.0.0
+ idna
[options.packages.find]
exclude =