Apache HTTPD
Classes | Macros | Functions | Variables
tls_cert.c File Reference
module tls_module
#include <assert.h>
#include <apr_lib.h>
#include <apr_encode.h>
#include <apr_strings.h>
#include <httpd.h>
#include <http_connection.h>
#include <http_core.h>
#include <http_log.h>
#include <rustls.h>
#include "tls_cert.h"
#include "tls_util.h"

Go to the source code of this file.

Classes

struct  tls_cert_reg_entry_t
 
struct  reg_visit_ctx_t
 
struct  tls_cert_root_stores_entry_t
 
struct  tls_cert_verifiers_entry_t
 

Macros

#define PEM_IN_CHUNK   48 /* PEM demands at most 64 chars per line */
 
#define PEM_CERT_HD   "-----BEGIN CERTIFICATE-----"
 
#define PEM_CERT_FT   "-----END CERTIFICATE-----"
 

Functions

apr_status_t tls_cert_load_pem (apr_pool_t *p, const tls_cert_spec_t *cert, tls_cert_pem_t **ppem)
 
static apr_status_t tls_der_to_pem (const char **ppem, apr_pool_t *p, const unsigned char *der_data, apr_size_t der_len, const char *header, const char *footer)
 
apr_status_t tls_cert_to_pem (const char **ppem, apr_pool_t *p, const rustls_certificate *cert)
 
static void nullify_key_pem (tls_cert_pem_t *pems)
 
static apr_status_t make_certified_key (apr_pool_t *p, const char *name, const tls_data_t *cert_pem, const tls_data_t *pkey_pem, const rustls_certified_key **pckey)
 
apr_status_t tls_cert_load_cert_key (apr_pool_t *p, const tls_cert_spec_t *spec, const char **pcert_pem, const rustls_certified_key **pckey)
 
static int reg_entry_cleanup (void *ctx, const void *key, apr_ssize_t klen, const void *val)
 
static apr_status_t reg_cleanup (void *data)
 
tls_cert_reg_ttls_cert_reg_make (apr_pool_t *p)
 
apr_size_t tls_cert_reg_count (tls_cert_reg_t *reg)
 
static const charcert_spec_to_id (const tls_cert_spec_t *spec)
 
apr_status_t tls_cert_reg_get_certified_key (tls_cert_reg_t *reg, server_rec *s, const tls_cert_spec_t *spec, const rustls_certified_key **pckey)
 
static int reg_visit (void *vctx, const void *key, apr_ssize_t klen, const void *val)
 
void tls_cert_reg_do (tls_cert_reg_visitor *visitor, void *userdata, tls_cert_reg_t *reg)
 
const chartls_cert_reg_get_id (tls_cert_reg_t *reg, const rustls_certified_key *certified_key)
 
apr_status_t tls_cert_load_root_store (apr_pool_t *p, const char *store_file, const rustls_root_cert_store **pstore)
 
static int stores_entry_cleanup (void *ctx, const void *key, apr_ssize_t klen, const void *val)
 
static apr_status_t stores_cleanup (void *data)
 
tls_cert_root_stores_ttls_cert_root_stores_make (apr_pool_t *p)
 
void tls_cert_root_stores_clear (tls_cert_root_stores_t *stores)
 
apr_status_t tls_cert_root_stores_get (tls_cert_root_stores_t *stores, const char *store_file, const rustls_root_cert_store **pstore)
 
static int verifiers_entry_cleanup (void *ctx, const void *key, apr_ssize_t klen, const void *val)
 
static apr_status_t verifiers_cleanup (void *data)
 
tls_cert_verifiers_ttls_cert_verifiers_make (apr_pool_t *p, tls_cert_root_stores_t *stores)
 
void tls_cert_verifiers_clear (tls_cert_verifiers_t *verifiers)
 
static tls_cert_verifiers_entry_tverifiers_get_or_make_entry (tls_cert_verifiers_t *verifiers, const char *store_file)
 
static apr_status_t tls_cert_client_verifiers_get_internal (tls_cert_verifiers_t *verifiers, const char *store_file, const rustls_client_cert_verifier **pverifier, bool allow_unauthenticated)
 
apr_status_t tls_cert_client_verifiers_get (tls_cert_verifiers_t *verifiers, const char *store_file, const rustls_client_cert_verifier **pverifier)
 
apr_status_t tls_cert_client_verifiers_get_optional (tls_cert_verifiers_t *verifiers, const char *store_file, const rustls_client_cert_verifier **pverifier)
 

Variables

static int *const aplog_module_index = &( tls_module.module_index)
 

Macro Definition Documentation

◆ PEM_CERT_FT

#define PEM_CERT_FT   "-----END CERTIFICATE-----"

Definition at line 119 of file tls_cert.c.

◆ PEM_CERT_HD

#define PEM_CERT_HD   "-----BEGIN CERTIFICATE-----"

Definition at line 118 of file tls_cert.c.

◆ PEM_IN_CHUNK

#define PEM_IN_CHUNK   48 /* PEM demands at most 64 chars per line */

Definition at line 67 of file tls_cert.c.

Function Documentation

◆ cert_spec_to_id()

static const char * cert_spec_to_id ( const tls_cert_spec_t spec)
static

Definition at line 259 of file tls_cert.c.

◆ make_certified_key()

static apr_status_t make_certified_key ( apr_pool_t p,
const char name,
const tls_data_t cert_pem,
const tls_data_t pkey_pem,
const rustls_certified_key **  pckey 
)
static

Definition at line 147 of file tls_cert.c.

◆ nullify_key_pem()

static void nullify_key_pem ( tls_cert_pem_t pems)
static

Definition at line 140 of file tls_cert.c.

◆ reg_cleanup()

static apr_status_t reg_cleanup ( void *  data)
static

Definition at line 231 of file tls_cert.c.

◆ reg_entry_cleanup()

static int reg_entry_cleanup ( void *  ctx,
const void *  key,
apr_ssize_t  klen,
const void *  val 
)
static

Definition at line 220 of file tls_cert.c.

◆ reg_visit()

static int reg_visit ( void *  vctx,
const void *  key,
apr_ssize_t  klen,
const void *  val 
)
static

Definition at line 307 of file tls_cert.c.

◆ stores_cleanup()

static apr_status_t stores_cleanup ( void *  data)
static

Definition at line 402 of file tls_cert.c.

◆ stores_entry_cleanup()

static int stores_entry_cleanup ( void *  ctx,
const void *  key,
apr_ssize_t  klen,
const void *  val 
)
static

Definition at line 391 of file tls_cert.c.

◆ tls_cert_client_verifiers_get()

apr_status_t tls_cert_client_verifiers_get ( tls_cert_verifiers_t verifiers,
const char store_file,
const rustls_client_cert_verifier **  pverifier 
)

Get the mandatory client certificate verifier for the root certificate store in store_file. Will create the verifier if not already known.

Parameters
verifiersthe registry of certificate verifiers
store_filethe (server relative) path of the PEM file with certificates
pverifiersthe verifier on success

Definition at line 569 of file tls_cert.c.

◆ tls_cert_client_verifiers_get_internal()

static apr_status_t tls_cert_client_verifiers_get_internal ( tls_cert_verifiers_t verifiers,
const char store_file,
const rustls_client_cert_verifier **  pverifier,
bool  allow_unauthenticated 
)
static

Definition at line 521 of file tls_cert.c.

◆ tls_cert_client_verifiers_get_optional()

apr_status_t tls_cert_client_verifiers_get_optional ( tls_cert_verifiers_t verifiers,
const char store_file,
const rustls_client_cert_verifier **  pverifier 
)

Get the optional client certificate verifier for the root certificate store in store_file. Will create the verifier if not already known.

Parameters
verifiersthe registry of certificate verifiers
store_filethe (server relative) path of the PEM file with certificates
pverifiersthe verifier on success

Definition at line 577 of file tls_cert.c.

◆ tls_cert_load_cert_key()

apr_status_t tls_cert_load_cert_key ( apr_pool_t p,
const tls_cert_spec_t spec,
const char **  pcert_pem,
const rustls_certified_key **  pckey 
)

Load a rustls certified key from a certificate specification. The returned rustls_certified_key is owned by the caller.

Parameters
pthe memory pool to use
specthe specification for the certificate (file or PEM data)
cert_pemreturn the PEM data used for loading the certificates, optional
pckeythe loaded certified key on return

Definition at line 177 of file tls_cert.c.

◆ tls_cert_load_pem()

apr_status_t tls_cert_load_pem ( apr_pool_t p,
const tls_cert_spec_t cert,
tls_cert_pem_t **  ppem 
)

Load the PEM data for a certificate file and key file as given in cert.

Definition at line 35 of file tls_cert.c.

◆ tls_cert_load_root_store()

apr_status_t tls_cert_load_root_store ( apr_pool_t p,
const char store_file,
const rustls_root_cert_store **  pstore 
)

Load all root certificates from a PEM file into a rustls_root_cert_store.

Parameters
pthe memory pool to use
store_filethe (server relative) path of the PEM file
pstorethe loaded root store on success

Definition at line 333 of file tls_cert.c.

◆ tls_cert_reg_count()

apr_size_t tls_cert_reg_count ( tls_cert_reg_t reg)

