Download Fixity

Breakdown of how download fixity works.

The function download_fixity_checker(binary_file, hashes) takes in two required arguments, binary_file and hashes:

  • binary_file : The file, in binary format, to run the hash algorithm on to check fixity.

  • hashes : A dictionary of hashes provided by the target to compare to the hash calculated from the provided binary file. Example below:

    • {
          "sha256": "343e249fdb0818a58edcc64663e1eb116843b4e1c4e74790ff331628593c02be",
          "md5": "a4536efb47b26eaf509edfdaca442037"
      }

The download_fixity_checker will loop through this hashes dictionary and when if finds a hashing algorithm that is supported by the python hashlib (https://docs.python.org/3/library/hashlib.html) then it will run that algorithm against the provided binary_file. If the provided hash and the calculated hash match then fixity passes!

If the fixity_checker can't find a hashlib supported algorithm in hashes or if all the hash values in hashes are None then the fixity_checker will use md5 as a default algorithm to still hash the file so we can pass that hash to the user. It also counts these situations as fixity passing since we didn't know what the original hash was. Below are examples.

Valid Hashes Provided + Fixity Passes
{
    "sha256": "343e249fdb0818a58edcc64663e1eb116843b4e1c4e74790ff331628593c02be",
    "md5": "a4536efb47b26eaf509edfdaca442037"
}

will yield

{
    'hash_algorithm': sha256,
    'given_hash': 343e249fdb0818a58edcc64663e1eb116843b4e1c4e74790ff331628593c02be,
    'calculated_hash': 343e249fdb0818a58edcc64663e1eb116843b4e1c4e74790ff331628593c02be,
    'fixity': True
}
Valid Hashes Provided + Fixity Fails
{
    "sha256": "343e249fdb0818a58edcc64663e1eb116843b4e1c4e74790ff331628593c02be",
    "md5": "a4536efb47b26eaf509edfdaca442037"
}

will yield

{
    'hash_algorithm': sha256,
    'given_hash': 343e249fdb0818a58edcc64663e1eb116843b4e1c4e74790ff331628593c02be,
    'calculated_hash': 12345678,
    'fixity': False
}
Blank Hashes Provided
{
    "sha256": None,
    "md5": None
}

will yield

{
    'hash_algorithm': md5,
    'given_hash': None,
    'calculated_hash': 343e249fdb0818a58edcc64663e1eb116843b4e1c4e74790ff331628593c02be,
    'fixity': True
}
Unknown Hashes Provided
{
    "unknown_hasher": None,
    "special_hasher": None
}

will yield

{
    'hash_algorithm': md5,
    'given_hash': None,
    'calculated_hash': 343e249fdb0818a58edcc64663e1eb116843b4e1c4e74790ff331628593c02be,
    'fixity': True
}

Last updated