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

Add GPGKey Implementation #6

Merged
merged 3 commits into from
Jul 20, 2022
Merged

Conversation

PradyumnaKrishna
Copy link

Description of the changes being introduced by the pull request:

A container class representing Public Key portion of the GPG is added. it consist of a verify method to verify the GPGSignature and an arbitrary data. This GPGKey will be used to verify DSSE signatures in near future.
For simplicity dataclasses are used, which initializes several methods like __init__, __eq__ etc.

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

cc: @lukpueh

@PradyumnaKrishna PradyumnaKrishna mentioned this pull request Jul 15, 2022
3 tasks
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.

Lovely!!

@@ -120,6 +126,120 @@ def test_sslib_equality(self):
self.assertEqual(sslib_key_2, sslib_key)


@unittest.skipIf(not HAVE_GPG, "gpg not found")
class TestGPGKey(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

Let's combine this test case with test_signer.TestGPGRSA to save some redundant test code in test_key, test_signer and test_gpg.

Copy link
Author

Choose a reason for hiding this comment

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

you mean using GPGKey in test_signer.TestGPGRSA or something else?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, or keep your newly added test case and remove test_signer.TestGPGRSA. Either way is fine.

if self.subkeys:
subkeys_dict = {}
for keyid, subkey in self.subkeys.items():
subkeys_dict[keyid] = subkey.to_dict()
Copy link
Member

Choose a reason for hiding this comment

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

style nit: seems like a job for a dict comprehension

if subkeys_dict:
gpg_subkeys = {}
for keyid, subkey_dict in subkeys_dict.items():
gpg_subkeys[keyid] = GPGKey.from_dict(subkey_dict)
Copy link
Member

Choose a reason for hiding this comment

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

style nit: seems like a job for a dict comprehension

@@ -95,7 +75,7 @@ def from_dict(cls, key_dict: Dict[str, Any], keyid: str) -> "SSlibKey":
keyval = key_dict.pop("keyval")

# All fields left in the key_dict are unrecognized.
return cls(keyid, keytype, scheme, keyval, key_dict)
return cls(keytype, scheme, keyval, keyid, key_dict)
Copy link
Member

Choose a reason for hiding this comment

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

Why change the argument order?

Copy link
Author

Choose a reason for hiding this comment

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

I thought in future keyid will get optional, so it's a better position for that.

Copy link
Member

Choose a reason for hiding this comment

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

Okay. Would be good to note reasoning like this in the commit message. I think we still need to have more discussion about keyid and the other fields, both in the keys' in-memory representation (Key, see secure-systems-lab#310), and in the their metadata representation (see secure-systems-lab#308). I'll make some notes in the corresponding issues.

A container class of GPG public key required to verify GPG signatures
in DSSE.

Signed-off-by: Pradyumna Krishna <git@onpy.in>
Dataclass simplifies the SSlibKey by initilizing a constructor
and other few methods like __eq__ for the SSlibKey.
keyid argument order changed because of it's implementaion as
optional in future.

Signed-off-by: Pradyumna Krishna <git@onpy.in>
Tests all methods for a GPGKey and ensures that verification process
works properly.

Signed-off-by: Pradyumna Krishna <git@onpy.in>
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.

Great work!

Just realized that GPGSignature, GPGSigner and GPGKey don't support unrecognized_fields should we add them for consistency sake with the other implementations of Signature, Signer and Key? I suggest to not change this PR, but would you mind creating a downstream ticket.

@lukpueh
Copy link
Member

lukpueh commented Jul 20, 2022

Test failure is unrelated and has been fixed upstream (kudos to @PradyumnaKrishna, see secure-systems-lab#420). Merging

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.

2 participants