Sortix nightly manual
This manual documents Sortix nightly, a development build that has not been officially released. You can instead view this document in the latest official manual.
NAME
RSA_get_ex_new_index, RSA_set_ex_data, RSA_get_ex_data — add application specific data to RSA objectsSYNOPSIS
#include <openssl/rsa.h>RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
RSA_set_ex_data(RSA *rsa, int idx, void *data);
RSA_get_ex_data(RSA *rsa, int idx);
DESCRIPTION
The following parent objects can have application specific data called “ex_data” attached to them: BIO, DH, DSA, EC_KEY, RSA, SSL, SSL_CTX, SSL_SESSION, UI, X509, X509_STORE, and X509_STORE_CTX. The present manual page documents the related API functions taking the RSA object type as an example. The functions for the other object types work in exactly the same way: just replace the string “RSA” with the name of the respective object type throughout the rest of this manual page.RETURN VALUES
RSA_get_ex_new_index() returns a new index equal to or greater than 1 or -1 if memory allocation fails.ERRORS
After failure of RSA_get_ex_new_index() or RSA_set_ex_data(), the following diagnostic can be retrieved with ERR_get_error(3), ERR_GET_REASON(3), and ERR_reason_error_string(3):- ERR_R_MALLOC_FAILURE “malloc failure”
- Memory allocation failed.
SEE ALSO
BIO_set_ex_data(3), CRYPTO_set_ex_data(3), DH_set_ex_data(3), DSA_set_ex_data(3), RSA_new(3), SSL_CTX_set_ex_data(3), SSL_SESSION_set_ex_data(3), SSL_set_ex_data(3), X509_STORE_CTX_set_ex_data(3), X509_STORE_set_ex_data(3)HISTORY
These functions first appeared in SSLeay 0.9.0 and have been available since OpenBSD 2.4.CAVEATS
A relatively small minority of application programs attempt to change the API contract such that RSA_set_ex_data() transfers ownership of the data to the rsa object. They do this by providing a free_func that calls free(3) or higher-level *_free() functions on the data and sometimes also attempt additional cleanup work as a side effect.- Due to a massive design mistake in the low-level API function CRYPTO_free_ex_data(3), this practice creates a possibility that RSA_free(3) may fail due to memory allocation failure, consequently leaking the memory containing the application specific data and silently skipping any additional cleanup work the free_func was supposed to do, leaving the application in an undetectably inconsistent state. Arguably, leaking additional memory while trying to free some is most unfortunate especially when the program is already starved for memory.
- This practice introduces a risk of use-after-free and double-free bugs in case the rsa object gets destructed while a caller of RSA_set_ex_data() or RSA_get_ex_data() still holds a data pointer. No such risk exists when no free_func is installed.
- Attempting additional cleanup work in free_func is an even worse idea because free_func is unable to report any issues it might detect while doing that work. Instead, if any additional cleanup work is needed, it is recommended that the calling code takes care of that before calling RSA_free(3).