libressl-SSL_load_client_CA_file3
Load certificate names from files
Usage
SSL Library (libssl, -lssl) libcrypto
#include <openssl/ssl.h>
STACK_OF(X509_NAME) *
SSL_load_client_CA_file(const char *file);
int
SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, const char *file);
int
SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, const char *dir);
Overview
SSL_load_client_CA_file() reads PEM formatted certificates from file and returns a new STACK_OF(X509_NAME) with the subject names found. While the name suggests the specific usage as a support function for SSL_CTX_set_client_CA_list(3), it is not limited to CA certificates.
SSL_add_file_cert_subjects_to_stack() is similar except that the names are added to the existing stack.
SSL_add_dir_cert_subjects_to_stack() calls SSL_add_file_cert_subjects_to_stack() on every file in the directory dir.
If a name is already on the stack, all these functions skip it and do not add it again.
Return values
SSL_load_client_CA_file() returns a pointer to the new STACK_OF(X509_NAME) or NULL on failure.
SSL_add_file_cert_subjects_to_stack() and SSL_add_dir_cert_subjects_to_stack() return 1 for success or 0 for failure.
All these functions treat empty files and directories as failures.
In some cases of failure, the reason can be determined with ERR_get_error(3).
Examples
Load names of CAs from a file and use it as a client CA list:
SSL_CTX *ctx;
STACK_OF(X509_NAME) *cert_names;
...
cert_names = SSL_load_client_CA_file("/path/to/CAfile.pem");
if (cert_names != NULL)
SSL_CTX_set_client_CA_list(ctx, cert_names);
else
error_handling();
...