Skip to content

Add GPGKey Implementation#6

Merged
lukpueh merged 3 commits into
in-toto:masterfrom
PradyumnaKrishna:gpgkey
Jul 20, 2022
Merged

Add GPGKey Implementation#6
lukpueh merged 3 commits into
in-toto:masterfrom
PradyumnaKrishna:gpgkey

Conversation

@PradyumnaKrishna

Copy link
Copy Markdown

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

@lukpueh lukpueh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lovely!!

Comment thread tests/test_key.py Outdated


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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread securesystemslib/key.py Outdated
if self.subkeys:
subkeys_dict = {}
for keyid, subkey in self.subkeys.items():
subkeys_dict[keyid] = subkey.to_dict()

Copy link
Copy Markdown
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

Comment thread securesystemslib/key.py Outdated
if subkeys_dict:
gpg_subkeys = {}
for keyid, subkey_dict in subkeys_dict.items():
gpg_subkeys[keyid] = GPGKey.from_dict(subkey_dict)

Copy link
Copy Markdown
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

Comment thread securesystemslib/key.py

# 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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>

@lukpueh lukpueh left a comment

Copy link
Copy Markdown
Member

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

lukpueh commented Jul 20, 2022

Copy link
Copy Markdown
Member

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