Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signed file support #30

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Signed file support #30

wants to merge 11 commits into from

Conversation

joeFischetti
Copy link
Collaborator

@joeFischetti joeFischetti commented Nov 26, 2021

Note - my commit timestamps are all FUBAR... WSL loses its clock when the machine goes to sleep.

Anyway:
Changes should be pretty straightforward.

Additional file lib/signature_tools.py that now handles read_bytes and write_bytes when necessary.

signatures are only supported against full bins.

When a full bin is read in (via input_bin) if the last 350 bytes include METADATA:xxxx, they're pulled off and processed, otherwise the bin is read in directly.
When a write is planned (via output_bin), if theres args provided that trigger a signature, it's performed. Otherwise, it's just written directly.

The following is how you actually sign a full bin. Optionally including some notes about the file and a secondary_key to sign it with (if you have your own private key). If you don't provide a secondary key, only the private key in data/VW_Flash.key is used

python VW_Flash.py --action prepare --input_bin FILENAME --output_bin FILENAME_OUT [--signed [--notes "Some notes about the file" ] [--secondary_key PRIVATE_KEY ]  ]

validation is simple as well. The following command would read in the input_bin and check the signatures against the public key in data/VW_Flash.pub as well as the secondary_key (if the file contains a dual signature)

python VW_Flash.py --action validate --input_bin FILENAME [ --secondary_key PUBLIC_KEY ]

@bri3d
Copy link
Owner

bri3d commented Nov 26, 2021

This looks good to me as a start. One piece of feedback, and a question:

It would be nice if the signature module were less dependent on side effects - that is, I/O like loading files and printing text.

If the signature module took bytes and returned a class or enumerated values explaining the signing state, we would need one extra line of calling code instead of replacing the file input, yes - but then we'd have access to the signature capabilities in places where we already have read the file, and we'd be able to do what we want with the return value.

An example would be displaying a checkbox or X mark in the GUI for example, rather than relying on side effects from the file's loading process to print to the log only.

As for my one question -

You've verified the behavior of "signed" files with older versions of VW_Flash? From a quick skim of the code, it should just ignore the extra bytes, but I want to be sure :)

@joeFischetti
Copy link
Collaborator Author

Recent commit:
Created a class in constants.py as a 'container' for a full bin file (includes properties for metadata and signatures).
Flow now looks like this (for full bin input operations):

  1. call binfile.blocks_from_bin()
  2. Inside binfile.blocks_from_bin(),
    a) read bytes from the file path
    b) pass those bytes into signature_tools.check_signature_data
    c) signature data is stripped/processed (if exists), and a FullBinData object is returned
    d) the blocks are parsed like always
  3. a FullBinData object is returned
  4. existing code extracts the input_blocks from the FullBinData object (but the object is there to extract signature info/metadata from now.

It's not ready to merge, but is this kinda what you were thinking? I included the changes in the CLI + GUI, but I only tested --action validate via CLI so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants