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

WIP: Add DSSE Envelope #1

Merged
merged 7 commits into from
Jun 20, 2022
Merged

Conversation

PradyumnaKrishna
Copy link

@PradyumnaKrishna PradyumnaKrishna commented Jun 14, 2022

Fixes: secure-systems-lab#370

Description of the changes being introduced by the pull request:

Pull Request for DSSE Envelope.

  • Created a container class named Envelope having attributes payload, payloadType, and signatures.
  • Built several methods including functions to load and dump the class into JSON/dict.
  • Add a method to generate Pre-Auth-Encoding for the envelope.
  • Add tests cases to test the metadata.py or Envelope

Please verify and check that the pull request fulfils the following requirements:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

DSSE Envelope is a specification for signing arbitrary data.

Envelope contains from_dict and to_dict methods to convert the object to
json/dict and vice versa.

Signed-off-by: Pradyumna Krishna <git@onpy.in>
@lukpueh
Copy link
Member

lukpueh commented Jun 14, 2022

This looks great! Is there anything you want to add, before I take a look? Otherwise, I suggest to un-draft the PR.

Also, in our conversation earlier today, you mentioned an alternative design that uses data classes. Do you want comments on that too?

helper functions related to base64 is now moved to util.py

Signed-off-by: Pradyumna Krishna <git@onpy.in>
@PradyumnaKrishna PradyumnaKrishna marked this pull request as ready for review June 14, 2022 13:26
@PradyumnaKrishna
Copy link
Author

Also, in our conversation earlier today, you mentioned an alternative design that uses data classes. Do you want comments on that too?

Actually I think dataclasses won't have a major affect. Only problem is asdict won't convert byte sequence into base64.
I will push it in another branch.

Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impeccable work, @PradyumnaKrishna! 🎉 I only left a few very minor style comments inline, but otherwise this looks great to me.

Regarding style, would you mind running black, isort and pylint locally over any new modules you add until we fix secure-systems-lab#243?

see secure-systems-lab#243 (comment) for details

Also some test would be great. But we can do that in a follow-up PR.

securesystemslib/metadata.py Outdated Show resolved Hide resolved
securesystemslib/metadata.py Outdated Show resolved Hide resolved
securesystemslib/metadata.py Outdated Show resolved Hide resolved
securesystemslib/metadata.py Outdated Show resolved Hide resolved

<Return>
base64 string
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate that you adopt the existing code style here (wrt indentation), but I'd say it's okay to deviate from the rest of the file when it comes to docs. Could you please use the same docstring style as above in metadata.py?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I was following the docstring used by signer.py. Do I have to add all the fields like Purpose, Arguments, Exceptions, Side Effects and Returns in class methods because many functions don't have any arguments or exceptions. or have to use <> for specifying field in docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our code style guide has some notes about docstrings.

TLDR: In new functions/methods/classes, we should use the Google docstring-style, even if the new code is added to an existing module that otherwise uses the old docstring style, which you used here.

Context: The advantage of the Google docstring-style is that there is a Sphinx-parser that can convert it for Readthedocs. And that it is generally more compact, e.g. the <Purpose> header is omitted because it is implicit and empty sections are also omitted (often times this is the <Side Effects> section).

Please take a quick look at the style guide linked above and let me know if you have more questions.

securesystemslib/util.py Outdated Show resolved Hide resolved
@PradyumnaKrishna
Copy link
Author

@lukpueh, I guess the indent size is 2 as almost all files follow it except signer.py which uses 4 space of indent. Do I have to change the indent size in metadata.py that I have created.

@lukpueh
Copy link
Member

lukpueh commented Jun 15, 2022

Do I have to change the indent size in metadata.py that I have created.

No, it's okay to use 4 in metadata.py, which is new, but 2 in util.py, which already uses 2.

Run linters like black, isort, pylint and fix all errors.
Update some doc strings.
Change attribute "payload_type" to snake case.

Signed-off-by: Pradyumna Krishna <git@onpy.in>
Pre-Auth-Encoding method returns a byte sequence required to sign the
payload and create DSSE signatures.

Signed-off-by: Pradyumna Krishna <git@onpy.in>
@PradyumnaKrishna
Copy link
Author

By the end of this week I will try to add tests for the implemented methods and then it will be good to merge. Afterwards I will look into sign and verification of payload and generating signatures.

DSSE envelope tests are added which included test cases like
* test for from and to dict methods of envelope
* test to check envelope equality
* and test to check Pre-Auth-Encoding of envelope

Signed-off-by: Pradyumna Krishna <git@onpy.in>
Copy link
Author

@PradyumnaKrishna PradyumnaKrishna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about GitHub actions can work in forks, please check if they can enable in this repository.

"""Test envelope to_dict and from_dict methods"""

# create envelope object from its dict.
envelope_obj = Envelope.from_dict(copy.deepcopy(self.envelope_dict))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

envelope_dict contains a nested dict and these tests changes the signature, so I have to use deepcopy.

@lukpueh
Copy link
Member

lukpueh commented Jun 17, 2022

I am not sure about GitHub actions can work in forks, please check if they can enable in this repository.

I just enabled them for the fork. Not sure how to trigger the workflow for the existing PR. Maybe pushing a new commit does it?

@PradyumnaKrishna
Copy link
Author

Maybe pushing a new commit does it?

I think reopening this PR would work, let me try.

Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent PR and I really appreciate the commit discipline! I'm inclined to just merge it, but maybe you can still change the docstring style for the base64 function (see inline comment)?

Regrading pre-authentication encoding, you will likely also need a deserialization function. You can add it in a follow-up PR. But maybe it makes sense to already spend a thought on its name and whether pae will then still make sense for the serialization function implemented here.


<Return>
base64 string
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our code style guide has some notes about docstrings.

TLDR: In new functions/methods/classes, we should use the Google docstring-style, even if the new code is added to an existing module that otherwise uses the old docstring style, which you used here.

Context: The advantage of the Google docstring-style is that there is a Sphinx-parser that can convert it for Readthedocs. And that it is generally more compact, e.g. the <Purpose> header is omitted because it is implicit and empty sections are also omitted (often times this is the <Side Effects> section).

Please take a quick look at the style guide linked above and let me know if you have more questions.

Minor changes includes
* Improve test case of from_dict.
* Convert PreAuthEncoding to property.
* Use of TypeError instead of FormatError.

Signed-off-by: Pradyumna Krishna <git@onpy.in>
Signed-off-by: Pradyumna Krishna <git@onpy.in>
@lukpueh lukpueh merged commit d3f4888 into in-toto:master Jun 20, 2022
@PradyumnaKrishna PradyumnaKrishna deleted the dsse_envelope branch June 20, 2022 12:06
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.

Add support for DSSE
2 participants