Module Expr Str ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias Import alias Import alias Import alias Import alias Import alias Import alias Import alias Import alias Import alias If CompareGtE AttributeLoad NameLoad attr TupleLoad Num Num body Import alias orelse Import alias identifier Import alias Import alias Import alias Import alias Import alias identifier Import alias identifier Import alias Assign NameStore Call AttributeLoad NameLoad attr Str ClassDef bases AttributeLoad NameLoad attr body FunctionDef arguments args NameParam defaults body Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr keyword Call AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Num Num Assign NameStore ListLoad Str Str Call NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr NameLoad keyword AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpAdd Str Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr BinOpAdd Str Call NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr BinOpAdd BinOpAdd Str Call NameLoad AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr Num decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr If CompareIs AttributeLoad AttributeLoad NameLoad attr attr NameLoad body Expr Call AttributeLoad NameLoad attr BinOpAdd BinOpAdd Str Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr keyword AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Assign AttributeStore NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Assign AttributeStore NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Expr Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Slice Call NameLoad Call AttributeLoad NameLoad attr Assign NameStore BinOpAdd BinOpAdd Str Call NameLoad AttributeLoad NameLoad attr NameLoad Assign AttributeStore AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Dict Str Dict Str Str Str Str NameLoad Str Str ListLoad Str Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Str AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Str Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Assign NameStore SubscriptLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Index Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Str Expr Call AttributeLoad AttributeLoad AttributeLoad AttributeLoad NameLoad attr attr attr attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad With Call NameLoad NameLoad Str NameStore body Expr Call AttributeLoad NameLoad attr Str Assign TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Expr Call AttributeLoad AttributeLoad AttributeLoad AttributeLoad NameLoad attr attr attr attr NameLoad NameLoad Assign TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Expr Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Str Str With Call NameLoad NameLoad Str NameStore body Expr Call AttributeLoad NameLoad attr Str TryExcept body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad handlers ExceptHandler type AttributeLoad NameLoad attr name NameStore body Assign NameStore SubscriptLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Index Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Str Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr Num Expr Call AttributeLoad NameLoad attr CompareIn NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index NameLoad AttributeLoad NameLoad attr orelse Expr Call AttributeLoad NameLoad attr Str decorator_list FunctionDef arguments args NameParam defaults body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Str Str With Call NameLoad NameLoad Str NameStore body Expr Call AttributeLoad NameLoad attr Str Assign TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Str Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign SubscriptStore SubscriptLoad SubscriptLoad SubscriptLoad NameLoad Index Str Index Str Index Str Index Str NameLoad Assign SubscriptStore SubscriptLoad SubscriptLoad SubscriptLoad NameLoad Index Str Index Str Index Str Index Str NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad With Call NameLoad NameLoad Str NameStore body Expr Call AttributeLoad Call AttributeLoad NameLoad attr NameLoad NameLoad keyword Num keyword NameLoad attr Str TryExcept body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad handlers ExceptHandler type AttributeLoad NameLoad attr name NameStore body Assign NameStore SubscriptLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Index Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Str Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr Num Expr Call AttributeLoad NameLoad attr CompareIn NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index NameLoad AttributeLoad NameLoad attr orelse Expr Call AttributeLoad NameLoad attr Str decorator_list decorator_list If CompareEq NameLoad Str body Expr Call AttributeLoad NameLoad attr
N/A N/A 
<Program Name>
  test_arbitrary_package_attack.py

<Author>
  Konstantin Andrianov.

<Started>
  February 22, 2012.

  March 21, 2014.
    Refactored to use the 'unittest' module (test conditions in code, rather
    than verifying text output), use pre-generated repository files, and
    discontinue use of the old repository tools. -vladimir.v.diaz

<Copyright>
  See LICENSE for licensing information.

