Skip to content

Conversation

levitte
Copy link
Member

@levitte levitte commented Jul 10, 2025

OSSL_STORE_load() called OSSL_STORE_eof() before checking if there is
cached OSSL_STORE_INFO to consider. To fix this issue, the cached info
check is moved to OSSL_STORE_eof(), as that seems to make most common
sense.

This solves an issue with PKCS#12 files, where the cached info was never
considered because the underlying file IO layer signaled that EOF is
reached.

Fixes #28010

OSSL_STORE_load() called OSSL_STORE_eof() before checking if there is
cached OSSL_STORE_INFO to consider.  To fix this issue, the cached info
check is moved to OSSL_STORE_eof(), as that seems to make most common
sense.

This solves an issue with PKCS#12 files, where the cached info was never
considered because the underlying file IO layer signaled that EOF is
reached.

Fixes openssl#28010
@levitte levitte added branch: master Merge to master branch approval: review pending This pull request needs review by a committer triaged: bug The issue/pr is/fixes a bug branch: 3.0 Merge to openssl-3.0 branch severity: regression The issue/pr is a regression from previous released version branch: 3.2 Merge to openssl-3.2 branch: 3.3 Merge to openssl-3.3 branch: 3.4 Merge to openssl-3.4 branch: 3.5 Merge to openssl-3.5 labels Jul 10, 2025
@levitte
Copy link
Member Author

levitte commented Jul 10, 2025

Please note that #28010 shows a regression. The same PKCS#12 was loaded flawlessly in OpenSSL 1.1.1

@DDvO
Copy link
Contributor

DDvO commented Jul 10, 2025

Would be good to add a test case demonstrating that the issue is fixed and flagging any future regression.

@levitte
Copy link
Member Author

levitte commented Jul 10, 2025

Would be good to add a test case demonstrating that the issue is fixed and flagging any future regression.

I agree, but will need a triggering test case. I'm currently checking an unpatched 3.5 to see if the regression is visible there somehow

@levitte
Copy link
Member Author

levitte commented Jul 10, 2025

Would be good to add a test case demonstrating that the issue is fixed and flagging any future regression.

I agree, but will need a triggering test case. I'm currently checking an unpatched 3.5 to see if the regression is visible there somehow

Nope, our tests are fine, so it's quite clear that the unusual form of the PKCS#12 file you tested with was part of the issue, and that we have never seen that case before.

t8m
t8m previously approved these changes Jul 10, 2025
Copy link
Member

@t8m t8m left a comment

Choose a reason for hiding this comment

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

Very interesting. I wonder if there are any other consequences of this bug not related to PKCS12 at all. For example in terms of a file containing multiple PEM encoded objects of a different type.

@t8m t8m added the tests: deferred Tests will be added in a subsequent PR (label should be removed when the PR with tests is merged) label Jul 10, 2025
@levitte
Copy link
Member Author

levitte commented Jul 10, 2025

... For example in terms of a file containing multiple PEM encoded objects of a different type.

Nope. They are genuinely loaded from the file one at a time. PKCS#12 makes for a unique situation, where all objects are wrapped into one container, and because of how the rest of the flow works, the only way to handle those is to unpack them and cache them.

@DDvO
Copy link
Contributor

DDvO commented Jul 12, 2025

The fix looks good to me.

Would be good to add a test case demonstrating that the issue is fixed and flagging any future regression.

I agree, but will need a triggering test case. I'm currently checking an unpatched 3.5 to see if the regression is visible there somehow

Nope, our tests are fine, so it's quite clear that the unusual form of the PKCS#12 file you tested with was part of the issue, and that we have never seen that case before.

So PKCS#12 with non-DER indefinite-length encodings have never been explicitly addressed before,
but happened to be supported before OpenSSL 3.0.

Why not simply add a CLI-based test like this?

openssl x509 -passin pass:12345 -in test-BER.p12 

Unfortunately cannot use the more general storeutl app here because
it does not have a -pass(in) option, which IMO should be added
for general usability, in particular for non-interactive scenarios.

@levitte
Copy link
Member Author

levitte commented Jul 15, 2025

@DDvO, may I consider the PKCS#12 file from #28010 as a contribution for testing with?

@DDvO
Copy link
Contributor

DDvO commented Jul 16, 2025

Actually this is what I had in mind. I'd just suggest renaming it (to e.g., test-BER.p12 as written above)
because as you found the point here is the encoding, not the encryption alg.

DDvO
DDvO previously approved these changes Jul 16, 2025
Copy link
Contributor

@DDvO DDvO 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 fix, including the test case.

The test file (test-BER.p12) was given to us by David von Oheimb

Co-Authored-By: David von Oheimb <david.von.oheimb@siemens.com>
@levitte
Copy link
Member Author

levitte commented Jul 17, 2025

Unfortunately, test-BER.p12 causes errors when DES or EC are disabled. I've modified the test accordingly.

@levitte levitte requested a review from DDvO July 17, 2025 07:05
Copy link
Contributor

@DDvO DDvO left a comment

Choose a reason for hiding this comment

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

reconfirmed

@DDvO DDvO requested a review from t8m July 18, 2025 12:23
@t8m t8m added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Jul 24, 2025
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Jul 25, 2025
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
OSSL_STORE_load() called OSSL_STORE_eof() before checking if there is
cached OSSL_STORE_INFO to consider.  To fix this issue, the cached info
check is moved to OSSL_STORE_eof(), as that seems to make most common
sense.

This solves an issue with PKCS#12 files, where the cached info was never
considered because the underlying file IO layer signaled that EOF is
reached.

Fixes #28010

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
The test file (test-BER.p12) was given to us by David von Oheimb

Co-Authored-By: David von Oheimb <david.von.oheimb@siemens.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
OSSL_STORE_load() called OSSL_STORE_eof() before checking if there is
cached OSSL_STORE_INFO to consider.  To fix this issue, the cached info
check is moved to OSSL_STORE_eof(), as that seems to make most common
sense.

This solves an issue with PKCS#12 files, where the cached info was never
considered because the underlying file IO layer signaled that EOF is
reached.

Fixes #28010

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 1f3af48)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
The test file (test-BER.p12) was given to us by David von Oheimb

Co-Authored-By: David von Oheimb <david.von.oheimb@siemens.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 49f8db5)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
OSSL_STORE_load() called OSSL_STORE_eof() before checking if there is
cached OSSL_STORE_INFO to consider.  To fix this issue, the cached info
check is moved to OSSL_STORE_eof(), as that seems to make most common
sense.

This solves an issue with PKCS#12 files, where the cached info was never
considered because the underlying file IO layer signaled that EOF is
reached.

Fixes #28010

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 1f3af48)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
The test file (test-BER.p12) was given to us by David von Oheimb

Co-Authored-By: David von Oheimb <david.von.oheimb@siemens.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 49f8db5)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
OSSL_STORE_load() called OSSL_STORE_eof() before checking if there is
cached OSSL_STORE_INFO to consider.  To fix this issue, the cached info
check is moved to OSSL_STORE_eof(), as that seems to make most common
sense.

This solves an issue with PKCS#12 files, where the cached info was never
considered because the underlying file IO layer signaled that EOF is
reached.

Fixes #28010

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 1f3af48)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
The test file (test-BER.p12) was given to us by David von Oheimb

Co-Authored-By: David von Oheimb <david.von.oheimb@siemens.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 49f8db5)
@DDvO
Copy link
Contributor

DDvO commented Jul 26, 2025

Merged to all indicated branches - thanks.

@DDvO DDvO closed this Jul 26, 2025
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
OSSL_STORE_load() called OSSL_STORE_eof() before checking if there is
cached OSSL_STORE_INFO to consider.  To fix this issue, the cached info
check is moved to OSSL_STORE_eof(), as that seems to make most common
sense.

This solves an issue with PKCS#12 files, where the cached info was never
considered because the underlying file IO layer signaled that EOF is
reached.

Fixes #28010

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 1f3af48)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
The test file (test-BER.p12) was given to us by David von Oheimb

Co-Authored-By: David von Oheimb <david.von.oheimb@siemens.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 49f8db5)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
OSSL_STORE_load() called OSSL_STORE_eof() before checking if there is
cached OSSL_STORE_INFO to consider.  To fix this issue, the cached info
check is moved to OSSL_STORE_eof(), as that seems to make most common
sense.

This solves an issue with PKCS#12 files, where the cached info was never
considered because the underlying file IO layer signaled that EOF is
reached.

Fixes #28010

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 1f3af48)
openssl-machine pushed a commit that referenced this pull request Jul 26, 2025
The test file (test-BER.p12) was given to us by David von Oheimb

Co-Authored-By: David von Oheimb <david.von.oheimb@siemens.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #28016)

(cherry picked from commit 49f8db5)
@levitte
Copy link
Member Author

levitte commented Jul 27, 2025

Thank you

@levitte levitte deleted the fix-28010 branch July 27, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.2 Merge to openssl-3.2 branch: 3.3 Merge to openssl-3.3 branch: 3.4 Merge to openssl-3.4 branch: 3.5 Merge to openssl-3.5 severity: regression The issue/pr is a regression from previous released version tests: present The PR has suitable tests present triaged: bug The issue/pr is/fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OSSL_STORE does not support loading certs from unusual PKCS#12 encoding and does not give any clue about this
4 participants