Python 3 port:
/!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
This commit is contained in:
parent
d21a6a660f
commit
fbfe96c505
1 changed files with 6336 additions and 6398 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT plugin for Hash functions (XEP-0300)
|
||||
|
|
@ -27,7 +27,7 @@ from twisted.words.xish import domish
|
|||
from twisted.words.protocols.jabber.xmlstream import XMPPHandler
|
||||
from twisted.internet import threads
|
||||
from twisted.internet import defer
|
||||
from zope.interface import implements
|
||||
from zope.interface import implementer
|
||||
from wokkel import disco, iwokkel
|
||||
from collections import OrderedDict
|
||||
import hashlib
|
||||
|
|
@ -46,7 +46,7 @@ PLUGIN_INFO = {
|
|||
}
|
||||
|
||||
NS_HASHES = "urn:xmpp:hashes:2"
|
||||
NS_HASHES_FUNCTIONS = u"urn:xmpp:hash-function-text-names:{}"
|
||||
NS_HASHES_FUNCTIONS = "urn:xmpp:hash-function-text-names:{}"
|
||||
BUFFER_SIZE = 2 ** 12
|
||||
ALGO_DEFAULT = "sha-256"
|
||||
|
||||
|
|
@ -55,10 +55,10 @@ class XEP_0300(object):
|
|||
# TODO: add blake after moving to Python 3
|
||||
ALGOS = OrderedDict(
|
||||
(
|
||||
(u"md5", hashlib.md5),
|
||||
(u"sha-1", hashlib.sha1),
|
||||
(u"sha-256", hashlib.sha256),
|
||||
(u"sha-512", hashlib.sha512),
|
||||
("md5", hashlib.md5),
|
||||
("sha-1", hashlib.sha1),
|
||||
("sha-256", hashlib.sha256),
|
||||
("sha-512", hashlib.sha512),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ class XEP_0300(object):
|
|||
)
|
||||
if has_feature:
|
||||
log.debug(
|
||||
u"Best hashing algorithm found for {jid}: {algo}".format(
|
||||
"Best hashing algorithm found for {jid}: {algo}".format(
|
||||
jid=to_jid.full(), algo=algo
|
||||
)
|
||||
)
|
||||
|
|
@ -156,7 +156,7 @@ class XEP_0300(object):
|
|||
hash_used_elt = next(parent.elements(NS_HASHES, "hash-used"))
|
||||
except StopIteration:
|
||||
raise exceptions.NotFound
|
||||
algo = hash_used_elt[u"algo"]
|
||||
algo = hash_used_elt["algo"]
|
||||
if not algo:
|
||||
raise exceptions.DataError
|
||||
return algo
|
||||
|
|
@ -172,7 +172,8 @@ class XEP_0300(object):
|
|||
assert algo
|
||||
hash_elt = domish.Element((NS_HASHES, "hash"))
|
||||
if hash_ is not None:
|
||||
hash_elt.addContent(base64.b64encode(hash_))
|
||||
b64_hash = base64.b64encode(hash_.encode('utf-8')).decode('utf-8')
|
||||
hash_elt.addContent(b64_hash)
|
||||
hash_elt["algo"] = algo
|
||||
return hash_elt
|
||||
|
||||
|
|
@ -181,12 +182,12 @@ class XEP_0300(object):
|
|||
|
||||
if multiple elements are found, the strongest managed one is returned
|
||||
@param (domish.Element): parent of <hash/> element
|
||||
@return (tuple[unicode, str]): (algo, hash) tuple
|
||||
@return (tuple[str, bytes]): (algo, hash) tuple
|
||||
both values can be None if <hash/> is empty
|
||||
@raise exceptions.NotFound: the element is not present
|
||||
@raise exceptions.DataError: the element is invalid
|
||||
"""
|
||||
algos = XEP_0300.ALGOS.keys()
|
||||
algos = list(XEP_0300.ALGOS.keys())
|
||||
hash_elt = None
|
||||
best_algo = None
|
||||
best_value = None
|
||||
|
|
@ -195,13 +196,13 @@ class XEP_0300(object):
|
|||
try:
|
||||
idx = algos.index(algo)
|
||||
except ValueError:
|
||||
log.warning(u"Proposed {} algorithm is not managed".format(algo))
|
||||
log.warning("Proposed {} algorithm is not managed".format(algo))
|
||||
algo = None
|
||||
continue
|
||||
|
||||
if best_algo is None or algos.index(best_algo) < idx:
|
||||
best_algo = algo
|
||||
best_value = base64.b64decode(unicode(hash_elt))
|
||||
best_value = base64.b64decode(str(hash_elt))
|
||||
|
||||
if not hash_elt:
|
||||
raise exceptions.NotFound
|
||||
|
|
@ -210,8 +211,8 @@ class XEP_0300(object):
|
|||
return best_algo, best_value
|
||||
|
||||
|
||||
@implementer(iwokkel.IDisco)
|
||||
class XEP_0300_handler(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
|
||||
hash_functions_names = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue