Projet

Général

Profil

0001-python3-use-binascii-s-hexadecimal-encoding-hexlify-.patch

Paul Marillonnet, 06 mars 2019 19:56

Télécharger (3,29 ko)

Voir les différences:

Subject: [PATCH] python3: use binascii's hexadecimal encoding "hexlify"
 (#31163)

 src/authentic2/hashers.py    | 11 ++++++-----
 src/authentic2/middleware.py |  3 ++-
 2 files changed, 8 insertions(+), 6 deletions(-)
src/authentic2/hashers.py
1 1
import hashlib
2 2
import math
3 3
import base64
4
from binascii import hexlify
4 5
from collections import OrderedDict
5 6

  
6 7
from django.contrib.auth import hashers
......
138 139
        algo_name, salt_offset, hex_encode = OPENLDAP_ALGO_MAPPING[algo]
139 140
        salt, password = (password[salt_offset:], password[:salt_offset]) if salt_offset else ('', password)
140 141
        if hex_encode:
141
            password = password.encode('hex')
142
        return '%s$%s$%s' % (algo_name, salt.encode('hex'), password)
142
            password = hexlify(password)
143
        return '%s$%s$%s' % (algo_name, hexlify(salt), password)
143 144
    else:
144 145
        return make_password(password)
145 146

  
......
149 150
        assert password
150 151
        assert '$' not in salt
151 152
        hash = self.digest(force_bytes(password + salt)).hexdigest()
152
        return "%s$%s$%s" % (self.algorithm, salt.encode('hex'), hash)
153
        return "%s$%s$%s" % (self.algorithm, hexlify(salt), hash)
153 154

  
154 155
    def verify(self, password, encoded):
155 156
        algorithm, salt, hash = encoded.split('$', 2)
......
199 200
        assert password
200 201
        assert '$' not in salt
201 202
        hash = self.digest(force_bytes(password + salt)).hexdigest()
202
        return "%s$md5$%s$%s" % (self.algorithm, salt.encode('hex'), hash)
203
        return "%s$md5$%s$%s" % (self.algorithm, hexlify(salt), hash)
203 204

  
204 205
    def verify(self, password, encoded):
205 206
        algorithm, subalgo, salt, hash = encoded.split('$', 3)
......
222 223
                h, salt = encoded.split(':', 1)
223 224
            else:
224 225
                h, salt = encoded, ''
225
            return '%s$md5$%s$%s' % (cls.algorithm, salt.encode('hex'), h)
226
            return '%s$md5$%s$%s' % (cls.algorithm, hexlify(salt), h)
226 227

  
227 228
    @classmethod
228 229
    def to_joomla(cls, encoded):
src/authentic2/middleware.py
9 9
except ImportError:
10 10
    threading = None
11 11

  
12
from binascii import hexlify
12 13
from django.conf import settings
13 14
from django.contrib import messages
14 15
from django.utils.translation import ugettext as _
......
130 131
                # Use Mersennes Twister rng, no need for a cryptographic grade
131 132
                # rng in this case
132 133
                random_id = random.getrandbits(32)
133
                request.request_id = struct.pack('I', random_id).encode('hex')
134
                request.request_id = hexlify(struct.pack('I', random_id))
134 135

  
135 136
class StoreRequestMiddleware(object):
136 137
    collection = {}
137
-