예제 #1
0
def makehashes(path, regex, pwd):
    (key, verifier, salt) = key_derivation(pwd)

    # create output file at the place as input
    hashesfile = path + EXTENSION
    try:
        fout = open(hashesfile, 'w')
    except IOError:
        print 'error: failed to create %s' % hashesfile
        return 1

    # write regex, salt, and verifier
    towrite = '%s\n%s,%s\n' % (regex, salt, verifier)
    fout.write(towrite)

    # speed not critical, so write line per line
    with open(path) as fin:
        for line in fin:
            linestring = line.rstrip('\n').strip()
            (per_secret_key, _, per_secret_salt) = key_derivation(pwd)
            towrite = '%s,%s\n' % (hash_string(
                linestring, per_secret_key), per_secret_salt)
            fout.write(towrite)
    fout.close()

    return 0
예제 #2
0
def makehashes(path, regex, pwd):
    (key, verifier, salt) = key_derivation(pwd)

    # create output file at the place as input
    hashesfile = path + EXTENSION
    try:
        fout = open(hashesfile, 'w')
    except IOError:
        print 'error: failed to create %s' % hashesfile
        return 1

    # write regex, salt, and verifier
    towrite = '%s\n%s,%s\n' % (regex, salt, verifier)
    fout.write(towrite)

    # speed not critical, so write line per line
    with open(path) as fin:
        for line in fin:
            linestring = line.rstrip('\n').strip()
            (per_secret_key, _, per_secret_salt) = key_derivation(pwd)
            towrite = '%s,%s\n' % (hash_string(linestring, per_secret_key), per_secret_salt)
            fout.write(towrite)
    fout.close()

    return 0
예제 #3
0
파일: core.py 프로젝트: veorq/blueflower
def get_hashes(hashesfile, pwd):
    """create hashes list from hashesfile using the given password"""
    global HASHES
    global HASH_REGEX
    log_comment('verifying hashes file %s...' % hashesfile)
    fin = open(hashesfile)
    regex = fin.readline().rstrip('\n')
    try:
        (salt, verifier_from_file) = fin.readline().rstrip('\n').split(',')
    except ValueError:
        raise BFException('failed to extract verifier and salt')

    (key, verifier_from_pwd, salt) = key_derivation(pwd, salt)

    if verifier_from_pwd != verifier_from_file:
        log_comment('verifier does not match (incorrect password?)')
        fail()
    else:
        HASH_REGEX = regex

    try:
        re.compile(regex)
    except re.error:
        log_comment('invalid regex')
        fail()

    # file pointer is now at the 3rd line:
    hashes = []

    for line in fin:
        hash_line = line.strip().split(',')
        ahash = hash_line[0]
        if len(hash_line) != 2:
            log_comment('Missing salt for this secret: %s' % ahash)
            fail()

        ahash_salt = hash_line[1]
        ahash_key, _, _ = key_derivation(pwd, ahash_salt)

        if len(ahash) != 2*HASH_BYTES:
            log_comment('invalid hash length (%d bytes): %s' %
                        (len(ahash), ahash))
            fail()
        # check that the hash is an hex value
        try:
            int(ahash, 16)
        except ValueError:
            log_comment('invalid hash value: %s' % ahash)
            fail()
        hashes.append((ahash, ahash_key))

    # record hashes and key, notifies of duplicates
    HASHES = frozenset(hashes)
    log_comment('%d hashes read, %d uniques' % (len(hashes), len(HASHES)))
    log_comment('using regex %s' % HASH_REGEX)
    log_comment('hashes file successfully verified')
예제 #4
0
def get_hashes(hashesfile, pwd):
    """create hashes list from hashesfile using the given password"""
    global HASHES
    global HASH_REGEX
    log_comment('verifying hashes file %s...' % hashesfile)
    fin = open(hashesfile)
    regex = fin.readline().rstrip('\n')
    try:
        (salt, verifier_from_file) = fin.readline().rstrip('\n').split(',')
    except ValueError:
        raise BFException('failed to extract verifier and salt')

    (key, verifier_from_pwd, salt) = key_derivation(pwd, salt)

    if verifier_from_pwd != verifier_from_file:
        log_comment('verifier does not match (incorrect password?)')
        fail()
    else:
        HASH_REGEX = regex

    try:
        re.compile(regex)
    except re.error:
        log_comment('invalid regex')
        fail()

    # file pointer is now at the 3rd line:
    hashes = []

    for line in fin:
        hash_line = line.strip().split(',')
        ahash = hash_line[0]
        if len(hash_line) != 2:
            log_comment('Missing salt for this secret: %s' % ahash)
            fail()

        ahash_salt = hash_line[1]
        ahash_key, _, _ = key_derivation(pwd, ahash_salt)

        if len(ahash) != 2 * HASH_BYTES:
            log_comment('invalid hash length (%d bytes): %s' %
                        (len(ahash), ahash))
            fail()
        # check that the hash is an hex value
        try:
            int(ahash, 16)
        except ValueError:
            log_comment('invalid hash value: %s' % ahash)
            fail()
        hashes.append((ahash, ahash_key))

    # record hashes and key, notifies of duplicates
    HASHES = frozenset(hashes)
    log_comment('%d hashes read, %d uniques' % (len(hashes), len(HASHES)))
    log_comment('using regex %s' % HASH_REGEX)
    log_comment('hashes file successfully verified')