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

always digest #111

Merged
merged 13 commits into from
Apr 14, 2023
Merged

always digest #111

merged 13 commits into from
Apr 14, 2023

Conversation

drahnr
Copy link
Contributor

@drahnr drahnr commented Apr 1, 2023

@dralley includes the part of your PR, some additional cleanups, and the direction of using a fn verify_digest explicitly, so the user can opt-in explicitly to have either or both checked. The fn verify_digest is not feature gated, while the fn verify_signature is.

I hope this clarifies the conversation had in #106

Potentially I'll complete this PR soon™

@dralley dralley marked this pull request as draft April 1, 2023 19:36
@dralley
Copy link
Collaborator

dralley commented Apr 7, 2023

FYI, I'm working on an overhaul of the tests right now now, so it might be best to drop that commit to avoid conflicts - but I will try to introduce a similar split by the time I'm done with it.

Work in progress here: #115

@drahnr
Copy link
Contributor Author

drahnr commented Apr 8, 2023

@drally please hold off, I'll complete these changes early next week

@dralley
Copy link
Collaborator

dralley commented Apr 8, 2023

Well, I was hoping to finish mine tomorrow or by the end of the weekend...

Note that I'm talking exclusively about the tests and not the digest PR. It's separate.

@dralley
Copy link
Collaborator

dralley commented Apr 9, 2023

I don't, in general, like keeping tests that could (and ought to be) integration tests inside src/. The tests commit goes further in that direction and so I'd prefer we didn't do that. Just letting you know before you put too much work into it.

@drahnr drahnr marked this pull request as ready for review April 14, 2023 06:36
@drahnr drahnr requested review from cmeister2 and dralley and removed request for cmeister2 April 14, 2023 11:42
@@ -136,17 +136,17 @@ where
Ok(())
}

pub(crate) fn find_entry_or_err(&self, tag: &T) -> Result<&IndexEntry<T>, RPMError> {
pub(crate) fn find_entry_or_err(&self, tag: T) -> Result<&IndexEntry<T>, RPMError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this isn't your code, but find_entry_or_err seems a little redundant on a function that returns a Result. I don't see this pattern on any of the standard library (https://doc.rust-lang.org/std/index.html?search=or_err). Might be worth fixing up as part of this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

With regards to this specific change - I think this makes the interface a little nicer if you're only comparing to "instances" of Tags (as per the tests). I'm assuming that Tags are not very big and the general use for this interface is to search for specific Tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tags are u32s in disguise, hence there is no point in taking a reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll leave the API as is, since my expectation on a find would be to return an Option, but this does return a Result.

@drahnr drahnr requested a review from cmeister2 April 14, 2023 13:14
maxdymond

This comment was marked as duplicate.

Copy link
Collaborator

@cmeister2 cmeister2 left a comment

Choose a reason for hiding this comment

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

Oops, wrong account. Looks good :)

(I can't really comment on the design aspects here - they look reasonable though! The Rust I've already commented on.)

@drahnr drahnr merged commit 815ddb3 into master Apr 14, 2023
@drahnr drahnr deleted the bernhard-always-digest branch April 14, 2023 14:12
@dralley
Copy link
Collaborator

dralley commented Apr 14, 2023

@drahnr I had asked for "split up tests" to be dropped : /

@drahnr
Copy link
Contributor Author

drahnr commented Apr 14, 2023

I am sorry, I forgot about that. I would generally prefer if we could sync on any upcoming work, rather than fighting on changes to merged or skipped, but rather avoid competing changes in the first place if they become to cumbersome to do a git-rebase.

@drahnr drahnr mentioned this pull request Apr 14, 2023
5 tasks
@dralley
Copy link
Collaborator

dralley commented Apr 14, 2023

@drahnr Since the commits got squashed, the commit a408803b13 isn't present in the git tree, which makes it kind of a pain to revert. Since you still have it in your local git history, can you revert it and push?

@@ -142,12 +191,10 @@ impl RPMPackage {
///
///
#[cfg(feature = "signature-meta")]
pub fn verify_signature<V>(&self, verifier: V) -> Result<(), RPMError>
pub fn verify_signature<V>(&self, verifier: V) -> Result<SignatureVerificationOutcome, RPMError>
Copy link
Collaborator

Choose a reason for hiding this comment

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

@drahnr I'm confused by this. Nothing actually returns SignatureVerificationOutcome::Fail so it doesn't seem useful? Even if it did, encoding an error condition in the success path feels very wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct, fix eta today

Ok(DigestVerificationOutcome::Match)
} else {
Ok(DigestVerificationOutcome::Mismatch)
}
Copy link
Collaborator

@dralley dralley Apr 15, 2023

Choose a reason for hiding this comment

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

A test for this would be good.

Like above though I'm confused about the error strategy. If I were to write some fairly intuitive code such as

pkg.verify_digest()?;

it effectively won't actually be checking the digests because we've created a separate feedback mechanisms, and we're not marking the return value #[must_use] to force the user to check it. It feels like a footgun.

Also with this approach there is no way to tell which digest failed or get any additional context back? We already have a ValidationError variant for signature mismatch, I'm just confused why we're doing something different for digests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rationale was, that the RPM format is fine, the signature just failed to verify. And the verfication might simply caused by a missing key.

But I think for the common usage pattern you're correct that it poses a footgun.

Copy link
Collaborator

Choose a reason for hiding this comment

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

VerificationError could have subtypes potentially

Copy link
Collaborator

Choose a reason for hiding this comment

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

} = RPMPackage::create_digests_from_readers(
&mut header.as_slice(),
header_and_content_cursor,
)?;
Copy link
Collaborator

@dralley dralley Apr 15, 2023

Choose a reason for hiding this comment

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

Modern versions of RPM don't actually generate these digests, but they would still be needed for e.g. EL7 packages. Maybe in a year when it goes EOL we can ditch this code.

This function can only be used for the legacy digests though, because the modern ones (PAYLOADDIGEST, PAYLOADDIGESTALT which I am currently adding support for) go into the main header, which has already been generated at this point.

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.

4 participants