PEM_X509_INFO_READ_BIO_EX(3ossl)

πŸ’– PEM_X509_INFO_READ_BIO_EX πŸ’–

okay so bestie, this one's from the OpenSSL manual, section 3ossl, and it's literally all about the PEM ✨info reading✨ girlies: PEM_X509_INFO_read_ex, PEM_X509_INFO_read, PEM_X509_INFO_read_bio_ex, and PEM_X509_INFO_read_bio. four functions, one job, and that job is pulling PEM-encoded stuff out of a file or a BIO and turning it into one or more X509_INFO objects. no cap. πŸŽ€


🌸 NAME 🌸

PEM_X509_INFO_read_ex, PEM_X509_INFO_read, PEM_X509_INFO_read_bio_ex, PEM_X509_INFO_read_bio β€” read PEM-encoded data structures into one or more X509_INFO objects. that's it, that's the whole vibe πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <openssl/pem.h>

STACK_OF(X509_INFO) *PEM_X509_INFO_read_ex(FILE *fp, STACK_OF(X509_INFO) *sk,
                                           pem_password_cb *cb, void *u,
                                           OSSL_LIB_CTX *libctx,
                                           const char *propq);
STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
                                        pem_password_cb *cb, void *u);
STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio_ex(BIO *bio,
                                               STACK_OF(X509_INFO) *sk,
                                               pem_password_cb *cb, void *u,
                                               OSSL_LIB_CTX *libctx,
                                               const char *propq);
STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk,
                                            pem_password_cb *cb, void *u);

like, look at those return types. STACK_OF(X509_INFO) *. we love a pointer to a stack, it's giving organized πŸ’…


✨ DESCRIPTION ✨

so here's the tea, bestie πŸ“

  • PEM_X509_INFO_read_ex() β€” loads the X509_INFO objects from a file fp. that's the whole thing, it just reads the file, iconic behavior.
  • PEM_X509_INFO_read() β€” basically the same as PEM_X509_INFO_read_ex() except it uses the default (that's NULL) library context libctx and an empty property query propq. the no-frills version, lowkey.
  • PEM_X509_INFO_read_bio_ex() β€” loads the X509_INFO objects using a bio bp. yes, BIO girlies get their own function, we stay fed 🫢
  • PEM_X509_INFO_read_bio() β€” same energy as PEM_X509_INFO_read_bio_ex() except again: default (that's NULL) library context libctx, empty property query propq.

now the actual juicy part πŸ‘‘

Each of the loaded X509_INFO objects can contain a CRL, a certificate, and/or a private key. yes, and/or. the elements get read sequentially, and as long as they're a different type than the elements read before them, they get combined into the same X509_INFO object. the reasoning behind this? say it with me: if a certificate is followed by a private key, then the private key is supposed to correspond to the certificate. it's a matching set, bestie, it's giving couple goals πŸ’–

about the input stack sk:

  • if sk is NULL β†’ a new stack gets allocated, fresh out the box ✨
  • if sk is not NULL β†’ the given stack gets extended, no replacement, just growth 🌱

and the optional cb and u parameters? those are for providing a pass phrase when you need to decrypt encrypted PEM structures (normally that's only private keys, iykyk πŸ”). for the full deets, go see PEM_read_bio_PrivateKey(3) and passphrase-encoding(7).

last but not least: the library context libctx and the property query propq are used for fetching algorithms from providers. periodt.


πŸ”₯ RETURN VALUES πŸ”₯

PEM_X509_INFO_read_ex(), PEM_X509_INFO_read(), PEM_X509_INFO_read_bio_ex() and PEM_X509_INFO_read_bio() return a stack of X509_INFO objects… or NULL on failure 😭. that's the whole deal. if you get NULL, something went wrong, and no amount of manifesting will fix it. check your inputs.


🌈 SEE ALSO 🌈

go read those too, they're part of the lore πŸ’œ


πŸ‘‘ HISTORY πŸ‘‘

the functions PEM_X509_INFO_read_ex() and PEM_X509_INFO_read_bio_ex() were added in OpenSSL 3.0. so yeah, they're the newer siblings, the _ex girlies came later and we're obsessed πŸŽ€


Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


okay that's the page bestie, go forth and read your PEM structures 🌸

this was OpenSSL 3.5.9, dated 2026-09-29, and the manual page is PEM_X509_INFO_READ_BIO_EX(3ossl) β€” mwah, slay, bye πŸ’…βœ¨

πŸ“¦ where this page comes from