<Purpose>
  Simulate an arbitrary package attack, where an updater client attempts to
  download a malicious file.  TUF and non-TUF client scenarios are tested.  

  There is no difference between 'updates' and 'target' files.
 __future__ print_function __future__ absolute_import __future__ division __future__ unicode_literals N/A os N/A tempfile N/A random N/A time N/A shutil N/A json N/A subprocess N/A logging N/A sys N/A N/A N/A sys version_info N/A 2 7 N/A N/A unittest N/A N/A unittest2 unittest N/A tuf N/A tuf.formats N/A tuf.util N/A tuf.log N/A tuf.client.updater updater N/A tuf.unittest_toolbox unittest_toolbox N/A six N/A logger N/A N/A logging getLogger tuf.test_arbitrary_package_attack TestArbitraryPackageAttack N/A N/A unittest_toolbox Modified_TestCase N/A setUpClass N/A N/A cls N/A N/A N/A N/A cls temporary_directory N/A N/A tempfile mkdtemp dir N/A N/A os getcwd N/A N/A cls SERVER_PORT N/A N/A random randint 30000 45000 N/A command N/A python simple_server.py N/A str N/A cls SERVER_PORT N/A N/A cls server_process N/A N/A subprocess Popen command stderr N/A subprocess PIPE N/A N/A N/A logger info Server process started. N/A N/A N/A logger info N/A Server process id:  N/A str N/A N/A cls server_process pid N/A N/A N/A logger info N/A Serving on port:  N/A str N/A cls SERVER_PORT N/A N/A cls url N/A N/A http://localhost: N/A str N/A cls SERVER_PORT N/A N/A os path sep N/A N/A N/A time sleep 1 N/A classmethod tearDownClass N/A N/A cls N/A N/A N/A N/A N/A shutil rmtree N/A cls temporary_directory N/A N/A N/A N/A cls server_process returncode None N/A N/A N/A N/A logger info N/A N/A Server process  N/A str N/A N/A cls server_process pid  terminated. N/A N/A N/A N/A cls server_process kill N/A classmethod setUp N/A N/A self N/A N/A N/A N/A N/A N/A unittest_toolbox Modified_TestCase setUp self N/A original_repository_files N/A N/A N/A os path join N/A N/A os getcwd repository_data N/A temporary_repository_root N/A N/A self make_temp_directory directory N/A self temporary_directory N/A original_repository N/A N/A N/A os path join original_repository_files repository N/A original_client N/A N/A N/A os path join original_repository_files client N/A N/A self repository_directory N/A N/A N/A os path join temporary_repository_root repository N/A N/A self client_directory N/A N/A N/A os path join temporary_repository_root client N/A N/A N/A shutil copytree original_repository N/A self repository_directory N/A N/A N/A shutil copytree original_client N/A self client_directory N/A repository_basepath N/A N/A self repository_directory N/A N/A len N/A N/A os getcwd N/A url_prefix N/A N/A http://localhost: N/A str N/A self SERVER_PORT repository_basepath N/A N/A N/A tuf conf repository_directory N/A self client_directory N/A N/A self repository_mirrors N/A mirror1 N/A url_prefix metadata_path targets_path confined_target_dirs url_prefix metadata targets N/A N/A N/A self repository_updater N/A N/A updater Updater test_repository N/A self repository_mirrors N/A tearDown N/A N/A self N/A N/A N/A N/A N/A N/A unittest_toolbox Modified_TestCase tearDown self N/A test_without_tuf N/A N/A self N/A N/A N/A target_path N/A N/A N/A os path join N/A self repository_directory targets file1.txt N/A client_target_path N/A N/A N/A os path join N/A self client_directory file1.txt N/A N/A N/A self assertFalse N/A N/A N/A os path exists client_target_path N/A N/A length hashes N/A N/A N/A tuf util get_file_details target_path N/A fileinfo N/A N/A N/A tuf formats make_fileinfo length hashes N/A url_prefix N/A N/A N/A self repository_mirrors N/A mirror1 N/A url_prefix N/A url_file N/A N/A N/A os path join url_prefix targets file1.txt N/A N/A N/A N/A N/A N/A six moves urllib request urlretrieve url_file client_target_path N/A N/A N/A self assertTrue N/A N/A N/A os path exists client_target_path N/A N/A length hashes N/A N/A N/A tuf util get_file_details client_target_path N/A download_fileinfo N/A N/A N/A tuf formats make_fileinfo length hashes N/A N/A N/A self assertEqual fileinfo download_fileinfo N/A N/A open target_path wt file_object N/A N/A N/A N/A file_object write add malicious content. N/A N/A length hashes N/A N/A N/A tuf util get_file_details target_path N/A malicious_fileinfo N/A N/A N/A tuf formats make_fileinfo length hashes N/A N/A N/A N/A N/A N/A six moves urllib request urlretrieve url_file client_target_path N/A N/A length hashes N/A N/A N/A tuf util get_file_details client_target_path N/A download_fileinfo N/A N/A N/A tuf formats make_fileinfo length hashes N/A N/A N/A self assertNotEqual download_fileinfo fileinfo N/A N/A N/A self assertEqual download_fileinfo malicious_fileinfo N/A test_with_tuf N/A N/A self N/A N/A N/A file1_fileinfo N/A N/A N/A self repository_updater target file1.txt N/A destination N/A N/A N/A os path join N/A self client_directory N/A N/A N/A N/A self repository_updater download_target file1_fileinfo destination N/A client_target_path N/A N/A N/A os path join destination file1.txt N/A N/A N/A self assertTrue N/A N/A N/A os path exists client_target_path N/A target_path N/A N/A N/A os path join N/A self repository_directory targets file1.txt N/A N/A open target_path wt file_object N/A N/A N/A N/A file_object write add malicious content. N/A N/A N/A N/A N/A N/A self repository_updater download_target file1_fileinfo destination N/A N/A N/A N/A tuf NoWorkingMirrorError N/A exception N/A N/A url_prefix N/A N/A N/A self repository_mirrors N/A mirror1 N/A url_prefix N/A url_file N/A N/A N/A os path join url_prefix targets file1.txt N/A N/A N/A self assertTrue N/A len N/A exception mirror_errors 1 N/A N/A N/A self assertTrue N/A url_file N/A exception mirror_errors N/A N/A N/A self assertTrue N/A isinstance N/A N/A exception mirror_errors N/A url_file N/A tuf DownloadLengthMismatchError N/A N/A N/A N/A self fail TUF did not prevent an arbitrary package attack. N/A test_with_tuf_and_metadata_tampering N/A N/A self N/A N/A N/A target_path N/A N/A N/A os path join N/A self repository_directory targets file1.txt N/A N/A open target_path wt file_object N/A N/A N/A N/A file_object write add malicious content. N/A N/A length hashes N/A N/A N/A tuf util get_file_details target_path N/A metadata_path N/A N/A N/A os path join N/A self repository_directory metadata targets.json N/A metadata N/A N/A N/A tuf util load_json_file metadata_path N/A N/A N/A N/A N/A metadata N/A signed N/A targets N/A /file1.txt N/A hashes hashes N/A N/A N/A N/A N/A metadata N/A signed N/A targets N/A /file1.txt N/A length length N/A N/A N/A N/A tuf formats check_signable_object_format metadata N/A N/A open metadata_path wb file_object N/A N/A N/A N/A N/A N/A json dumps metadata file_object indent 1 sort_keys True encode utf-8 N/A N/A N/A N/A N/A N/A self repository_updater refresh N/A file1_fileinfo N/A N/A N/A self repository_updater target file1.txt N/A destination N/A N/A N/A os path join N/A self client_directory N/A N/A N/A N/A self repository_updater download_target file1_fileinfo destination N/A N/A N/A N/A tuf NoWorkingMirrorError N/A exception N/A N/A url_prefix N/A N/A N/A self repository_mirrors N/A mirror1 N/A url_prefix N/A url_file N/A N/A N/A os path join url_prefix targets file1.txt N/A N/A N/A self assertTrue N/A len N/A exception mirror_errors 1 N/A N/A N/A self assertTrue N/A url_file N/A exception mirror_errors N/A N/A N/A self assertTrue N/A isinstance N/A N/A exception mirror_errors N/A url_file N/A tuf DownloadLengthMismatchError N/A N/A N/A N/A self fail TUF did not prevent an arbitrary package attack. N/A N/A N/A N/A __name__ __main__ N/A N/A N/A N/A unittest main