Example #1
0
def test_decode_single_line_file_v3():
        with open('tests/testfiles-v3/csenc/ssingle-line.txt', 'rb') as f:
                s = core.decode_csenc_stream(f)
                assert next(s) == ('compress', 1)
                assert next(s) == ('digest', 'md5')
                assert next(s) == ('enc_key1', '6Gbow/t0ltbdXw2L79IS41HTVY7ffwl7vlmUs4CCOmtoqSIdxDxTcmt2cmjE38AfkvmTg0BwcK5WIsEMJwA81NS8vaHUv74D9XhPXMRclbM=')
                assert next(s) == ('enc_key2', 'E+WD7iAnJibEDt6wtzoJq34MIu4s0sUSOnkCJcr85LcnI9hI6M2RQsQvhCZsWbxW0OXltkoVNvJX1UUVi13NyyEdNax1lPAmgGig8dEKAt0hEH8fNHS0N4A5xNwtFzqDKlFw5Jfiqq1Hw+yXzZ5PXz0Z1I3ORa/JwfK1L4lp3wDGiGrR1CVxHCgjm+Ncg9yM7UAAFydVPH8AenzOEKFyGcbmv6vibHNSGraBTrxEZBsxu1bnbH4eW5jpNNpoyjib1F7W4RE2qSI+DU7F4tij8GiePuMyihdg5SjMerEcvOQWDqHGsQ6IbXeYnGgZQ+bPd7EONsI4uYrUgENKId73Zw==')
                assert next(s) == ('encrypt', 1)
                assert next(s) == ('file_name', 'ssingle-line.txt')
                assert next(s) == ('key1_hash', 'uTVhxSKK1Da958d45e7a65a63f30cf527984e800f3')
                assert next(s) == ('key2_hash', 'vNPKBAbNC9207d495491d14cfbb2a960274ff65796')
                assert next(s) == ('salt', 'DXzp4VKu')
                assert next(s) == ('session_key_hash', 'ofQaqQeFxY2b95456e59bf119d04cef906dd8f8046')
                assert next(s) == ('version', collections.OrderedDict([('major', 3), ('minor', 0)]))
                (none, data) = next(s)
                assert none == None and isinstance(data, bytes) # a chunk of encrypted compressed data
                assert next(s) == ('file_md5', 'e45f14e62971070603ff27c2bb05f5a4')
                try:
                        next(s)
                        assert False
                except StopIteration: pass

                session_key = b'EA23EB5F36B9008AC73498A8FC53884D1D7EFBA052F902F44B44D40409CBC215'
                decrypted_compressed_data = core.decrypted_with_password(data, binascii.unhexlify(session_key), salt=b'')
                decrypted_uncompressed_data = lz4_uncompress(decrypted_compressed_data)
                assert decrypted_uncompressed_data == b'Just a single line, no newline character at the end...'
Example #2
0
def test_decode_single_line_file():
    with open('tests/testfiles-csenc/single-line.txt', 'rb') as f:
        s = core.decode_csenc_stream(f)
        assert next(s) == ('compress', 1)
        assert next(s) == ('digest', 'md5')
        assert next(s) == (
            'enc_key1',
            'f662PyjwrkzR61qSRHyBEVkXVd7STUpV6o7IrJs+m8gN1haqmBtMzLvq2/Gj134r')
        assert next(s) == (
            'enc_key2',
            'ovVar7Zpi0HVPZ3CGmXRBhp4l1Q1BNNo0/uYfdwSg1GDD/MXNSMXcuAf65pYObUQsu4aCQc82LldLINkUSFyoPYUDe5YKh4Fv3993YQ7CPYk5RrWem2CGntdjmS1J5KV9YHa7bF2l6wMT2FiFvfd+/3Pikadb/fqOC/hN5hx2kA2c5n3FltCGehhfW97Bb3aLEZaOJ8rpoPuHDIa6yxhstCHrajnb0870KprqSfFZUdin1G1hqpwJ+1gm7CmFkjKA6QqMD5dx7bru69g98VwrqYqGmYR3lmJuMI0wJn7WwbciWCOQV5fnfMMxiAiZ0DK1fseqWxMIYUk3lVOcAA3KA=='
        )
        assert next(s) == ('encrypt', 1)
        assert next(s) == ('file_name', 'single-line.txt')
        assert next(s) == ('key1_hash',
                           '4ZF3pd4Y17c7cf0f016aada3f8398d22c8708d8649')
        assert next(s) == ('key2_hash',
                           'Hs2fAqiRaTb73da9c06e2b824dc3a9935ae71bdd14')
        assert next(s) == ('session_key_hash',
                           'jM41by6vAd517830d42bfb52eae9b58cd41eac95b0')
        assert next(s) == ('version',
                           collections.OrderedDict([('major', 1),
                                                    ('minor', 0)]))
        (none, data) = next(s)
        assert none == None and isinstance(
            data, bytes)  # a chunk of encrypted compressed data
        assert next(s) == ('file_md5', 'e45f14e62971070603ff27c2bb05f5a4')

        session_key = b'BxY2A-ouRpI8YRvmiWii5KkCF3LVN1O6'
        decrypted_compressed_data = core.decrypted_with_password(
            data, session_key)
        decrypted_uncompressed_data = lz4_uncompress(decrypted_compressed_data)
        assert decrypted_uncompressed_data == b'Just a single line, no newline character at the end...'
Example #3
0
def test_decrypt_enc_key1_v1():
        """
        Test that we can do the equivalent of

          $ echo 'f662PyjwrkzR61qSRHyBEVkXVd7STUpV6o7IrJs+m8gN1haqmBtMzLvq2/Gj134r' | openssl enc -aes256 -d -a -pass pass:'******' -nosalt
          BxY2A-ouRpI8YRvmiWii5KkCF3LVN1O6
        """

        enc_key1 = b'f662PyjwrkzR61qSRHyBEVkXVd7STUpV6o7IrJs+m8gN1haqmBtMzLvq2/Gj134r'
        enc_key1_binary = base64.b64decode(enc_key1)
        assert core.decrypted_with_password(enc_key1_binary, PASSWORD, salt=b'') == b'BxY2A-ouRpI8YRvmiWii5KkCF3LVN1O6'
Example #4
0
def test_decrypt_enc_key1():
        """
        Test that we can do the equivalent of

          $ echo 'f662PyjwrkzR61qSRHyBEVkXVd7STUpV6o7IrJs+m8gN1haqmBtMzLvq2/Gj134r' | openssl enc -aes256 -d -a -pass pass:'******' -nosalt
          BxY2A-ouRpI8YRvmiWii5KkCF3LVN1O6
        """

        enc_key1 = b'f662PyjwrkzR61qSRHyBEVkXVd7STUpV6o7IrJs+m8gN1haqmBtMzLvq2/Gj134r'
        enc_key1_binary = base64.b64decode(enc_key1)
        assert core.decrypted_with_password(enc_key1_binary, PASSWORD) == b'BxY2A-ouRpI8YRvmiWii5KkCF3LVN1O6'
Example #5
0
def test_decrypt_enc_key1_v3():
        """
        Test that we can do the equivalent of the following, except with
        an OpenSSL key/iv algorithm that hashes 1000 times instead of
        OpenSSL's 1.

          $ echo '6Gbow/t0ltbdXw2L79IS41HTVY7ffwl7vlmUs4CCOmtoqSIdxDxTcmt2cmjE38AfkvmTg0BwcK5WIsEMJwA81NS8vaHUv74D9XhPXMRclbM=' | openssl enc -aes256 -d -a -pass pass:'******'
          EA23EB5F36B9008AC73498A8FC53884D1D7EFBA052F902F44B44D40409CBC215
        """

        salt = b'DXzp4VKu'
        enc_key1 = b'6Gbow/t0ltbdXw2L79IS41HTVY7ffwl7vlmUs4CCOmtoqSIdxDxTcmt2cmjE38AfkvmTg0BwcK5WIsEMJwA81NS8vaHUv74D9XhPXMRclbM='
        enc_key1_binary = base64.b64decode(enc_key1)
        assert core.decrypted_with_password(enc_key1_binary, PASSWORD, salt=salt) == b'EA23EB5F36B9008AC73498A8FC53884D1D7EFBA052F902F44B44D40409CBC215'
Example #6
0
def test_decode_single_line_file():
        with open('tests/testfiles-csenc/single-line.txt', 'rb') as f:
                s = core.decode_csenc_stream(f)
                assert next(s) == ('compress', 1)
                assert next(s) == ('digest', 'md5')
                assert next(s) == ('enc_key1', 'f662PyjwrkzR61qSRHyBEVkXVd7STUpV6o7IrJs+m8gN1haqmBtMzLvq2/Gj134r')
                assert next(s) == ('enc_key2', 'ovVar7Zpi0HVPZ3CGmXRBhp4l1Q1BNNo0/uYfdwSg1GDD/MXNSMXcuAf65pYObUQsu4aCQc82LldLINkUSFyoPYUDe5YKh4Fv3993YQ7CPYk5RrWem2CGntdjmS1J5KV9YHa7bF2l6wMT2FiFvfd+/3Pikadb/fqOC/hN5hx2kA2c5n3FltCGehhfW97Bb3aLEZaOJ8rpoPuHDIa6yxhstCHrajnb0870KprqSfFZUdin1G1hqpwJ+1gm7CmFkjKA6QqMD5dx7bru69g98VwrqYqGmYR3lmJuMI0wJn7WwbciWCOQV5fnfMMxiAiZ0DK1fseqWxMIYUk3lVOcAA3KA==')
                assert next(s) == ('encrypt', 1)
                assert next(s) == ('file_name', 'single-line.txt')
                assert next(s) == ('key1_hash', '4ZF3pd4Y17c7cf0f016aada3f8398d22c8708d8649')
                assert next(s) == ('key2_hash', 'Hs2fAqiRaTb73da9c06e2b824dc3a9935ae71bdd14')
                assert next(s) == ('session_key_hash', 'jM41by6vAd517830d42bfb52eae9b58cd41eac95b0')
                assert next(s) == ('version', collections.OrderedDict([('major', 1), ('minor', 0)]))
                (none, data) = next(s)
                assert none == None and isinstance(data, bytes) # a chunk of encrypted compressed data
                assert next(s) == ('file_md5', 'e45f14e62971070603ff27c2bb05f5a4')

                session_key = b'BxY2A-ouRpI8YRvmiWii5KkCF3LVN1O6'
                decrypted_compressed_data = core.decrypted_with_password(data, session_key)
                decrypted_uncompressed_data = lz4_uncompress(decrypted_compressed_data)
                assert decrypted_uncompressed_data == b'Just a single line, no newline character at the end...'