Beispiel #1
0
    def login(self, module='', user='', passwd=''):
        if not user: user = '******'
        if not passwd: passwd = 'www'
        if not module: module = 'www'

        self.putline(self.server_protocol_version)
        #        self.putline('@RSYNCD: 28.0')
        #        self.protocol_version = 28
        resp = self.sendcmd(module)

        challenge = resp[resp.find('AUTHREQD ') + 9:]

        if self.protocol_version >= 30:
            md5 = hashlib.md5()
            md5.update(passwd)
            md5.update(challenge)
            hash = base64.b64encode(md5.digest())
        else:
            md4 = hashlib.new('md4')
            tmp = '\0\0\0\0' + passwd + challenge
            md4.update(tmp)
            hash = base64.b64encode(md4.digest())

        response, number = re.subn(r'=+$', '', hash)
        print response
        resp = self.sendcmd(user + ' ' + response)

        if resp.find('OK') == -1:
            raise Error, resp
        return resp
    def login(self, module='', user = '', passwd = ''):
        if not user: user = '******'
        if not passwd: passwd = 'www'
        if not module: module = 'www'

        self.putline(self.server_protocol_version)
#        self.putline('@RSYNCD: 28.0')
#        self.protocol_version = 28
        resp = self.sendcmd(module)

        challenge = resp[resp.find('AUTHREQD ')+9:]

        if self.protocol_version >= 30:
            md5=hashlib.md5()
            md5.update(passwd)
            md5.update(challenge)
            hash = base64.b64encode(md5.digest())
        else:
            md4=hashlib.new('md4')
            tmp = '\0\0\0\0' + passwd + challenge
            md4.update(tmp)
            hash = base64.b64encode(md4.digest())

        response, number = re.subn(r'=+$','',hash)
        resp = self.sendcmd(user + ' ' + response)

        if resp.find('OK') == -1:
            raise Error, resp
        return resp
Beispiel #3
0
 def md5(indata):
     try:
         import hashlib
         md5 = hashlib.md5(indata)
     except ImportError:
         import md5
         md5 = md5.new(indata)
     return md5.digest()
Beispiel #4
0
def md5(indata):
	try:
		import hashlib
		md5 = hashlib.md5(indata)
	except ImportError:
		import md5
		md5 = md5.new(indata)
	return md5.digest()
Beispiel #5
0
def _assemble(nzf, path, dupe):
    if os.path.exists(path):
        unique_path = get_unique_filename(path)
        if dupe:
            path = unique_path
        else:
            renamer(path, unique_path)

    fout = open(path, "ab")

    if cfg.quick_check():
        md5 = new_md5()
    else:
        md5 = None

    decodetable = nzf.decodetable

    for articlenum in decodetable:
        # Break if deleted during writing
        if nzf.nzo.status is Status.DELETED:
            break

        # Sleep to allow decoder/assembler switching
        sleep(0.001)
        article = decodetable[articlenum]

        data = ArticleCache.do.load_article(article)

        if not data:
            logging.info(T("%s missing"), article)
        else:
            # yenc data already decoded, flush it out
            fout.write(data)
            if md5:
                md5.update(data)

    fout.flush()
    fout.close()
    set_permissions(path)
    if md5:
        nzf.md5sum = md5.digest()
        del md5

    return path
Beispiel #6
0
def _assemble(nzf, path, dupe):
    if os.path.exists(path):
        unique_path = get_unique_filename(path)
        if dupe:
            path = unique_path
        else:
            renamer(path, unique_path)

    fout = open(path, 'ab')

    if cfg.quick_check():
        md5 = new_md5()
    else:
        md5 = None

    decodetable = nzf.decodetable

    for articlenum in decodetable:
        # Break if deleted during writing
        if nzf.nzo.status is Status.DELETED:
            break

        # Sleep to allow decoder/assembler switching
        sleep(0.001)
        article = decodetable[articlenum]

        data = ArticleCache.do.load_article(article)

        if not data:
            logging.info(T('%s missing'), article)
        else:
            # yenc data already decoded, flush it out
            fout.write(data)
            if md5:
                md5.update(data)

    fout.flush()
    fout.close()
    set_permissions(path)
    if md5:
        nzf.md5sum = md5.digest()
        del md5

    return path
