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:
Goffi 2019-08-13 19:08:41 +02:00
commit fbfe96c505

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -92,7 +92,7 @@ class BlockCipher(object):
# a decrypted empty value and a decryption failure... both return
# the empty value. Fortunately, we detect empty passwords beforehand
# thanks to the "leave_empty" parameter which is used by default.
d.addCallback(lambda text: text.decode("utf-8") if text else None)
d.addCallback(lambda text: text if text else None)
return d
@classmethod
@ -114,11 +114,12 @@ class BlockCipher(object):
def pad(self, s):
"""Method from http://stackoverflow.com/a/12525165"""
bs = BlockCipher.BLOCK_SIZE
return s + (bs - len(s) % bs) * chr(bs - len(s) % bs)
return s + (bs - len(s) % bs) * (chr(bs - len(s) % bs)).encode('utf-8')
@classmethod
def unpad(self, s):
"""Method from http://stackoverflow.com/a/12525165"""
s = s.decode('utf-8')
return s[0 : -ord(s[-1])]
@ -136,7 +137,7 @@ class PasswordHasher(object):
@return: Deferred: base-64 encoded str
"""
if leave_empty and password == "":
return succeed(password)
return succeed(b"")
salt = (
b64decode(salt)[: PasswordHasher.SALT_LEN]
if salt
@ -146,6 +147,11 @@ class PasswordHasher(object):
d.addCallback(lambda hashed: b64encode(salt + hashed))
return d
@classmethod
def compare_hash(cls, hashed_attempt, hashed):
assert isinstance(hashed, bytes)
return hashed_attempt == hashed
@classmethod
def verify(cls, attempt, hashed):
"""Verify a password attempt.
@ -156,5 +162,5 @@ class PasswordHasher(object):
"""
leave_empty = hashed == ""
d = PasswordHasher.hash(attempt, hashed, leave_empty)
d.addCallback(lambda hashed_attempt: hashed_attempt == hashed)
d.addCallback(cls.compare_hash, hashed=hashed.encode('utf-8'))
return d