Bacula-users

Re: [Bacula-users] python implementation of bacula md5

2010-09-12 16:14:42
Subject: Re: [Bacula-users] python implementation of bacula md5
From: Rory Campbell-Lange <rory AT campbell-lange DOT net>
To: James Harper <james.harper AT bendigoit.com DOT au>
Date: Sun, 12 Sep 2010 21:10:43 +0100
On 12/09/10, James Harper (james.harper AT bendigoit.com DOT au) wrote:
> > I noted in my email of 14 August that I had a file with a bacula md5
> > that I was not able to match using the (Linux, Debian stable) md5 cli
> > utility.

> From memory, the MD5 is 'correct', but the base64 translation is a bit
> funny. Here's a C# version I wrote quite a while back, if it's any help.
> It's the baculaBase64 routine that's probably the most useful:

Hi James

Thanks very much for this. While trying to translate your routines into
python I came across the md5/base64 encoding routine at
http://effbot.org/librarybook/md5.htm. 

My code, which is slightly modified from the effbot original, is set out below
and works well for my purposes.

Thanks very much for posting your code.

Regards
Rory

"""
md5 sum utility with base64 encoding
adapted from http://effbot.org/librarybook/md5.htm
"""

import hashlib
import base64
import sys
import os

try:
    filename = sys.argv[1]
except IndexError:
    print "Filename required"
    sys.exit(1)

try:
    assert os.path.isfile(filename)
except AssertionError:
    print "File does not exist"
    sys.exit(1)

hash = hashlib.md5() # also possible : SHA1, SHA224, SHA256, SHA384, and SHA512 
for l in open(filename):
    hash.update(l)
value = hash.digest()

b64 = base64.encodestring(value)

# Take off the trailing '=' signs as bacula does not use them
# http://support.microsoft.com/kb/191239 suggests trailing = signs should be
# used for RFC 1521 compliance
# wierdly, a newline seems to be added to be encodedstring too, so this also
# needs to be stripped off.
print b64.strip().rstrip('=')


-- 
Rory Campbell-Lange
rory AT campbell-lange DOT net

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users

<Prev in Thread] Current Thread [Next in Thread>