Skip to content

gh-100372: Use BIO_eof to detect EOF for SSL_FILETYPE_ASN1#100373

Merged
miss-islington merged 2 commits into
python:mainfrom
davidben:der-eof
Mar 24, 2023
Merged

gh-100372: Use BIO_eof to detect EOF for SSL_FILETYPE_ASN1#100373
miss-islington merged 2 commits into
python:mainfrom
davidben:der-eof

Conversation

@davidben

@davidben davidben commented Dec 20, 2022

Copy link
Copy Markdown
Contributor

In PEM, we need to parse until error and then suppress PEM_R_NO_START_LINE, because PEM allows arbitrary leading and trailing data. DER, however, does not. Parsing until error and suppressing ASN1_R_HEADER_TOO_LONG doesn't quite work because that error also covers some cases that should be rejected.

Instead, check BIO_eof early and stop the loop that way.

Automerge-Triggered-By: GH:Yhg1s

In PEM, we need to parse until error and then suppress
PEM_R_NO_START_LINE, because PEM allows arbitrary leading and trailing
data. DER, however, does not. Parsing until error and suppressing
ASN1_R_HEADER_TOO_LONG doesn't quite work because that error also
covers some cases that should be rejected.

Instead, check BIO_eof early and stop the loop that way.
@davidben

Copy link
Copy Markdown
Contributor Author

@tiran This PR look reasonable? Anything missing on my end?

@Yhg1s Yhg1s self-requested a review March 24, 2023 12:36
@Yhg1s

Yhg1s commented Mar 24, 2023

Copy link
Copy Markdown
Member

I don't think this is a security issue, or at least not serious enough to backport to security-only releases. Do you disagree, @davidben, or is there a security angle I'm missing?

I'm not sure if this should be backported to 3.11/3.10 either. It's a bug, but it doesn't feel important enough to backport and risk breaking users who rely on the old broken behaviour.

@miss-islington

Copy link
Copy Markdown
Contributor

Status check is done, and it's a success ✅.

@miss-islington miss-islington merged commit acfe02f into python:main Mar 24, 2023
@davidben

Copy link
Copy Markdown
Contributor Author

Do you disagree, @davidben, or is there a security angle I'm missing?

Nah, can't think of any security angle. Just generally improving behavior and reducing dependency on OpenSSL error codes. (Conditioning on OpenSSL error codes can be a bit messy. Sometimes you have to, like the PEM case here, but other times the error codes don't correspond enough to clear, stable conditions to condition on. :-( )

Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
…honGH-100373)

In PEM, we need to parse until error and then suppress `PEM_R_NO_START_LINE`, because PEM allows arbitrary leading and trailing data. DER, however, does not. Parsing until error and suppressing `ASN1_R_HEADER_TOO_LONG` doesn't quite work because that error also covers some cases that should be rejected.

Instead, check `BIO_eof` early and stop the loop that way.

Automerge-Triggered-By: GH:Yhg1s
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
…honGH-100373)

In PEM, we need to parse until error and then suppress `PEM_R_NO_START_LINE`, because PEM allows arbitrary leading and trailing data. DER, however, does not. Parsing until error and suppressing `ASN1_R_HEADER_TOO_LONG` doesn't quite work because that error also covers some cases that should be rejected.

Instead, check `BIO_eof` early and stop the loop that way.

Automerge-Triggered-By: GH:Yhg1s
@h-vetinari

Copy link
Copy Markdown
Contributor

I'm not sure if this should be backported to 3.11/3.10 either. It's a bug, but it doesn't feel important enough to backport and risk breaking users who rely on the old broken behaviour.

FWIW, the fact that this was not backported is now affecting 3.10/3.11 versions together with the newest set of openssl versions (e.g. 3.6.3, 3.5.7): conda-forge/openssl-feedstock#237

The patch backports cleanly to 3.10 & 3.11 (and fixes the regression), which is what I'm looking towards doing as a fix for this in conda-forge.

@miss-islington-app

Copy link
Copy Markdown

Thanks @davidben for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @davidben for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 8, 2026

Copy link
Copy Markdown

GH-153311 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.11 only security fixes label Jul 8, 2026
@bedevere-app

bedevere-app Bot commented Jul 8, 2026

Copy link
Copy Markdown

GH-153312 is a backport of this pull request to the 3.10 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.10 only security fixes label Jul 8, 2026
@encukou

encukou commented Jul 8, 2026

Copy link
Copy Markdown
Member

It now fails on macOS on GitHub Actions; I made backports to run the CI.

It's up to the RMs. Not a security issue; it can make an OpenSSL upgrade break working code.
The alternative is of course to skip (or ignore) the relevant tests.

@nerijus

nerijus commented Jul 8, 2026

Copy link
Copy Markdown

Should be backported to 3.9 too, as it fails on CentOS 9 after openssl update.

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.

7 participants