Return the number of certified keys in the registry.

Definition at line 254 of file tls_cert.c.

◆ tls_cert_reg_do()

void tls_cert_reg_do ( tls_cert_reg_visitor visitor,
void *  userdata,
tls_cert_reg_t reg 
)

Visit all certified_key entries in the registry.

Parameters
visitorcallback invoked on each entry until it returns 0.
userdatapassed to callback
regthe registry to iterate over

Definition at line 316 of file tls_cert.c.

◆ tls_cert_reg_get_certified_key()

apr_status_t tls_cert_reg_get_certified_key ( tls_cert_reg_t reg,
server_rec s,
const tls_cert_spec_t spec,
const rustls_certified_key **  pckey 
)

Get a the rustls_certified_key identified by spec from the registry. This will load the key the first time it is requested. The returned rustls_certified_key is owned by the registry.

Parameters
regthe certified key registry
sthe server_rec this is loaded into, useful for error logging
specthe specification of the certified key
pckeythe certified key instance on return

Definition at line 266 of file tls_cert.c.

◆ tls_cert_reg_get_id()

const char * tls_cert_reg_get_id ( tls_cert_reg_t reg,
const rustls_certified_key certified_key 
)

Get the identity assigned to a loaded, certified key. Returns NULL, if the key is not part of the registry. The returned bytes are owned by the registry entry.

Parameters
regthe registry to look in.
certified_keythe key to get the identifier for

Definition at line 325 of file tls_cert.c.

◆ tls_cert_reg_make()

tls_cert_reg_t * tls_cert_reg_make ( apr_pool_t p)

Create a new registry with lifetime based on the memory pool. The registry will take care of its memory and allocated keys when the pool is destroyed.

Definition at line 242 of file tls_cert.c.

◆ tls_cert_root_stores_clear()

void tls_cert_root_stores_clear ( tls_cert_root_stores_t stores)

Clear the root stores registry, freeing all stores.

Definition at line 420 of file tls_cert.c.

◆ tls_cert_root_stores_get()

apr_status_t tls_cert_root_stores_get ( tls_cert_root_stores_t stores,
const char store_file,
const rustls_root_cert_store **  pstore 
)

Load all root certificates from a PEM file into a rustls_root_cert_store.

Parameters
pthe memory pool to use
store_filethe (server relative) path of the PEM file
pstorethe loaded root store on success

Definition at line 428 of file tls_cert.c.

◆ tls_cert_root_stores_make()

tls_cert_root_stores_t * tls_cert_root_stores_make ( apr_pool_t p)

Create a new root stores registry with lifetime based on the memory pool. The registry will take care of its memory and allocated stores when the pool is destroyed.

Definition at line 409 of file tls_cert.c.

◆ tls_cert_to_pem()

apr_status_t tls_cert_to_pem ( const char **  ppem,
apr_pool_t p,
const rustls_certificate cert 
)

Definition at line 121 of file tls_cert.c.

◆ tls_cert_verifiers_clear()

void tls_cert_verifiers_clear ( tls_cert_verifiers_t verifiers)

Clear the verifiers registry, freeing all verifiers.

Definition at line 498 of file tls_cert.c.

◆ tls_cert_verifiers_make()

tls_cert_verifiers_t * tls_cert_verifiers_make ( apr_pool_t p,
tls_cert_root_stores_t stores 
)

Create a new registry for certificate verifiers with lifetime based on the memory pool. The registry will take care of its memory and allocated verifiers when the pool is destroyed.

Parameters
pthe memory pool to use
storesthe store registry for lookups

Definition at line 485 of file tls_cert.c.

◆ tls_der_to_pem()

static apr_status_t tls_der_to_pem ( const char **  ppem,
apr_pool_t p,
const unsigned char der_data,
apr_size_t  der_len,
const char header,
const char footer 
)
static

Definition at line 69 of file tls_cert.c.

◆ verifiers_cleanup()

static apr_status_t verifiers_cleanup ( void *  data)
static

Definition at line 478 of file tls_cert.c.

◆ verifiers_entry_cleanup()

static int verifiers_entry_cleanup ( void *  ctx,
const void *  key,
apr_ssize_t  klen,
const void *  val 
)
static

Definition at line 463 of file tls_cert.c.

◆ verifiers_get_or_make_entry()

static tls_cert_verifiers_entry_t * verifiers_get_or_make_entry ( tls_cert_verifiers_t verifiers,
const char store_file 
)
static

Definition at line 506 of file tls_cert.c.

Variable Documentation

◆ aplog_module_index

int* const aplog_module_index = &( tls_module.module_index)
static

Definition at line 32 of file tls_cert.c.