PEM_X509_INFO_READ_BIO_EX(3ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… PEM_X509_INFO_READ_BIO_EX β€” or, how to slurp PEM blobs into X509_INFO cuties

okay so this page lives in section 3ossl of the OpenSSL manual, and it's literally the whole glow-up guide for four functions that read PEM-encoded stuff into one or more X509_INFO objects. bestie, if you've ever stared at a .pem file full of -----BEGIN lines and thought "what even is all this", this is your page πŸŽ€


✨ 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 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);

copy these exactly, bestie, no "fixing" them, they're iconic as-is πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, function by function:

  • PEM_X509_INFO_read_ex() β€” loads the X509_INFO objects from a file fp. that's it, that's the whole job ✨
  • PEM_X509_INFO_read() β€” same energy as PEM_X509_INFO_read_ex(), except it uses the default (NULL) library context libctx and an empty property query propq. so like, the plain-vanilla version 🍦
  • PEM_X509_INFO_read_bio_ex() β€” loads the X509_INFO objects using a bio bp.
  • PEM_X509_INFO_read_bio() β€” same as PEM_X509_INFO_read_bio_ex() but with the default (NULL) library context libctx and empty property query propq. again: vanilla 🫢

🌈 what's actually inside an X509_INFO?

each of the loaded X509_INFO objects can contain a CRL, a certificate, and/or a private key β€” like a little trio friendship bracelet πŸ”₯

the elements get read sequentially, and as far as they're of a different type than the elements read before them, they get combined into the same X509_INFO object. the idea behind this? say a certificate is followed by a private key β€” then that private key is supposed to correspond to that certificate. main character + their plus-one energy, fr fr πŸ’œ

🧚 the sk stack situation

if the input stack sk is NULL, a new stack is allocated. otherwise, the given stack gets extended. choose your fighter πŸ’…

πŸ” passwords & the cb / u duo

the optional cb and u parameters can be used to provide a pass phrase needed for decrypting encrypted PEM structures (normally only private keys). see PEM_read_bio_PrivateKey(3) and passphrase-encoding(7) for the details β€” iykyk 😭

πŸ‘‘ libctx & propq

the library context libctx and property query propq are used for fetching algorithms from providers. that's their whole job, no cap ⭐


πŸ’€ RETURN VALUES πŸ’€

PEM_X509_INFO_read_ex(), PEM_X509_INFO_read(), PEM_X509_INFO_read_bio_ex() and PEM_X509_INFO_read_bio() all return a stack of X509_INFO objects β€” or NULL on failure 😭 (yes, all four, no exceptions, check your returns bestie)


πŸ’– SEE ALSO πŸ’–

go read these next, they're the extended universe:


⭐ HISTORY ⭐

the functions PEM_X509_INFO_read_ex() and PEM_X509_INFO_read_bio_ex() were added in OpenSSL 3.0. so if you're on something older, those _ex cuties simply do not exist yet πŸ™ˆ


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>.

ngl, "you may not use this file except in compliance with the License" is the serious bit β€” take it seriously, bestie, it's the actual legal tea πŸ’…

alright, that's the whole page 🌸 huge shoutout to OpenSSL 3.5.6, dated 2026-04-07 β€” that's the version and date this page shipped with, mwah πŸ’‹ slay, go read your PEM files responsibly πŸ¦‹

πŸ“¦ where this page comes from