Skip to content

reject empty subjectAltName and issuerAltName sequences - #15472

Open
dxbjavid wants to merge 1 commit into
pyca:mainfrom
dxbjavid:empty-san-ian-sequence
Open

reject empty subjectAltName and issuerAltName sequences#15472
dxbjavid wants to merge 1 commit into
pyca:mainfrom
dxbjavid:empty-san-ian-sequence

Conversation

@dxbjavid

Copy link
Copy Markdown
Contributor

RFC 5280 defines subjectAltName and issuerAltName as a GeneralNames value, which is a SEQUENCE of one or more GeneralName, but the parser accepted an empty sequence, so a malformed certificate or CRL carrying a zero-entry SAN or IAN parsed to an empty extension rather than being rejected. The check sits in parse_general_names rather than on the GeneralNames type alias because the path validation engine reuses that alias and relies on an empty sequence to stand in for a certificate with no SAN. This rejects an empty sequence when the extension is parsed, matching the constraint and the behaviour already in place for an empty extendedKeyUsage.

// RFC 5280, so an empty sequence is malformed. The path validation engine
// represents a certificate with no subjectAltName using its own empty
// sequence and does not call this.
if gn_seq.clone().next().is_none() {

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.

SequenceOf takes a MINIMUM_LEN, is there a reason not to just set that to 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i looked at that first, but the SubjectAlternativeName and IssuerAlternativeName aliases are shared with the path validation engine, which stands in for a certificate with no SAN by parsing an empty sequence into SubjectAlternativeName (the \x30\x00 parse in cryptography-x509-verification/src/lib.rs). setting MINIMUM_LEN to 1 on the alias would make that parse fail. keeping the check in parse_general_names also means the other GeneralNames users that go through it, authorityCertIssuer and the CRL distribution point names, pick up the same 1..MAX constraint, since 5280 defines them all the same way. happy to move it to a type-level constraint if you'd rather give verification its own zero-minimum type.

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.

Oh, I think we should probably fix the \x30\x00 callsites to just store an Option<SequenceOf<>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants