PEM_BYTES_READ_BIO(3ossl)
π PEM_BYTES_READ_BIO π
okay bestie, welcome to the OpenSSL 3ossl manual for PEM_bytes_read_bio and PEM_bytes_read_bio_secmem β the little functions that read a PEM-encoded data structure from a BIO. this is your group-chat crash course, and yes, every detail is staying. π
π NAME π
PEM_bytes_read_bio, PEM_bytes_read_bio_secmem β read a PEM-encoded data structure from a BIO. π
β¨ SYNOPSIS β¨
#include <openssl/pem.h>
int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm,
const char *name, BIO *bp, pem_password_cb *cb,
void *u);
int PEM_bytes_read_bio_secmem(unsigned char **pdata, long *plen, char **pnm,
const char *name, BIO *bp, pem_password_cb *cb,
void *u);
that's the whole flex: two functions, same shape, one is the secure-heap girlie. π
π¦ DESCRIPTION π¦
so PEM_bytes_read_bio() reads PEM-formatted data β specifically IETF RFC 1421 and IETF RFC 7468 β from the BIO called bp, looking for the data type you pass in name (think RSA PRIVATE KEY, CERTIFICATE, etc.). πΈ
if the same stream has multiple PEM-encoded data structures, PEM_bytes_read_bio() will skip the ones that don't match your requested data type and keep reading. but non-PEM data hanging out in the stream? yeah, that may cause an error. π
the PEM header may say the data after it is encrypted. if it does, the data will be decrypted, and if a passphrase is needed it will wait on user input to supply one. the password callback cb and the rock u are used to get that decryption passphrase, if applicable. π
some data types have compatibility aliases β for example, a file containing X509 CERTIFICATE can match a request for the deprecated type CERTIFICATE. the actual type indicated by the file is returned in *pnm if pnm is non-NULL. the caller must free the storage pointed to by *pnm. π§
the returned data is the DER-encoded form of the requested type, in *pdata with length *plen. the caller must free the storage pointed to by *pdata. π«Ά
PEM_bytes_read_bio_secmem() is like PEM_bytes_read_bio(), but it uses memory from the secure heap for its temporary buffers and for the storage returned in *pdata and *pnm. accordingly, the caller must use OPENSSL_secure_free() to free that storage. periodt. π
π NOTES π
PEM_bytes_read_bio_secmem() only enforces that the secure heap is used for storage allocated within the PEM processing stack. the BIO stack you read input from may also use temporary buffers, and those are not necessarily allocated from the secure heap. π³
so in cases where it is desirable to ensure that the contents of the PEM file only appears in memory from the secure heap, care is needed in generating the BIO passed as bp. in particular, using BIO_s_file() indicates the use of the operating system stdio functionality, which includes buffering as a feature; BIO_s_fd() is likely to be more appropriate in such cases. π
also: these functions make no assumption regarding the pass phrase received from the password callback. it will simply be treated as a byte sequence. that's it, that's the vibe. β¨
π RETURN VALUES π
PEM_bytes_read_bio() and PEM_bytes_read_bio_secmem() return 1 for success or 0 for failure. yes, that's the whole scoring system. β
π SEE ALSO π
π¦ HISTORY π¦
PEM_bytes_read_bio_secmem() was introduced in OpenSSL 1.1.1. throwback moment. β
π COPYRIGHT π
Copyright 2017-2018 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>. π«Ά
mwah π β this page is from OpenSSL version 3.5.6, dated 2026-04-07, and it's the PEM_BYTES_READ_BIO(3ossl) manual. bye bestie, go read some PEM safely π§ββοΈβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms