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

Remove uses of keyid_hash_algorithms #1014

Merged

Conversation

mnm678
Copy link
Contributor

@mnm678 mnm678 commented Apr 2, 2020

This is a first step toward removing keyid_hash_algorithms from the reference implementation as discussed in #848. This pr removes all uses of this field during the client verification by using the keyids provided in the metadata instead of recalculating keyids using the keyid_hash_algorithms.

This pr requires changes to securesystemslib that are is a pull request at secure-systems-lab/securesystemslib#225.

@mnm678 mnm678 mentioned this pull request Jul 17, 2020
3 tasks
@mnm678 mnm678 requested review from lukpueh and joshuagl July 21, 2020 17:49
@joshuagl joshuagl added the securesystemslib Requires corresponding implementation in securesystemslib label Jul 23, 2020
Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

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

Thanks for the submission Marina! Am I correct in thinking the behavioural changes introduced by this PR are that:

  • a client no longer recalculates keyids, and instead trusts the values in the metadata
  • when loading an existing repository with repository_tool, keyids are not calculated and instead the keyids from the metadata are used

I'd like to see the additional test for a duplicate keyid enabled, or removed from this PR. I also pointed had some minor comments inline about not passing the default value for an argument and what appears to be unnecessarily assigning a value to a dictionary field.

NOTE: the required securesystemslib change has been merged and is available in release 0.15.0, which we already depend on in py-TUF.

Comment on lines 377 to 380
# New key with a duplicate keyid
#rsakey4 = KEYS[1]
#keyid4 = KEYS[3]['keyid']
#keydict[keyid4] = rsakey4
Copy link
Member

Choose a reason for hiding this comment

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

Should this test work? If not, what's preventing it from working? Should we be addressing it in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As keyids are no longer calculated before use, the client will want a different way to verify that all keys applied to a threshold are unique. I think this may be better left to a separate pr (which I've documented in #1084) for 2 reasons:

  • This is a larger change that will require creating a standardized representation for keys
  • It is only an issue if the delegating metadata makes a mistake or in the case of multi-role delegations (which are not currently in the reference implementation). Also, this issue already exists with the current implementation if multiple keyid_hash_algorithms are used

That being said, I have started looking into this issue and could include the fix here if that would be more clear. Otherwise I'll remove this test for now.

self.assertRaises(tuf.exceptions.UnknownKeyError, tuf.keydb.get_key, keyid3)
#self.assertRaises(tuf.exceptions.UnknownKeyError, tuf.keydb.get_key, keyid4)
Copy link
Member

Choose a reason for hiding this comment

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

Can we enable this part of the test?

tuf/client/updater.py Outdated Show resolved Hide resolved
tuf/keydb.py Outdated
# keyids, otherwise add_key() will have no reference to it.
key_dict['keyid'] = keyid
add_key(key_dict, keyid=None, repository_name=repository_name)
key_dict['keyid'] = keyid
Copy link
Member

Choose a reason for hiding this comment

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

I think key_dict['keyid'] should already be set to keyid here, because we pass it in as the default_keyid in format_metadata_to_key?

tuf/keydb.py Outdated Show resolved Hide resolved
key_object['keyid'] = keyid
tuf.keydb.add_key(key_object, keyid=None,
repository_name=repository_name)
key_object['keyid'] = keyid
Copy link
Member

Choose a reason for hiding this comment

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

Again, I think this is already set correctly by format_metadata_to_key()?

@joshuagl
Copy link
Member

Note the DCO check is failing because none of the commits have a Signed-off-by: line, the check details suggest the following to address that:

git rebase HEAD~8 --signoff
git push --force-with-lease origin remove-keyid_hash_algorithms

mnm678 and others added 11 commits July 23, 2020 09:53
… as the keyid is provided in signed metadata. Removing this check allows the client to avoid use of the keyid_hash_algorithm field during verification. Note that this change requires a small change to the securesystemslib api.

Signed-off-by: marinamoore <mmoore32@calpoly.edu>
…eyid. Check that this keyid matches the keyid listed in the key for consistent behavior.

Signed-off-by: marinamoore <mmoore32@calpoly.edu>
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
…e keyid provided in the delegation. Note that this requires a change to securesystems lib.

Signed-off-by: marinamoore <mmoore32@calpoly.edu>
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
@mnm678 mnm678 force-pushed the remove-keyid_hash_algorithms branch from 8fe9ef7 to 376590d Compare July 23, 2020 16:53
@mnm678
Copy link
Contributor Author

mnm678 commented Jul 23, 2020

Thanks for the submission Marina! Am I correct in thinking the behavioural changes introduced by this PR are that:

* a client no longer recalculates keyids, and instead trusts the values in the metadata

* when loading an existing repository with repository_tool, keyids are not calculated and instead the keyids from the metadata are used

Thanks for the review! Yes, those are the main behavioural changes. These changes will help both with the TAP 12 implementation and with the removal of keyid_hash_algorithms from TUF metadata per #848.

@mnm678
Copy link
Contributor Author

mnm678 commented Jul 23, 2020

The failing test looks like a timeout issue that should be unrelated to this pr.

Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

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

Some minor comments in-line, but otherwise LGTM.

tests/test_keydb.py Outdated Show resolved Hide resolved
tests/test_keydb.py Outdated Show resolved Hide resolved
Co-authored-by: Joshua Lock <jlock@vmware.com>
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
@mnm678 mnm678 force-pushed the remove-keyid_hash_algorithms branch from 0c1ee76 to f96cf50 Compare July 28, 2020 13:54
Copy link
Member

@trishankatdatadog trishankatdatadog left a comment

Choose a reason for hiding this comment

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

💯

Should we have an accompany securesystemslib PR to remove securesystemslib.settings.HASH_ALGORITHMS?

@mnm678
Copy link
Contributor Author

mnm678 commented Jul 29, 2020

Should we have an accompany securesystemslib PR to remove securesystemslib.settings.HASH_ALGORITHMS?

Is this setting used by other securesystemslib users, especially intoto? @SantiagoTorres @lukpueh

@joshuagl
Copy link
Member

Should we have an accompany securesystemslib PR to remove securesystemslib.settings.HASH_ALGORITHMS?

Is this setting used by other securesystemslib users, especially intoto? @SantiagoTorres @lukpueh

Based on a quick git grep of in-toto, it doesn't appear to be used there.

@joshuagl joshuagl merged commit 7b4ffe3 into theupdateframework:develop Aug 18, 2020
joshuagl added a commit to joshuagl/tuf that referenced this pull request Sep 9, 2020
PR theupdateframework#1014 removed uses of keyid_hash_algorithms in favour of using the calculated
keyid values from the metadata. A few instances of this removal were
unintentionally reintroduced in PR theupdateframework#1016, when changing to explicitly passing
a list of hash algorithms rather than changing securesystemslib settings
values.

This change removes uneccessary uses of keyid_hash_algorithms.

Signed-off-by: Joshua Lock <jlock@vmware.com>
MVrachev pushed a commit to MVrachev/tuf that referenced this pull request Sep 17, 2020
PR theupdateframework#1014 removed uses of keyid_hash_algorithms in favour of using the calculated
keyid values from the metadata. A few instances of this removal were
unintentionally reintroduced in PR theupdateframework#1016, when changing to explicitly passing
a list of hash algorithms rather than changing securesystemslib settings
values.

This change removes uneccessary uses of keyid_hash_algorithms.

Signed-off-by: Joshua Lock <jlock@vmware.com>
@lukpueh
Copy link
Member

lukpueh commented Feb 1, 2021

Hi @lorenzo-blasa! What exactly are you trying to achieve? Maybe taking a look at the corresponding PR (#1014) helps to better understand the commit (3c78d67)?

@lorenzo-blasa
Copy link

@lukpueh many thanks! That PR definitely helps. I'm currently working on having a TUF reference implementation written in JavaScript. The effort started last year and only last week I resumed.

So I was running the local JavaScript tests and comparing that with the version I had in Python and I found it was also failing but maybe because the unit tests were actually referring the TUF package installed instead of the local copy.

Running pip install -r requirements-dev.txt made it all work but it wasn't very clear what had changed as I didn't do a very good job at tracking the revision I was using as base.

It's all good now :)

@trishankatdatadog
Copy link
Member

@lorenzo-blasa A tuf.js has been a dream of mine for a while now... you might look at my toy reimplementation tuf-on-a-plane to get a few more clarifications or ideas. Thanks for your feedback!

@lorenzo-blasa
Copy link

@trishankatdatadog thanks for sharing that!

The intention I have with the JS implementation is to open source it as soon as possible, being complete and going through necessary approvals. So it's great to know there's more people interested in it.

@lukpueh
Copy link
Member

lukpueh commented Feb 1, 2021

@lorenzo-blasa, tuf.js sounds exciting, please keep us posted! And of course, feel free to ping us if you have any questions regarding the TUF spec or this reference implementation.

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

Successfully merging this pull request may close these issues.

None yet

6 participants