Skip to content

Simplify NameIterator - #311

Merged
djc merged 4 commits into
mainfrom
simplify-name-iter
Jan 20, 2025
Merged

Simplify NameIterator#311
djc merged 4 commits into
mainfrom
simplify-name-iter

Conversation

@djc

@djc djc commented Jan 16, 2025

Copy link
Copy Markdown
Member

No description provided.

@djc
djc requested review from cpu and ctz January 16, 2025 20:49
@djc
djc force-pushed the simplify-name-iter branch from 8e80685 to 340a07a Compare January 16, 2025 20:50
@codecov

codecov Bot commented Jan 16, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 98.73950% with 3 lines in your changes missing coverage. Please review.

Project coverage is 97.42%. Comparing base (c32bfb9) to head (8ec1f76).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/subject_name/mod.rs 98.71% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #311      +/-   ##
==========================================
+ Coverage   97.30%   97.42%   +0.11%     
==========================================
  Files          20       20              
  Lines        4343     4345       +2     
==========================================
+ Hits         4226     4233       +7     
+ Misses        117      112       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cpu cpu 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.

This makes sense to me as a way to tidy the existing logic +1.

The broader purpose/pre-existing logic still feels off to me in a way that's tricky to articulate. Here's my analysis. WDYT?

By my read, the bool on the NameIterator (and its Option<..> predecessor) only influences whether the iterator yields GeneralName::DirectoryName after yielding each of the SANs. Previously it didn't seem to consider whether the option-wrapped untrusted::Input was empty or not, just whether it was assigned Some(_), so a bool (or a more descriptive two-value enum) seems like a sensible replacement.

The GeneralName::DirectoryName variant is a content-less variant that seems to serve no deeper purpose than to make sure we fall in to a specific rejection match arm from check_presented_id_conforms_to_constraints() when we have the cert's subject GeneralName::DirectoryName from the NameIter in hand while also looking at a GeneralName::DirectoryName base general name from a name constraint extension.

A couple questions that come to mind:

  • Does this work the right way if there's an empty cert subject? It seems like both the prev & current code set the NameIterator's directory_name control to true for the name constraint evaluation in check_name_constraints() without deeper analysis of the path node's subject. Is that the right thing to do?
  • Could we remove this logic from NameIterator entirely, and somehow arrange for an extra call to check_presented_id_conforms_to_constraints() with a hardcoded GeneralName::DirectoryName for name be made after processing the SANs from NameIterator? Is that more brittle in a way that matters?

I don't know that we need to block this small improvement on the broader topic but it feels like there's something left to pull at here. Name constraints are super gross so it's also very possible I'm overlooking some fundamental issue that makes the current approach superior/necessary.

Comment thread src/subject_name/mod.rs Outdated
@djc

djc commented Jan 20, 2025

Copy link
Copy Markdown
Member Author

Fair questions.

  • Could we remove this logic from NameIterator entirely, and somehow arrange for an extra call to check_presented_id_conforms_to_constraints() with a hardcoded GeneralName::DirectoryName for name be made after processing the SANs from NameIterator? Is that more brittle in a way that matters?

Implemented this, which seems like a nice simplification.

@djc
djc force-pushed the simplify-name-iter branch from 0b058ba to ce94ca2 Compare January 20, 2025 10:08
Comment thread src/subject_name/mod.rs

@cpu cpu 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.

LGTM, thanks!

@djc
djc added this pull request to the merge queue Jan 20, 2025
Merged via the queue into main with commit 02c153c Jan 20, 2025
@djc
djc deleted the simplify-name-iter branch January 20, 2025 13:39
@cpu

cpu commented Jan 20, 2025

Copy link
Copy Markdown
Member

Does this work the right way if there's no cert subject?

@ctz Do you have any memories on this subject from the name constraint work that happened around the time of the fork? No worries if not, just curious.

@ctz

ctz commented Jan 20, 2025

Copy link
Copy Markdown
Member

Does this work the right way if there's no cert subject?

@ctz Do you have any memories on this subject from the name constraint work that happened around the time of the fork? No worries if not, just curious.

I don't. But what do you mean by "no cert subject"? I don't think it can be entirely absent, but it could be just empty?

@cpu

cpu commented Jan 20, 2025

Copy link
Copy Markdown
Member

but it could be just empty?

That's what I meant. Sorry, agreed that "no cert subject" is ambiguous.

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.

3 participants