Beispiel #7
0
def ParseFilePacket(f, header):
    """ Look up and analyse a FileDesc package """

    nothing = None, None

    if header != 'PAR2\0PKT':
        return nothing

    # Length must be multiple of 4 and at least 20
    len = struct.unpack('<Q', f.read(8))[0]
    if int(len / 4) * 4 != len or len < 20:
        return nothing

    # Next 16 bytes is md5sum of this packet
    md5sum = f.read(16)

    # Read and check the data
    data = f.read(len - 32)
    md5 = new_md5()
    md5.update(data)
    if md5sum != md5.digest():
        return nothing

    # The FileDesc packet looks like:
    # 16 : "PAR 2.0\0FileDesc"
    # 16 : FileId
    # 16 : Hash for full file **
    # 16 : Hash for first 16K
    #  8 : File length
    # xx : Name (multiple of 4, padded with \0 if needed) **

    # See if it's the right packet and get name + hash
    for offset in range(0, len, 8):
        if data[offset:offset + 16] == "PAR 2.0\0FileDesc":
            hash = data[offset + 32:offset + 48]
            filename = data[offset + 72:].strip('\0')
            return filename, hash

    return nothing
Beispiel #8
0
def ParseFilePacket(f, header):
    """ Look up and analyse a FileDesc package """

    nothing = None, None

    if header != 'PAR2\0PKT':
        return nothing

    # Length must be multiple of 4 and at least 20
    len = struct.unpack('<Q', f.read(8))[0]
    if int(len/4)*4 != len or len < 20:
        return nothing

    # Next 16 bytes is md5sum of this packet
    md5sum = f.read(16)

    # Read and check the data
    data = f.read(len-32)
    md5 = new_md5()
    md5.update(data)
    if md5sum != md5.digest():
        return nothing

    # The FileDesc packet looks like:
    # 16 : "PAR 2.0\0FileDesc"
    # 16 : FileId
    # 16 : Hash for full file **
    # 16 : Hash for first 16K
    #  8 : File length
    # xx : Name (multiple of 4, padded with \0 if needed) **

    # See if it's the right packet and get name + hash
    for offset in range(0, len, 8):
        if data[offset:offset+16] == "PAR 2.0\0FileDesc":
            hash = data[offset+32:offset+48]
            filename = data[offset+72:].strip('\0')
            return filename, hash

    return nothing
Beispiel #9
0
                        nbytes = (((ord(line[0]) - 32) & 63) * 4 + 5) / 3
                        try:
                            tmpdata = binascii.a2b_uu(line[:nbytes])
                            chunks.append(tmpdata)
                        except binascii.Error, msg:
                            logging.info('Decode failed in part %s: %s',
                                         article.article, msg)
                data = ''.join(chunks)
                fout.write(data)
                if md5: md5.update(data)

    fout.flush()
    fout.close()
    set_permissions(path)
    if md5:
        nzf.md5sum = md5.digest()
        del md5

    return path


def file_has_articles(nzf):
    """ Do a quick check to see if any articles are present for this file.
        Destructive: only to be used to differentiate between unknown encoding and no articles.
    """
    has = False
    decodetable = nzf.decodetable
    for articlenum in decodetable:
        sleep(0.01)
        article = decodetable[articlenum]
        data = ArticleCache.do.load_article(article)
Beispiel #10
0
def hexdigest(md5):  #XXX: argh. 1.5.2 doesn't have this.
    return ''.join(map(lambda x: hex(ord(x))[2:], md5.digest()))
Beispiel #11
0
def unix_md5_crypt(pw, salt, magic=None):

    if magic is None:
        magic = MAGIC

    # Take care of the magic string if present
    if salt[:len(magic)] == magic:
        salt = salt[len(magic):]

    # salt can have up to 8 characters:
    import string
    salt = string.split(salt, '$', 1)[0]
    salt = salt[:8]

    ctx = pw + magic + salt

    md5 = hash_md5()
    md5.update(pw + salt + pw)
    final = md5.digest()

    for pl in range(len(pw), 0, -16):
        if pl > 16:
            ctx = ctx + final[:16]
        else:
            ctx = ctx + final[:pl]

    # Now the 'weird' xform (??)

    i = len(pw)
    while i:
        if i & 1:
            ctx = ctx + chr(0)  #if ($i & 1) { $ctx->add(pack("C", 0)); }
        else:
            ctx = ctx + pw[0]
        i = i >> 1

    md5 = hash_md5()
    md5.update(ctx)
    final = md5.digest()

    # The following is supposed to make
    # things run slower.

    # my question: WTF???

    for i in range(1000):
        ctx1 = ''
        if i & 1:
            ctx1 = ctx1 + pw
        else:
            ctx1 = ctx1 + final[:16]

        if i % 3:
            ctx1 = ctx1 + salt

        if i % 7:
            ctx1 = ctx1 + pw

        if i & 1:
            ctx1 = ctx1 + final[:16]
        else:
            ctx1 = ctx1 + pw

        md5 = hash_md5()
        md5.update(ctx1)
        final = md5.digest()

    # Final xform

    passwd = ''

    passwd = passwd + to64((int(ord(final[0])) << 16)
                           | (int(ord(final[6])) << 8)
                           | (int(ord(final[12]))), 4)

    passwd = passwd + to64((int(ord(final[1])) << 16)
                           | (int(ord(final[7])) << 8)
                           | (int(ord(final[13]))), 4)

    passwd = passwd + to64((int(ord(final[2])) << 16)
                           | (int(ord(final[8])) << 8)
                           | (int(ord(final[14]))), 4)

    passwd = passwd + to64((int(ord(final[3])) << 16)
                           | (int(ord(final[9])) << 8)
                           | (int(ord(final[15]))), 4)

    passwd = passwd + to64((int(ord(final[4])) << 16)
                           | (int(ord(final[10])) << 8)
                           | (int(ord(final[5]))), 4)

    passwd = passwd + to64((int(ord(final[11]))), 2)

    return magic + salt + '$' + passwd
Beispiel #12
0
def hexdigest(md5): #XXX: argh. 1.5.2 doesn't have this.
    return ''.join(map(lambda x: hex(ord(x))[2:], md5.digest()))
def unix_md5_crypt(pw, salt, magic=None):

    if magic==None:
        magic = MAGIC

    # Take care of the magic string if present
    if salt[:len(magic)] == magic:
        salt = salt[len(magic):]


    # salt can have up to 8 characters:
    import string
    salt = string.split(salt, '$', 1)[0]
    salt = salt[:8]

    ctx = pw + magic + salt

    md5 = hash_md5()
    md5.update(pw + salt + pw)
    final = md5.digest()

    for pl in range(len(pw),0,-16):
        if pl > 16:
            ctx = ctx + final[:16]
        else:
            ctx = ctx + final[:pl]


    # Now the 'weird' xform (??)

    i = len(pw)
    while i:
        if i & 1:
            ctx = ctx + chr(0)  #if ($i & 1) { $ctx->add(pack("C", 0)); }
        else:
            ctx = ctx + pw[0]
        i = i >> 1

    md5 = hash_md5()
    md5.update(ctx)
    final = md5.digest()

    # The following is supposed to make
    # things run slower.

    # my question: WTF???

    for i in range(1000):
        ctx1 = ''
        if i & 1:
            ctx1 = ctx1 + pw
        else:
            ctx1 = ctx1 + final[:16]

        if i % 3:
            ctx1 = ctx1 + salt

        if i % 7:
            ctx1 = ctx1 + pw

        if i & 1:
            ctx1 = ctx1 + final[:16]
        else:
            ctx1 = ctx1 + pw


        md5 = hash_md5()
        md5.update(ctx1)
        final = md5.digest()


    # Final xform

    passwd = ''

    passwd = passwd + to64((int(ord(final[0])) << 16)
                           |(int(ord(final[6])) << 8)
                           |(int(ord(final[12]))),4)

    passwd = passwd + to64((int(ord(final[1])) << 16)
                           |(int(ord(final[7])) << 8)
                           |(int(ord(final[13]))), 4)

    passwd = passwd + to64((int(ord(final[2])) << 16)
                           |(int(ord(final[8])) << 8)
                           |(int(ord(final[14]))), 4)

    passwd = passwd + to64((int(ord(final[3])) << 16)
                           |(int(ord(final[9])) << 8)
                           |(int(ord(final[15]))), 4)

    passwd = passwd + to64((int(ord(final[4])) << 16)
                           |(int(ord(final[10])) << 8)
                           |(int(ord(final[5]))), 4)

    passwd = passwd + to64((int(ord(final[11]))), 2)


    return magic + salt + '$' + passwd
Beispiel #14
0
                        ##/Fredrik Lundh
                        nbytes = (((ord(line[0])-32) & 63) * 4 + 5) / 3
                        try:
                            tmpdata = binascii.a2b_uu(line[:nbytes])
                            chunks.append(tmpdata)
                        except binascii.Error, msg:
                            logging.info('Decode failed in part %s: %s', article.article, msg)
                data = ''.join(chunks)
                fout.write(data)
                if md5: md5.update(data)

    fout.flush()
    fout.close()
    set_permissions(path)
    if md5:
        nzf.md5sum = md5.digest()
        del md5

    return path


def file_has_articles(nzf):
    """ Do a quick check to see if any articles are present for this file.
        Destructive: only to be used to differentiate between unknown encoding and no articles.
    """
    has = False
    decodetable = nzf.decodetable
    for articlenum in decodetable:
        sleep(0.01)
        article = decodetable[articlenum]
        data = ArticleCache.do.load_article(article)