Edgewall Software

Ticket #7458: 7458-hashlib-r7376.patch

File 7458-hashlib-r7376.patch, 4.4 KB (added by Remy Blank <remy.blank@…>, 4 years ago)

Patch against 0.11-stable that implements the solution suggested by eblot

  • contrib/htdigest.py

    diff --git a/contrib/htdigest.py b/contrib/htdigest.py
    a b  
    1717 
    1818import errno 
    1919import fileinput 
    20 import md5 
    2120import sys 
    2221from optparse import OptionParser 
    2322from getpass import getpass 
     23 
     24# The md5 module is deprecated in Python 2.5 
     25try: 
     26    from hashlib import md5 
     27except ImportError: 
     28    from md5 import md5 
    2429 
    2530def ask_pass(): 
    2631    pass1 = getpass('New password: ') 
     
    3641    return make_digest(userprefix, password) 
    3742 
    3843def make_digest(userprefix, password): 
    39     return userprefix + md5.new(userprefix + password).hexdigest() 
     44    return userprefix + md5(userprefix + password).hexdigest() 
    4045 
    4146usage = "%prog [-c] [-b] passwordfile realm username" 
    4247parser = OptionParser(usage=usage) 
  • trac/ticket/notification.py

    diff --git a/trac/ticket/notification.py b/trac/ticket/notification.py
    a b  
    1616# Author: Daniel Lundin <daniel@edgewall.com> 
    1717# 
    1818 
    19 import md5 
    20  
    2119from trac import __version__ 
    2220from trac.core import * 
    2321from trac.config import * 
    2422from trac.notification import NotifyEmail 
     23from trac.util import md5 
    2524from trac.util.datefmt import to_timestamp 
    2625from trac.util.text import CRLF, wrap, to_unicode 
    2726 
     
    284283        s = '%s.%08d.%d.%s' % (self.config.get('project', 'url'), 
    285284                               int(self.ticket.id), to_timestamp(modtime), 
    286285                               rcpt.encode('ascii', 'ignore')) 
    287         dig = md5.new(s).hexdigest() 
     286        dig = md5(s).hexdigest() 
    288287        host = self.from_email[self.from_email.find('@') + 1:] 
    289288        msgid = '<%03d.%s@%s>' % (len(s), dig, host) 
    290289        return msgid 
  • trac/util/__init__.py

    diff --git a/trac/util/__init__.py b/trac/util/__init__.py
    a b  
    1818#         Matthew Good <trac@matt-good.net> 
    1919 
    2020import locale 
    21 import md5 
    2221import os 
    2322import re 
    2423import sys 
     
    2625import tempfile 
    2726from urllib import quote, unquote, urlencode 
    2827from itertools import izip 
     28 
     29# The md5 module is deprecated in Python 2.5 
     30try: 
     31    from hashlib import md5 
     32except ImportError: 
     33    from md5 import md5 
    2934 
    3035# Imports for backward compatibility 
    3136from trac.core import TracError 
     
    271276    # /* The password first, since that is what is most unknown */ 
    272277    # /* Then our magic string */ 
    273278    # /* Then the raw salt */ 
    274     m = md5.new() 
    275     m.update(password + magic + salt) 
     279    m = md5(password + magic + salt) 
    276280 
    277281    # /* Then just as many characters of the MD5(pw,salt,pw) */ 
    278     mixin = md5.md5(password + salt + password).digest() 
     282    mixin = md5(password + salt + password).digest() 
    279283    for i in range(0, len(password)): 
    280284        m.update(mixin[i % 16]) 
    281285 
     
    293297 
    294298    # /* and now, just to make sure things don't run too fast */ 
    295299    for i in range(1000): 
    296         m2 = md5.md5() 
     300        m2 = md5() 
    297301        if i & 1: 
    298302            m2.update(password) 
    299303        else: 
  • trac/web/api.py

    diff --git a/trac/web/api.py b/trac/web/api.py
    a b  
    2626import urlparse 
    2727 
    2828from trac.core import Interface, TracError 
    29 from trac.util import get_last_traceback 
     29from trac.util import get_last_traceback, md5 
    3030from trac.util.datefmt import http_date, localtz 
    3131from trac.web.href import Href 
    3232from trac.web.wsgi import _FileWrapper 
     
    244244        so that consecutive requests can be cached. 
    245245        """ 
    246246        if isinstance(extra, list): 
    247             import md5 
    248             m = md5.new() 
     247            m = md5() 
    249248            for elt in extra: 
    250249                m.update(repr(elt)) 
    251250            extra = m.hexdigest() 
  • trac/web/auth.py

    diff --git a/trac/web/auth.py b/trac/web/auth.py
    a b  
    2222    import threading 
    2323except ImportError: 
    2424    import dummy_threading as threading 
    25 import md5 
    2625import os 
    2726import re 
    2827import sys 
     
    3534from trac.core import * 
    3635from trac.web.api import IAuthenticator, IRequestHandler 
    3736from trac.web.chrome import INavigationContributor 
    38 from trac.util import hex_entropy, md5crypt 
     37from trac.util import hex_entropy, md5, md5crypt 
    3938 
    4039 
    4140class LoginModule(Component): 
     
    367366            self.send_auth_request(environ, start_response) 
    368367            return None 
    369368 
    370         kd = lambda x: md5.md5(':'.join(x)).hexdigest() 
     369        kd = lambda x: md5(':'.join(x)).hexdigest() 
    371370        a1 = self.hash[auth['username']] 
    372371        a2 = kd([environ['REQUEST_METHOD'], auth['uri']]) 
    373372        # Is the response correct?