Edgewall Software

Ticket #7458: trac-0.11-hashlib.patch

File trac-0.11-hashlib.patch, 5.2 KB (added by mad, 4 years ago)

patch to replace the usage of the depecated md5 module with hashlib

  • contrib/htdigest.py

    diff -Nurp Trac-0.11.orig/contrib/htdigest.py Trac-0.11/contrib/htdigest.py
    old new  
    1717 
    1818import errno 
    1919import fileinput 
    20 import md5 
     20import hashlib 
    2121import sys 
    2222from optparse import OptionParser 
    2323from getpass import getpass 
    def get_digest(userprefix, password=None 
    3636    return make_digest(userprefix, password) 
    3737 
    3838def make_digest(userprefix, password): 
    39     return userprefix + md5.new(userprefix + password).hexdigest() 
     39    return userprefix + hashlib.md5(userprefix + password).hexdigest() 
    4040 
    4141usage = "%prog [-c] [-b] passwordfile realm username" 
    4242parser = OptionParser(usage=usage) 
  • trac/ticket/notification.py

    diff -Nurp Trac-0.11.orig/trac/ticket/notification.py Trac-0.11/trac/ticket/notification.py
    old new  
    1616# Author: Daniel Lundin <daniel@edgewall.com> 
    1717# 
    1818 
    19 import md5 
     19import hashlib 
    2020 
    2121from trac import __version__ 
    2222from trac.core import * 
    class TicketNotifyEmail(NotifyEmail): 
    284284        s = '%s.%08d.%d.%s' % (self.config.get('project', 'url'), 
    285285                               int(self.ticket.id), to_timestamp(modtime), 
    286286                               rcpt.encode('ascii', 'ignore')) 
    287         dig = md5.new(s).hexdigest() 
     287        dig = hashlib.md5(s).hexdigest() 
    288288        host = self.from_email[self.from_email.find('@') + 1:] 
    289289        msgid = '<%03d.%s@%s>' % (len(s), dig, host) 
    290290        return msgid 
  • trac/util/__init__.py

    diff -Nurp Trac-0.11.orig/trac/util/__init__.py Trac-0.11/trac/util/__init__.py
    old new  
    1818#         Matthew Good <trac@matt-good.net> 
    1919 
    2020import locale 
    21 import md5 
     21import hashlib 
    2222import os 
    2323import re 
    2424import sys 
    def md5crypt(password, salt, magic='$1$' 
    271271    # /* The password first, since that is what is most unknown */ 
    272272    # /* Then our magic string */ 
    273273    # /* Then the raw salt */ 
    274     m = md5.new() 
     274    m = hashlib.md5() 
    275275    m.update(password + magic + salt) 
    276276 
    277277    # /* Then just as many characters of the MD5(pw,salt,pw) */ 
    278     mixin = md5.md5(password + salt + password).digest() 
     278    mixin = hashlib.md5(password + salt + password).digest() 
    279279    for i in range(0, len(password)): 
    280280        m.update(mixin[i % 16]) 
    281281 
    def md5crypt(password, salt, magic='$1$' 
    293293 
    294294    # /* and now, just to make sure things don't run too fast */ 
    295295    for i in range(1000): 
    296         m2 = md5.md5() 
     296        m2 = hashlib.md5() 
    297297        if i & 1: 
    298298            m2.update(password) 
    299299        else: 
  • trac/web/api.py

    diff -Nurp Trac-0.11.orig/trac/web/api.py Trac-0.11/trac/web/api.py
    old new class Request(object): 
    243243        so that consecutive requests can be cached. 
    244244        """ 
    245245        if isinstance(extra, list): 
    246             import md5 
    247             m = md5.new() 
     246            import hashlib 
     247            m = hashlib.md5() 
    248248            for elt in extra: 
    249249                m.update(repr(elt)) 
    250250            extra = m.hexdigest() 
  • trac/web/auth.py

    diff -Nurp Trac-0.11.orig/trac/web/auth.py Trac-0.11/trac/web/auth.py
    old new try: 
    2222    import threading 
    2323except ImportError: 
    2424    import dummy_threading as threading 
    25 import md5 
     25import hashlib 
    2626import os 
    2727import re 
    2828import sys 
    from trac.config import BoolOption 
    3535from trac.core import * 
    3636from trac.web.api import IAuthenticator, IRequestHandler 
    3737from trac.web.chrome import INavigationContributor 
    38 from trac.util import hex_entropy, md5crypt 
     38from trac.util import hex_entropy, hashlibcrypt 
    3939 
    4040 
    4141class LoginModule(Component): 
    class DigestAuthentication(PasswordFileA 
    367367            self.send_auth_request(environ, start_response) 
    368368            return None 
    369369 
    370         kd = lambda x: md5.md5(':'.join(x)).hexdigest() 
     370        kd = lambda x: hashlib.md5(':'.join(x)).hexdigest() 
    371371        a1 = self.hash[auth['username']] 
    372372        a2 = kd([environ['REQUEST_METHOD'], auth['uri']]) 
    373373        # Is the response correct? 
  • trac/wiki/default-pages/TracStandalone

    diff -Nurp Trac-0.11.orig/trac/wiki/default-pages/TracStandalone Trac-0.11/trac/wiki/default-pages/TracStandalone
    old new If you don't have Apache available, you  
    111111{{{ 
    112112#!python 
    113113from optparse import OptionParser 
    114 import md5 
     114import hashlib 
    115115 
    116116# build the options 
    117117usage = "usage: %prog [options]" 
    if (options.username is None) or (option 
    128128    
    129129# Generate the string to enter into the htdigest file 
    130130realm = 'trac' 
    131 kd = lambda x: md5.md5(':'.join(x)).hexdigest() 
     131kd = lambda x: hashlib.md5(':'.join(x)).hexdigest() 
    132132print ':'.join((options.username, realm, kd([options.username, realm, options.password]))) 
    133133}}} 
    134134