KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
tls_mbedtls.h
Go to the documentation of this file.
1/*
2 * tls_mbedtls.h — mbedTLS backend for Keel's KlTls vtable
3 *
4 * Provides TLS 1.2/1.3 server (and client) support using mbedTLS.
5 * Supports mutual TLS (mTLS) with configurable client authentication.
6 *
7 * Usage:
8 * KlAllocator alloc = kl_allocator_default();
9 * KlTlsCtx *ctx = kl_tls_mbedtls_ctx_create("cert.pem", "key.pem",
10 * NULL, 0, &alloc);
11 * KlConfig config = {
12 * .tls = &(KlTlsConfig){
13 * .ctx = ctx,
14 * .factory = kl_tls_mbedtls_create,
15 * .ctx_destroy = kl_tls_mbedtls_ctx_destroy,
16 * },
17 * ...
18 * };
19 *
20 * For client-side usage (e.g. Hull HTTP client):
21 * KlAllocator alloc = kl_allocator_default();
22 * KlTlsCtx *ctx = kl_tls_mbedtls_client_ctx_create(NULL, &alloc);
23 * KlTls *tls = kl_tls_mbedtls_create(ctx, &alloc);
24 * tls->handshake(tls, fd);
25 * tls->write(tls, fd, buf, len);
26 * tls->read(tls, fd, buf, len);
27 * tls->shutdown(tls, fd);
28 * tls->destroy(tls);
29 * kl_tls_mbedtls_ctx_destroy(ctx);
30 *
31 * SPDX-License-Identifier: MIT
32 */
33
34#ifndef KEEL_TLS_MBEDTLS_H
35#define KEEL_TLS_MBEDTLS_H
36
37#include <keel/tls.h>
38#include <keel/allocator.h>
39
48
60KlTlsCtx *kl_tls_mbedtls_ctx_create(const char *cert_path,
61 const char *key_path,
62 const char *ca_path,
63 int client_auth,
64 KlAllocator *alloc);
65
77 KlAllocator *alloc);
78
85
98
108int kl_tls_mbedtls_set_hostname(KlTls *tls, const char *hostname);
109
110#endif /* KEEL_TLS_MBEDTLS_H */
Bring-your-own allocator vtable.
Definition allocator.h:12
Definition tls.h:27
struct KlTlsCtx KlTlsCtx
Opaque per-server TLS context (certificates, keys, ciphers). User-owned — KEEL never inspects or modi...
Definition tls.h:94
void kl_tls_mbedtls_ctx_destroy(KlTlsCtx *ctx)
Destroy a TLS context.
KlMtlsMode
Client authentication mode for mTLS.
Definition tls_mbedtls.h:43
@ KL_MTLS_OPTIONAL
Definition tls_mbedtls.h:45
@ KL_MTLS_NONE
Definition tls_mbedtls.h:44
@ KL_MTLS_REQUIRED
Definition tls_mbedtls.h:46
int kl_tls_mbedtls_set_hostname(KlTls *tls, const char *hostname)
Set the expected server hostname for SNI (client mode).
KlTlsCtx * kl_tls_mbedtls_ctx_create(const char *cert_path, const char *key_path, const char *ca_path, int client_auth, KlAllocator *alloc)
Create a server-side TLS context (certificates + keys).
KlTlsCtx * kl_tls_mbedtls_client_ctx_create(const char *ca_path, KlAllocator *alloc)
Create a client-side TLS context (for outbound connections).
KlTls * kl_tls_mbedtls_create(KlTlsCtx *ctx, KlAllocator *alloc)
Factory: create a per-connection KlTls session.