Skip to content

Calling PEM_read_bio_PrivateKey() and PEM_read_bio_X509() on the same BIO is broken #14788

Closed

Description

@t8m

If there is both private key and certificate in a file and it is read by calling PEM_read_bio_PrivateKey() and then PEM_read_bio_X509(), the X509 decoding will fail with the current master because when decoding the key the file is completely read and the X509 decoding does not have any data to read.

Activity

  1. added
    branch: master
    triaged: bug
    on Apr 7, 2021
  2. added this to the 3.0.0 beta1 milestone on Apr 7, 2021
  3. self-assigned this
    on Apr 7, 2021
  4. reopened this on Apr 7, 2021
  5. richsalz commented on Apr 7, 2021

    @richsalz
    Contributor

    When you think about the general case, this becomes more complicated. Imagine a file with multiple certs. You don't want to rewind (which you might for cert/key) because you'll keep re-reading the same cert. You don't want to ftell/fseek back to where you were because you'll get the same problem.

    It might be cleaner to have a "rewind if necessary" behavior. Or leave it up to the application to do that.

  6. t8m commented on Apr 7, 2021

    @t8m
    MemberAuthor

    IMO we simply should not regress on this in comparison with 1.1.1. At least not in the simple case of having a key and cert in the file in the same order as it is to be read.

  7. richsalz commented on Apr 7, 2021

    @richsalz
    Contributor

    Just to make sure I understand: the file has key and then cert, and calling read-private-key now consumes the whole file so the subsequent call to read-cert fails. If that's the case, then yes, that seems like a bug. Everything else stops when it gets what it is looking for. Is consume the whole file common now? That should be noted if so. But yes I agree the regression should be fixed.

  8. t8m commented on Apr 7, 2021

    @t8m
    MemberAuthor

    Yes, your understanding is correct.

  9. added a commit that references this issue on Jul 7, 2021
    df66093
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

branch: mastertriaged: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions