def test_rar3_s2k(): exp = ('a160cb31cb262e9231c0b6fc984fbb0d', 'aa54a659fb0c359b30f353a6343fb11d') key, iv = rarfile.rar3_s2k(b'password', unhexlify('00FF00')) eq_((tohex(key), tohex(iv)), exp) key, iv = rarfile.rar3_s2k(u'password', unhexlify('00FF00')) eq_((tohex(key), tohex(iv)), exp) exp = ('ffff33ffaf31987c899ccc2f965a8927', 'bdff6873721b247afa4f978448a5aeef') key, iv = rarfile.rar3_s2k(u'p'*28, unhexlify('1122334455667788')) eq_((tohex(key), tohex(iv)), exp) exp = ('306cafde28f1ea78c9427c3ec642c0db', '173ecdf574c0bfe9e7c23bdfd96fa435') key, iv = rarfile.rar3_s2k(u'p'*29, unhexlify('1122334455667788')) eq_((tohex(key), tohex(iv)), exp)
def test_rar3_s2k(): exp = ('a160cb31cb262e9231c0b6fc984fbb0d', 'aa54a659fb0c359b30f353a6343fb11d') key, iv = rarfile.rar3_s2k(b'password', unhexlify('00FF00')) assert (tohex(key), tohex(iv)) == exp key, iv = rarfile.rar3_s2k('password', unhexlify('00FF00')) assert (tohex(key), tohex(iv)) == exp exp = ('ffff33ffaf31987c899ccc2f965a8927', 'bdff6873721b247afa4f978448a5aeef') key, iv = rarfile.rar3_s2k('p' * 28, unhexlify('1122334455667788')) assert (tohex(key), tohex(iv)) == exp exp = ('306cafde28f1ea78c9427c3ec642c0db', '173ecdf574c0bfe9e7c23bdfd96fa435') key, iv = rarfile.rar3_s2k('p' * 29, unhexlify('1122334455667788')) assert (tohex(key), tohex(iv)) == exp
def show_item_v5(h): """Show any RAR5 record. """ st = rar5_type(h.block_type) xprint("%s: hdrlen=%d datlen=%d hdr_extra=%d", st, h.header_size, h.compress_size, h.block_extra_size) xprint(" block_flags=0x%04x:%s", h.block_flags, render_flags(h.block_flags, r5_block_flags)) if h.block_type in (rf.RAR5_BLOCK_FILE, rf.RAR5_BLOCK_SERVICE): xprint(" name=%s", h.filename) if h.file_host_os == rf.RAR5_OS_UNIX: s_os = 'UNIX' s_mode = "0%o" % h.mode else: s_os = 'WINDOWS' s_mode = "0x%x" % h.mode xprint(" file_flags=0x%04x:%s", h.file_flags, render_flags(h.file_flags, r5_file_flags)) cmp_flags = h.file_compress_flags xprint(" cmp_algo=%d cmp_meth=%d dict=%d solid=%r", cmp_flags & 0x3f, (cmp_flags >> 7) & 0x07, cmp_flags >> 10, cmp_flags & rf.RAR5_COMPR_SOLID > 0) xprint(" os=%d:%s mode=%s cmp=%r dec=%r vol=%r", h.file_host_os, s_os, s_mode, h.compress_size, h.file_size, h.volume) if h.CRC is not None: xprint(" crc=0x%08x (%d)", h.CRC, h.CRC) if h.blake2sp_hash is not None: xprint(" blake2sp=%s", rf.tohex(h.blake2sp_hash)) if h.date_time is not None: xprint(" date_time=%s", fmt_time(h.date_time)) if h.mtime: xprint(" mtime=%s", fmt_time(h.mtime)) if h.ctime: xprint(" ctime=%s", fmt_time(h.ctime)) if h.atime: xprint(" atime=%s", fmt_time(h.atime)) if h.arctime: xprint(" arctime=%s", fmt_time(h.arctime)) if h.flags & rf.RAR_FILE_PASSWORD: enc_algo, enc_flags, kdf_count, salt, iv, checkval = h.file_encryption algo_name = 'AES256' if enc_algo == rf.RAR5_XENC_CIPHER_AES256 else 'UnknownAlgo' xprint( ' algo=%d:%s enc_flags=%04x:%s kdf_lg=%d kdf_count=%d salt=%s iv=%s checkval=%s', enc_algo, algo_name, enc_flags, render_flags(enc_flags, r5_file_enc_flags), kdf_count, 1 << kdf_count, rf.tohex(salt), rf.tohex(iv), checkval and rf.tohex(checkval) or '-') if h.file_redir: redir_type, redir_flags, redir_name = h.file_redir xprint(' redir: type=%s flags=%d:%s destination=%s', r5_file_redir_types.get(redir_type, 'Unknown'), redir_flags, render_flags(redir_flags, r5_file_redir_flags), redir_name) if h.file_owner: uname, gname, uid, gid = h.file_owner xprint(' owner: name=%r group=%r uid=%r gid=%r', uname, gname, uid, gid) if h.file_version: flags, version = h.file_version xprint(' version: flags=%r version=%r', flags, version) elif h.block_type == rf.RAR5_BLOCK_MAIN: xprint(" flags=0x%04x:%s", h.flags, render_flags(h.main_flags, r5_main_flags)) elif h.block_type == rf.RAR5_BLOCK_ENDARC: xprint(" flags=0x%04x:%s", h.flags, render_flags(h.endarc_flags, r5_endarc_flags)) elif h.block_type == rf.RAR5_BLOCK_ENCRYPTION: algo_name = 'AES256' if h.encryption_algo == rf.RAR5_XENC_CIPHER_AES256 else 'UnknownAlgo' xprint(" algo=%d:%s flags=0x%04x:%s", h.encryption_algo, algo_name, h.flags, render_flags(h.encryption_flags, r5_enc_flags)) xprint(" kdf_lg=%d kdf_count=%d", h.encryption_kdf_count, 1 << h.encryption_kdf_count) xprint(" salt=%s", rf.tohex(h.encryption_salt)) else: xprint(" - missing info -") if h.comment is not None: cm = repr(h.comment) if cm[0] == 'u': cm = cm[1:] xprint(" comment=%s", cm)
def test_hmac_sha256(): assert tohex( rarfile.hmac_sha256(b'key', b'data') ) == '5031fe3d989c6d1537a013fa6e739da23463fdaec3b70137d828e36ace221bd0'
def test_pbkdf2_hmac_sha256(): assert tohex(rarfile.pbkdf2_sha256(b'password', b'salt', 100)) == \ '07e6997180cf7f12904f04100d405d34888fdf62af6d506a0ecc23b196fe99d8'
def test_pbkdf2_hmac_sha256(): eq_(tohex(rarfile.pbkdf2_sha256(b'password', b'salt', 100)), '07e6997180cf7f12904f04100d405d34888fdf62af6d506a0ecc23b196fe99d8')
def test_rar3_s2k(): exp = ('a160cb31cb262e9231c0b6fc984fbb0d', 'aa54a659fb0c359b30f353a6343fb11d') key, iv = rarfile.rar3_s2k(b'password', unhexlify('00FF00')) eq_((tohex(key), tohex(iv)), exp) key, iv = rarfile.rar3_s2k(u'password', unhexlify('00FF00')) eq_((tohex(key), tohex(iv)), exp)
def test_hmac_sha256(): eq_(tohex(rarfile.hmac_sha256(b'key', b'data')), '5031fe3d989c6d1537a013fa6e739da23463fdaec3b70137d828e36ace221bd0')
def show_item_v5(h): """Show any RAR5 record. """ st = rar5_type(h.block_type) xprint("%s: hdrlen=%d datlen=%d hdr_extra=%d", st, h.header_size, h.compress_size, h.block_extra_size) xprint(" block_flags=0x%04x:%s", h.block_flags, render_flags(h.block_flags, r5_block_flags)) if h.block_type in (rf.RAR5_BLOCK_FILE, rf.RAR5_BLOCK_SERVICE): xprint(" name=%s", h.filename) if h.file_host_os == rf.RAR5_OS_UNIX: s_os = 'UNIX' s_mode = "0%o" % h.mode else: s_os = 'WINDOWS' s_mode = "0x%x" % h.mode xprint(" file_flags=0x%04x:%s", h.file_flags, render_flags(h.file_flags, r5_file_flags)) cmp_flags = h.file_compress_flags xprint(" cmp_algo=%d cmp_meth=%d dict=%d solid=%r", cmp_flags & 0x3f, (cmp_flags >> 7) & 0x07, cmp_flags >> 10, cmp_flags & rf.RAR5_COMPR_SOLID > 0) xprint(" os=%d:%s mode=%s cmp=%r dec=%r vol=%r", h.file_host_os, s_os, s_mode, h.compress_size, h.file_size, h.volume) if h.CRC is not None: xprint(" crc=0x%08x (%d)", h.CRC, h.CRC) if h.blake2sp_hash is not None: xprint(" blake2sp=%s", rf.tohex(h.blake2sp_hash)) if h.date_time is not None: xprint(" date_time=%s", fmt_time(h.date_time)) if h.mtime: xprint(" mtime=%s", fmt_time(h.mtime)) if h.ctime: xprint(" ctime=%s", fmt_time(h.ctime)) if h.atime: xprint(" atime=%s", fmt_time(h.atime)) if h.arctime: xprint(" arctime=%s", fmt_time(h.arctime)) if h.flags & rf.RAR_FILE_PASSWORD: enc_algo, enc_flags, kdf_count, salt, iv, checkval = h.file_encryption algo_name = enc_algo == rf.RAR5_XENC_CIPHER_AES256 and 'AES256' or 'UnknownAlgo' xprint(' algo=%d:%s enc_flags=%04x:%s kdf_lg=%d kdf_count=%d salt=%s iv=%s checkval=%s', enc_algo, algo_name, enc_flags, render_flags(enc_flags, r5_file_enc_flags), kdf_count, 1 << kdf_count, rf.tohex(salt), rf.tohex(iv), checkval and rf.tohex(checkval) or '-') if h.file_redir: redir_type, redir_flags, redir_name = h.file_redir xprint(' redir: type=%s flags=%d:%s destination=%s', r5_file_redir_types.get(redir_type, 'Unknown'), redir_flags, render_flags(redir_flags, r5_file_redir_flags), redir_name) if h.file_owner: uname, gname, uid, gid = h.file_owner xprint(' owner: name=%r group=%r uid=%r gid=%r', uname, gname, uid, gid) if h.file_version: flags, version = h.file_version xprint(' version: flags=%r version=%r', flags, version) elif h.block_type == rf.RAR5_BLOCK_MAIN: xprint(" flags=0x%04x:%s", h.flags, render_flags(h.main_flags, r5_main_flags)) elif h.block_type == rf.RAR5_BLOCK_ENDARC: xprint(" flags=0x%04x:%s", h.flags, render_flags(h.endarc_flags, r5_endarc_flags)) elif h.block_type == rf.RAR5_BLOCK_ENCRYPTION: algo_name = h.encryption_algo == rf.RAR5_XENC_CIPHER_AES256 and 'AES256' or 'UnknownAlgo' xprint(" algo=%d:%s flags=0x%04x:%s", h.encryption_algo, algo_name, h.flags, render_flags(h.encryption_flags, r5_enc_flags)) xprint(" kdf_lg=%d kdf_count=%d", h.encryption_kdf_count, 1 << h.encryption_kdf_count) xprint(" salt=%s", rf.tohex(h.encryption_salt)) else: xprint(" - missing info -") if h.comment is not None: cm = repr(h.comment) if cm[0] == 'u': cm = cm[1:] xprint(" comment=%s", cm)